Magento – How to update product price on a multi website environment using API (different price for different website)

apimagento-1.7magento-1.8price

How to update a product price on a multi website environment using API (different price for different website)

For single website the following code working, but if I give only one website id in "website" array it is un selecting the product from other website.

$client = new SoapClient('http://example.com/api/soap/?wsdl');
$session = $client->login('exapmple*', 'exapmple');
$result = $client->call($session, 'catalog_product.update', array(
    'PRIN-SKU',
    array(
        'websites' => array(5),
        'price' => '100',
    )
));

Best Answer

Updating the price on a specific website level unfortunately can't be done with the catalog_product.update API method.

Looking at your example. All the changes you define in the array are the actual changes being made to the product attributes. So in this case the product-website relation will be adjusted. The 'websites' parameter does not mean the other attributes are only updated for the given websites.

The only way to adjust data on a specific level can be done by passing in an additional parameter for the storeview. Like below, in this case the '2' as the last parameter stands for the storeview with ID 2.

$result = $client->call($session, 'catalog_product.update', array('33', array(
    'short_description' => 'Product short description 2',
    'meta_description' => 'Product meta description 2',
    'price' => '100',
), '2'));

Unfortunately though price is a website level attribute. I hoped that it would automatically echo the defined price attribute value to the website level, but instead the values is updated directly on the global level.

So in short, it does not look like you can adjust prices on a website level via the API. You will need to create a custom API for it. Either that, or I'm accidentally overlooking something in the Core API documentation. http://www.magentocommerce.com/api/soap/catalog/catalogProduct/catalog_product.update.html

By the looks of it there is a different API call for the setting special prices. Not something you asked for, but perhaps you can use it to copy/create your custom API method for setting the regular price. http://www.magentocommerce.com/api/soap/catalog/catalogProduct/catalog_product.setSpecialPrice.html

Do mind that this API method for specialPrice suffers the exact same issue regarding updating the price to the global level.

Hopefully this makes it all a bit more transparant for you. Unfortunately you will need to write some custom API code to reach your goal. The following page is a good start for that: http://www.magentocommerce.com/api/soap/create_your_own_api.html

Related Topic