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?
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
);
add this for specific store view
$product->setStoreId($storeId);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With