2

I need to check "Use Default Value" box for product status programmatically.

I found this answer. So to untick the box I could use this code:

$product = Mage::getModel('catalog/product')->load($productId);
                    $product->setData($args['row']);
                    $product->setStoreId($storeid);
                    $product->setData('status', true);
                    $product->save();

The problem I encountered was, that if I untick the box like this, the status would always change to "Enabled" and that is obviously because of $product->setData('status', true);

I want the status to remain as it was (like it would when manually unticking the box), so I made a change to the code:

    $actualstatusvalue = Mage::getModel('catalog/product')->setStoreId($storeid)->load($productId)->getData('status');
    $product = Mage::getModel('catalog/product')->load($productId);
                          $product->setData($args['row']);
                          $product->setStoreId($storeid);
                          $product->setData('status', true);
                          $product->setData('status', $actualstatusvalue);
                          $product->save();

So I set the status back to what it was before unticking the box.

This does what I need, but since I don't understand exactly how this works (specifically $product->setData($args['row']);), I am worried that this is a silly/stupid way of doing it.

1
  • Why are you doing $product->setData($args['row']); in the first place?
    – Clonkex
    Apr 1, 2022 at 0:01

0

Your Answer

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

Browse other questions tagged or ask your own question.