Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

[API] Add products to a website
 
Roderik
Member
 
Avatar
Total Posts:  35
Joined:  2007-09-15
Belgium
 

I’m trying to add products in magento through the api, and i’ve been unable to add a product to a site. I’m runnign the demoshop without extra config, and i can import my products, images, add the to categories, etc.

The only thing that doesn’t work is the setting of the website. The wiki specifies

$newProductData = array(
    
'name'              => 'name of product',
    
'websites'          => array('base'),
    
'short_description' => 'short description',
    
'description'       => 'description',
    
'price'             => 12.05
);

I’ve added the websites line to my array, and i can verify it gets though on the api side. But the products are not added to a website
But on the api side a method is called that i cannot find in the magento code??

$product->setWebsiteIds($productData[’websites’]);

I’ve found the getter but not this setter. Is there some magic setter function active or does my IDE fail to search correctly? Or alternatively, why doesn’t it it get activated in the store?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Roderik
Member
 
Avatar
Total Posts:  35
Joined:  2007-09-15
Belgium
 

Adittional information, i tried to pass “1” instead of base, but the error message i got was: Data retreiver for ‘0’ is not defined

Is there anyone who had some success with this?

 
Magento Community Magento Community
Magento Community
Magento Community
 
FOOMAN
Guru
 
Avatar
Total Posts:  669
Joined:  2007-12-13
Auckland, New Zealand
 

Hi Roderik,

I haven’t tried this myself but I have encountered similar behaviour when working with dataflow. My products wouldn’t show up as expected after a succesful import. The error turned out to be missing attributes required by the product type (weight in my case)

So this might work for you as well. Have a look at what attributes are set to required when adding a product normally through the backend and add them to your newProductArray.

good luck

ps: One other thing to try is to add them to your base store and then a second time to your actual store.

 
Magento Community Magento Community
Magento Community
Magento Community
 
zevious
Jr. Member
 
Total Posts:  23
Joined:  2008-07-17
 

Where do I find the info about setting this sort of import up?

(sorry to hijack the thread)

 
Magento Community Magento Community
Magento Community
Magento Community
 
JKwan13
Member
 
Total Posts:  63
Joined:  2008-06-12
 

@zevious - Take a look at the Core API for 1.1.1 release - http://www.magentocommerce.com/support/magento_core_api

@Roderik - I’ve been successful in using:

‘websites’ => array(1),

I’m not sure why its not working, but maybe more code or more of error message may help.

 
Magento Community Magento Community
Magento Community
Magento Community
 
cgalpin
Jr. Member
 
Total Posts:  11
Joined:  2008-06-25
 

Just curious if you guys found a way to name your images when adding images to a product using catalog_product_attribute_media.create.

What I have found is the name is always image.jpg so you end up with

i/m/image.jpg
i/m/image_1.jpg
i/m/image_2.jpg

which simply won’t scale when you have 45K pictures.

I can’t figure out how to specify the image name though (i tried adding a ‘name’ parameter in the image and file arrays).

thanks,
charles

 
Magento Community Magento Community
Magento Community
Magento Community
 
JKwan13
Member
 
Total Posts:  63
Joined:  2008-06-12
 

@cgalpin - I haven’t found a way to name the images because I didnt find a need.  Can I ask why you want to rename them?  I mean, once I upload them to the right products and they display correctly, I have no need to touch them.  The only reason is if I need to update the pictures, but won’t ‘product_media.update’ method do that (I haven’t tried it yet).

Note: I also have a lot of pictures (40K).

 
Magento Community Magento Community
Magento Community
Magento Community
 
magnet0
Jr. Member
 
Total Posts:  29
Joined:  2007-10-23
Heraklion, Crete
 

Hello,

Have you found any solution for this?

Thanks
Yiannis

cgalpin - 07 August 2008 06:19 AM

Just curious if you guys found a way to name your images when adding images to a product using catalog_product_attribute_media.create.

What I have found is the name is always image.jpg so you end up with

i/m/image.jpg
i/m/image_1.jpg
i/m/image_2.jpg

which simply won’t scale when you have 45K pictures.

I can’t figure out how to specify the image name though (i tried adding a ‘name’ parameter in the image and file arrays).

thanks,
charles

 
Magento Community Magento Community
Magento Community
Magento Community
 
magnet0
Jr. Member
 
Total Posts:  29
Joined:  2007-10-23
Heraklion, Crete
 

at
app\code\core\Mage\Catalog\Model\Product\Attribute\Media\Api.php
change line
$fileName = ‘image.’ . $this->_mimeTypes[$data[’file’][’mime’]];
into
$fileName = $data[’file’][’name’];
and add a line into your script for adding the image like this
“file” => array(
“content” => base64_encode(file_get_contents($_filename)),
“mime” => “image/jpeg”,
“name” => “image_filename”
),

magnet0 - 07 January 2009 01:39 AM

Hello,

Have you found any solution for this?

Thanks
Yiannis


cgalpin - 07 August 2008 06:19 AM
Just curious if you guys found a way to name your images when adding images to a product using catalog_product_attribute_media.create.

What I have found is the name is always image.jpg so you end up with

i/m/image.jpg
i/m/image_1.jpg
i/m/image_2.jpg

which simply won’t scale when you have 45K pictures.

I can’t figure out how to specify the image name though (i tried adding a ‘name’ parameter in the image and file arrays).

thanks,
charles
 
Magento Community Magento Community
Magento Community
Magento Community
 
finch8243
Sr. Member
 
Total Posts:  79
Joined:  2007-08-31
 

I needed this --thanks.  The product_media.create API is frigged up in 1.3.1 such that it always saves whatever you upload as i/m/image.jpg, so it overwrites itself each image upload.  You’ll need to change the filenames to prevent this.  I’ll post a bug on it now—

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top