Magento

eCommerce Software for Online Growth

Magento Forum

From setting up your store to managing your products, pages and promotions to generating detailed reports, the Magento User Guide empowers the user to utilize the platform for all of its vast capacity.
Available in eBook and Print formats – Download Now!!!
   
Page 3 of 3
Product Import (OR the simplest batch)
 
Jeena Paradies
Jr. Member
 
Avatar
Total Posts:  20
Joined:  2008-03-10
 

How stupid is that?! They really removed importFromTextArray() the only easy way to import something, this is stupid! In the beginning I liked Magento but with each update it all goes wrong, they change methods within the templates (!), they remove API-methods and so on. Each time I do a upgrade my whole shop explodes and I have to spend days on fixing it.

This is not a preview/beta anymore, Varien! Wake up! Otherwise we’ll find some other CMS which works at least within one main version without rewriting templates and plugins every update.

I think I will not update my shop for a long time when I get it working with 1.1.6 :-(

 
Magento Community Magento Community
Magento Community
Magento Community
 
allstarbooks
Jr. Member
 
Total Posts:  4
Joined:  2008-07-19
 

The importFromTextArray($productArrayToImport) function has been replaced by fromArray($productArrayToImport).  The functionality is the same as before.  To retrieve data from the object in array format, you can use $product->toArray().

 
Magento Community Magento Community
Magento Community
Magento Community
 
Laurent Bourrel
Jr. Member
 
Avatar
Total Posts:  25
Joined:  2008-06-09
SQLI - Poitiers
 

I dont’ think that fromArray() replace importFromTextArray()…
The first is just a setData() with stock management.
The second is (was !) a product save in the database with a more complex array in parameter (product type, categories, etc.)

 
Magento Community Magento Community
Magento Community
Magento Community
 
tza79
Jr. Member
 
Total Posts:  6
Joined:  2008-03-22
 

Well, I was bummed to find out the import script I have been using everytime I install a new version of Magento doesn’t work anymore because importFromTextArray() has been replaced. I managed to modify the script from this thread to make the import work again. However, the only thing I can’t get to work is the importing of images using addImageToMediaGallery. Does anyone have any ideas on this? It appears that the function still exists and works the same way, so I can’t figure out why it doesn’t work anymore.

Here is the script I ran to import.

while ($row mysql_fetch_array($resultMYSQL_ASSOC)) {

    $product 
Mage::getModel('catalog/product');
    
    
$file '/path/to/images/products/398_large_image.jpg';
    
$visibility = array (
            
'thumbnail',
            
'small_image',
            
'image'
    
);
    
    
$product->addImageToMediaGallery($file,null,$visibility,false);     
    
    
$product->setWebsiteIds(array(1));  // store id
    
$product->setAttributeSetId(39);
    
$product->setEntityId($row['record_number']);
    
$product->setSku('import-sku-' $row['record_number']);
    
$product->setType('Simple Product');
    
$product->setName($row['Name']);
    
$product->setModel($row['Name']);    
    
$product->setDescription($row['Description']);
    
$product->setInDepth($row['Description']);    
    
$product->setPrice($row['Base_Price']);
    
$product->setShortDescription($row['Brief_Description']);
    
$product->setWeight(0);
    
$product->setStatus(1);
    
$product->setCost($row['My_Cost']);
    
$product->setTaxClassId('Shipping');
    
$product->setKeywords($row['Keywords']);
    
$product->setCreatedAt($row['Date_Added_to_Cart']);
    
$product->addImageToMediaGallery($file,null,$visibility,false);     
    
$product->save();
    
    
$stockItem Mage::getModel('cataloginventory/stock_item');
    
$stockItem->loadByProduct($product->getId());
    
    if (! 
$stockItem->getId()) {
        $stockItem
->setProductId($product->getId())->setStockId(1);
    
}
    $stockItem
->setData('qty'$row['Stock']);
    
$stockItem->setData('is_in_stock'1);
    
    
$stockItem->save();
}

 
Magento Community Magento Community
Magento Community
Magento Community
 
andyfowler
Jr. Member
 
Total Posts:  2
Joined:  2008-07-10
 

tza79, thanks for the insight—you pointed me in the right direction! In regard to addImageToMediaGallery(), I’ve never used that method prior to 1.1.6, but it started working for me once I provided absolute paths to my media (some previous examples seemed to provide relative paths to /media/import/).

To those looking to add products to categories:

$product->setCategoryIds(array(1,3,8));

 
Magento Community Magento Community
Magento Community
Magento Community
 
David Sedeño
Jr. Member
 
Total Posts:  19
Joined:  2008-09-25
 

tza79 thanks a lot for your post!

Have you resolve the issue with the images import? It’s seems to import something in the DB because it’s show a entry in the image admin of the product, but nothing more (no label, no thumbnail)

 
Magento Community Magento Community
Magento Community
Magento Community
 
David Sedeño
Jr. Member
 
Total Posts:  19
Joined:  2008-09-25
 

Ok, I think I have it.

The parameter in addImageToMediaGallery are not correct. The correct form is:

$product->addImageToMediaGallery($file,$visibility,false,false);

With this, the image is imported correctly.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Fai
Jr. Member
 
Total Posts:  1
Joined:  2008-05-16
 

There’s another method of adding data to the product object -

$product->addData( $array );

For example:

$data = array(
   
'websites_ids' => array(1),
   
'sku' => $row['record_number'],
   
'type' => 'Simple Product',
   
'model' => $row['Name'],
   
'name' => $row['Name'],
   
'description' => $row['Description'],
   
'in_depth' => $row['Description'],
   
'price' => $row['Base_Price'],
   
'short_description = $row['Brief_Description'],
   '
weight' => 0,
   '
status' => 1,
   '
cost' => $row['My_Cost'],
   '
tax_class_id' => 'Shipping',
   '
keywords' => $row['Keywords'],
   '
set_created_at' => $row['Date_Added_to_Cart],
);

$product->addData($data);
$product->save();

This should help those who miss the importFromTextArray method.

Also, if this helps, the addImage doc shows:

/**
     * Add image to media gallery and return new filename
     *
     * @param Mage_Catalog_Model_Product $product
     * @param string                     $file              file path of image in file system
     * @param string|array               $mediaAttribute    code of attribute with type 'media_image',
     *                                                      leave blank if image should be only in gallery
     * @param boolean                    $move              if true, it will move source file
     * @param boolean                    $exclude           mark image as disabled in product page view
     * @return string
     */

addImage(Mage_Catalog_Model_Product $product$file$mediaAttribute=null$move=false$exclude=true)

The media attribute, as I’ve checked in the sample database, is optionally one or more of: “image”, “thumb_image” or “thumbnail”.

 
Magento Community Magento Community
Magento Community
Magento Community
 
C2K
Jr. Member
 
Avatar
Total Posts:  6
Joined:  2007-09-04
Eindhoven
 

How can I add a special price to a product, while importing?

Can I use:  ‘special_price’ = 12.34

Or can I use a existing function?

Kind regard,
Pascal van Gemert

 Signature 

C2K internet solutions

 
Magento Community Magento Community
Magento Community
Magento Community
 
nasha
Member
 
Total Posts:  61
Joined:  2009-04-15
 

Hi C2k
i think you can use this
$product->setSpecialPrice($p_specialprice);

 
Magento Community Magento Community
Magento Community
Magento Community
 
Hybrid Forge
Jr. Member
 
Avatar
Total Posts:  8
Joined:  2009-02-06
HybridForge.com
 

We wrote a command line product import tool that creates configurable and simple products from a .csv file. Once the products are setup in Magento the tool can be run again to update product details like inventory levels. This type of tool is perfect for enterprise-class Magento deployments where many thousands of products must be created and maintained from a back-office system like SAP or Oracle. Can you imagine the amount time it would take to manually create configurable products for thousands of simple products for a large apparel retailer?

http://www.merchantforge.com/magento-extensions/direct-importer-command-line-product-import.html

 
Magento Community Magento Community
Magento Community
Magento Community
 
vasim
Member
 
Avatar
Total Posts:  59
Joined:  2009-02-18
 

Hi, frnds..

I have read this whole topic and its a really great.. now i want to add custom option with this data so how can i do that....

Any kind of help will be appreciated.... many thanks in advance…

 Signature 

Send Gifts to INDIA
Magento Development India
Magento Developer
Hire PHP Programmer/

 
Magento Community Magento Community
Magento Community
Magento Community
 
bolasevich
Sr. Member
 
Total Posts:  124
Joined:  2008-03-04
CT USA
 

http://www.magentocommerce.com/extension/1894 will import custom options as well as all other combinations of imports and exports

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
Page 3 of 3
 
© Copyright 2010 Varien. Magento, eCommerce software, is a trademark of Irubin Consulting Inc. DBA Varien
Privacy Policy|Terms of Service
Magento Community Count
177591 users|1428 users currently online|277147 forum posts