Patrik Dendis
Patrik Dendis

Reputation: 313

Change attributes magento

I use custom attributes for my products and I am working on my script, which get attributes and after change them value. I have done selecting code but I dont know how can I do code, which change value.

<?php
    $mageFilename = 'app/Mage.php';
    require_once $mageFilename;
    Mage::app('default'); 
    $collection = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToFilter('manufacturer', '3')
    ->addAttributeToSelect('*'); 

    foreach ($collection as $product) {

      echo $product->getName();
      echo $product->getResource()->getAttribute('cena_balenia_czk')->getFrontend()->getValue($product);
      echo '-';
      echo $product->getResource()->getAttribute('czk')->getFrontend()->getValue($product);
      echo '<br>';
    }
?>

Upvotes: 0

Views: 208

Answers (1)

Kenny
Kenny

Reputation: 5400

Have a look at the code below:

<?php
    $mageFilename = 'app/Mage.php';
    require_once $mageFilename;
    Mage::app('default'); 
    $collection = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToFilter('manufacturer', '3')
    ->addAttributeToSelect('*'); 

    foreach ($collection as $product) {
        $product->setName('NEW PROUDUCT NAME');
        $product->setCenaBaleniaCzk(999);
        $product->setCzk('NEW Czk VALUE');

        $product->save(); // This line is extremely important to commit your changes
    }
?>

Upvotes: 2

Related Questions