2

I have product attribute "is_stock_update_custom". I need to update this attribute programmatically from CartController.php

I have tried so Far

$product = Mage::getModel("catalog/product")->load($params['product']);
$attributeCode = "is_stock_update_custom";
$value = "Yes";
$product->setData($attributeCode, $value);
$product->save();

In this neither "yes" nor "1" was worked. Please help.

2
  • Can you post your CartController.php with yout code you have tried? Commented Sep 19, 2018 at 14:25
  • @SukumarGorai I have added more on question. Commented Sep 20, 2018 at 5:01

1 Answer 1

0

Method 1:

$update_resource = Mage::getResourceSingleton('catalog/product_action');
$update_resource->updateAttributes(array($product_id), array( $attribute_code => $value), 0);

Method 2:

$product = Mage::getModel('catalog/product')->load($product_id);
$resource = $product->getResource();

$product->setData($attribue_code, $value);
$resource->saveAttribute($product, $attribute_code);
2
  • I was check this code on another question. this not work. On method 2 . What about $resource save? Did you try this? Commented Sep 20, 2018 at 5:13
  • Have you done reindexing after running the code? Commented Sep 20, 2018 at 5:14

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.