Call-back icon  Sales: Call 877.832.5289 (N America)|310.295.4144 (International)

Magento

eCommerce Software for Online Growth

Magento Forum

   
Page 2 of 3
Product Import (OR the simplest batch)
 
alanin
Member
 
Total Posts:  64
Joined:  2008-02-25
Meuselwitz, Germany
 

Hi there,

i tried to import my products now and i ran into a bug with specialchars…
magento is just cutting of the values from the first special char - in the name, the descriptions and the attributes… (well they are added to the database the same way, so its “correct” that it happens to all attributes)

Maybe someone has an idea to “reformat” the values, so they are added to the DB correct…

 
Magento Community Magento Community
Magento Community
Magento Community
 
cshontz
Sr. Member
 
Avatar
Total Posts:  85
Joined:  2007-11-07
 
Brikou Carré - 01 April 2008 02:12 AM

But with the 1.0 release, there is a new easy method to import picture corresponding to a product; I’ll try to do it this way soon…

Thanks for your effort, Brikou Carré - and superb work! smile

Make any progress on this new method to import pictures?

senders - 01 April 2008 05:43 AM

Hi Brikou Carré,

Do you also know, how to import a manufacturer by the same way?

Sebastian,
I haven’t confirmed, but I think you should be able to import manufacturer the same way, providing you’ve already configured all of the necessary manufacturers in the attributes section. Have you done this?

I bulk-imported manufacturer attributes using phpMyAdmin into eav_attribute_option, and eav_attribute_option_value using two CSV files. I think those are the only two tables that need to be updated with manufacturers. It seemed to work fairly well, and the attributes were valid for a dataflow import.

Good luck!

 
Magento Community Magento Community
Magento Community
Magento Community
 
alanin
Member
 
Total Posts:  64
Joined:  2008-02-25
Meuselwitz, Germany
 

damn - me stupid bastid…

the values i tried to enter were not UTF8 - so a utf8_encode() around the values did the trick wink

 
Magento Community Magento Community
Magento Community
Magento Community
 
Luc
Jr. Member
 
Total Posts:  15
Joined:  2007-08-31
 

Hi guys,

The media gallery is correctly created but unfortunately, the images are not assigned (image, thumbnail ans small image) for the product.

$row = array (
    
// ...
    
'thumbnail'   => "/c/h/charger_1.jpg",
    
'small_image' => "/c/h/charger_2.jpg",
    
'image'       => "/c/h/charger_3.jpg",
    
// ... other attributes

Any Idea ?

Luc

 
Magento Community Magento Community
Magento Community
Magento Community
 
cshontz
Sr. Member
 
Avatar
Total Posts:  85
Joined:  2007-11-07
 

I’ve done some sleuthing of my own - I can hold my own with PHP, but I’m not one of those superstar programmers. You know the sort. Anyway, I have it working so images are added “the easy way”, which is presumably the function that Brikou Carré mentioned earlier.

The function is addImageToMediaGallery.

/**
     * Add image to media gallery
     *
     * @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
     */

The following code

$file 'product_image.jpg'//specify path if necessary
$product->addImageToMediaGallery($file,null,false,false);

replaces

$source         '/var/www/MagentoTest/magento/media/catalog/product/c/h/charger.jpg';
$destination    '/var/www/MagentoTest/magento/media/tmp/catalog/product/c/h/charger.jpg';
copy($source$destination);


    
'media_gallery'                 => array (
        
'images' => array (
            array (
                
'url'       => "http://localhost/MagentoTest/magento/media/tmp/catalog/product/c/h/charger.jpg",
                
'file'      => "/c/h/charger.jpg",
                
'label'     => '',
                
'position'  => 1,
                
'disabled'  => 0,
                
'removed'   => 0
            
),
        ),
        
'values' => array (
            
'thumbnail'     => 'no_selection',
            
'small_image'   => null,
            
'image'         => 'no_selection'
        
),
    ),

Though I’ve only solved part of the problem. I’m still trying to figure out how to set the image’s label, base, small, thumb, and sort parameters. I just wanted to post this in the interim, hoping a solution would be obvious to someone else. Meanwhile, I’m going to continue to mess around with it.

Many thanks to Brikou Carré and everyone else for collaborating on this and getting us to this point. smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
cshontz
Sr. Member
 
Avatar
Total Posts:  85
Joined:  2007-11-07
 

Okay, the position value auto-increments based on order-of-import (if multiples), so that’s no problem. The label value doesn’t seem to be modified by the addImageToMediaGallery function - still working on that. However, I did manage to figure out how to set visibility.

This line of code

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

becomes

$visibility = array (
    
'thumbnail',
    
'small_image',
    
'image'
);

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

where the array “$visibility” contains 0-3 values, thumbnail, small_image, and/or image, depending on where you want the product image to appear. You can also forgo the variable and embed the array directly into the function like this

$product->addImageToMediaGallery($file,array('thumbnail','small_image','image'),false,false);

Keep in mind, each visibility attribute should only be set to 1 image per product.

 
Magento Community Magento Community
Magento Community
Magento Community
 
cshontz
Sr. Member
 
Avatar
Total Posts:  85
Joined:  2007-11-07
 

I’m striking out on setting the label value programmatically. Someone else’s turn. wink

EDIT: This is what my version of the code looks like, in the end. Now I just have to tailor it for a dynamic import to move products from the old e-commerce site to Magento.

<?php

define
('MAGENTO'realpath(dirname(__FILE__)));
ini_set('memory_limit''32M');

require_once 
MAGENTO '/app/Mage.php';

Mage::app();

$t time();

$file1 'parts.jpg';

$row = array (
    
'sku'                           => 'test-sku-' $t,
    
'store'                         => 0,
    
'attribute_set'                 => 'Default',
    
'type'                          => 'Simple Product',
    
'categories'                    => '12,25',
    
'name'                          => 'Test Product ' $t,
    
'description'                   => 'Here is the description of this product.',
    
'price'                         => 33.95,
    
'short_description'             => 'Here is the description...',
    
'weight'                        => 0,
    
'status'                        => 'Enabled',
    
'tax_class_id'                  => 'Taxable Goods',
);

$line = array (
    
'i'     => 1,
    
'row'   => $row
);

$visibility = array (
    
'thumbnail',
    
'small_image',
    
'image'
);

$product Mage::getModel('catalog/product');
$product->importFromTextArray($line);
$product->addImageToMediaGallery($file1,$visibility,false,false);
$product->setWebsiteIds(array(1));  // store id
$product->save();

$stockItem Mage::getModel('cataloginventory/stock_item');
$stockItem->loadByProduct($product->getId());

if (! 
$stockItem->getId()) {
    $stockItem
->setProductId($product->getId())->setStockId(1);
}

$stockItem
->setData('qty'100);
$stockItem->setData('is_in_stock'1);
$stockItem->save(); 

?>

 
Magento Community Magento Community
Magento Community
Magento Community
 
srinigenie
Guru
 
Avatar
Total Posts:  398
Joined:  2008-02-04
 

Some observations ....the way Magento updates stock has changed in Ver.1.0. Now stock is passed to product and saved through the product itself instead of $stockItem->save().

And on the images
http://www.magentocommerce.com/boards/viewthread/5120

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brikou Carré
Member
 
Avatar
Total Posts:  37
Joined:  2007-10-04
 

If you would like to “see” what a product is made of, you can print the content of this product… This can be helpfull to get all the parameters composing this product.

<?php
define
('MAGENTO'realpath(dirname(__FILE__) . '/../../magento')); // adjust this to your relative magento path
ini_set('memory_limit''32M');

require_once 
MAGENTO '/app/Mage.php';

Mage::app();

$id 28;   // the id of the product which is written in the product backend list 

$product Mage::getModel('catalog/product');
$product->load($id);
print_r($product->toArray());

Thanx everyone for the big effort… To be continued…

 Signature 

Sign here please…

 
Magento Community Magento Community
Magento Community
Magento Community
 
cshontz
Sr. Member
 
Avatar
Total Posts:  85
Joined:  2007-11-07
 

I put the above import script in a loop, and for some reason, the loop resets after iterating through roughly 40 records. Its not consistent, though. Could be a few more or a few less. So basically, I import 40 products, and then the script starts over. It does this 10 times before the browser calls it quits.

Its 2:00 AM. Anyone have any thoughts?

while($row mysql_fetch_array($result)) {
...and so on...
}

I’ve tried to echo the results without writing, and it goes to the end of the loop just fine (approx 3000 records). However, when I write to Magento, the loop resets at around record 40 - over, and over, and over again.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brikou Carré
Member
 
Avatar
Total Posts:  37
Joined:  2007-10-04
 

Ok !…

Now I can achieve to add some “Simple Product” easily, but the big deal would be to be able to create ”Configurable Product” and link “Simple Products” with “Configurable Product”.

First I started to create a derived object just assiging it the type to “Configurable Product”

$row = array (
    
'sku'                           => 'test-sku-' $t,
    
'store'                         => 0,
    
'attribute_set'                 => 'Default',
    
'type'                          => 'Configurable Product'// instead of 'Simple Product'
    
'categories'                    => '12,25',
    
'name'                          => 'Test Product ' $t,
    
'description'                   => 'Here is the description of this product.',
    
'price'                         => 33.95,
    
'short_description'             => 'Here is the description...',
    
'weight'                        => 0,
    
'status'                        => 'Enabled',
    
'tax_class_id'                  => 'Taxable Goods',
);

This partially works but we also need to tell what are the attribute(s) which make this product configurable.

I don’t really know how to do it right now but if anyone knows this could be great wink

Cheers…

 Signature 

Sign here please…

 
Magento Community Magento Community
Magento Community
Magento Community
 
uni-man
Member
 
Total Posts:  34
Joined:  2008-04-04
 

It looks like importFromTextArray() has been removed from v1.1.5.
This thread is helpful: http://www.magentocommerce.com/boards/viewthread/7519/P15/

I’m going to try using sql to import direct to the database shortly (will post the script here if i can get it to work). Many other topics have mentioned scripts but not posted anything (as far as I can find anyway).

Does anyone have tips / code on updating the layered navigation and caches etc once the import is complete?

 Signature 

http://www.unicycle.co.nz

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

I can’t believe that they removed importFromTextArray() !

Varien doesn’t care about retro-compatibility or what ??

 
Magento Community Magento Community
Magento Community
Magento Community
 
uni-man
Member
 
Total Posts:  34
Joined:  2008-04-04
 

I’m using Mage_Catalog_Model_Convert_Adapter_Product::saveRow() to create the initial product and then Mage::getModel( ‘catalog/product’ )->load() to fill in the details. Seems to work OK.

 Signature 

http://www.unicycle.co.nz

 
Magento Community Magento Community
Magento Community
Magento Community
 
ImpelGD
Jr. Member
 
Total Posts:  21
Joined:  2008-04-16
Dundee, UK
 
uni-man - 18 September 2008 04:16 PM

I’m using Mage_Catalog_Model_Convert_Adapter_Product::saveRow() to create the initial product and then Mage::getModel( ‘catalog/product’ )->load() to fill in the details. Seems to work OK.

I’m new to OOP and to Magento - could you point me in the right direction to learn about how to use these please? Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
Page 2 of 3
 
Sales: Call 877.832.5289 (North America) 310.295.4144 (International)
© Copyright 2008 Varien. Magento, eCommerce software, is a trademark of Irubin Consulting Inc. DBA Varien
Privacy Policy|Terms of Service
Magento Community Count
52311 users|455 users currently online|105635 forum posts