0

I have this code:

foreach ($skuScope as $sku)
{
    $object = Mage::getModel('catalog/product');
    $product = $object->loadByAttribute('sku', $sku);

    $attributes = $product->getAttributes();
    foreach ($attributes as $attribute) {
        $attributeCode = $attribute->getAttributeCode();
        $value = $attribute->getFrontend()->getValue($product);
}}

I can get all attributes, all values, but I don’t know how to rewrite values for an attribute

Help me, please! Thanks!

1 Answer 1

0

Please do like this.

<?php


Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

$productCollection = Mage::getModel('catalog/product')->getCollection();

foreach($productCollection as $product) 
{
    $attributeCode = "my_option";
    echo "\n".'updating '.$product->getSku()."...\n";
    $product = Mage::getModel('catalog/product’)
                   ->load($product->getEntityId());
    $product->setData($attributeCode, "enter_your_value")
            ->getResource()
            ->saveAttribute($product, $attributeCode);
}

Happy Coding :)

2
  • This does not fit, I need to rewrite the value of an existing attribute Commented Apr 6, 2020 at 14:32
  • Yes this is just a example of the code. Commented Apr 6, 2020 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.