Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save an attribute value for a specific store view?

I'm trying to create a product programmatically in Magento 1.8 and then set some attribute values to it. So far everyting is working, the attributes are being saved correctly with the product under the "default" scope.

The problem is that my store has two different "store view", one in English and one in French. I can't figure how to set the "scope" or "store view" for the data of a specific attribute.

How can I tell Magento to save an attribute value for a specific scope?

Here's a code sample using the "short description" attribute:

 $product = new Mage_Catalog_Model_Product();
 $product->setSku($sku);
 $product->setAttributeSetId($attributeSetId);
 $product->setTypeId($typeId);
 $product->setName($sku);
 $product->setWebsiteIDs(array($websiteId));
 $product->setShortDescription('Short description in english');
 $product->setShortDescription('Short description in french'); // Scope change here?
like image 912
Hubert Perron Avatar asked Apr 29 '14 00:04

Hubert Perron


2 Answers

After you have created the product it should have an id.
Here is a fast way to update the product name and short description for a specific store view without calling the resource consuming save method.
Let's assume that the product id is 10 and the store view id is 2.
Run this:

$productId = 10;
$storeId = 2;
$newName = 'Nom de produit';
$newShortDescription = 'description de produit';
Mage::getSingleton('catalog/product_action')->updateAttributes(
    array($productId),
    array('name'=>$newName, 'short_description' => $newShortDescription),
    $storeId
);
like image 136
Marius Avatar answered Sep 29 '22 20:09

Marius


add this for specific store view

$product->setStoreId($storeId);
like image 40
Ansyori Avatar answered Sep 29 '22 20:09

Ansyori