0

I have three store view in my magento site. I want to update product price programmatically for all store view.

For this I am using below code :

$product = Mage::getModel('catalog/product')->setStoreId(1)->load($id);
$product->setPrice(ceil($product_price))->getResource()->saveAttribute($product, 'price'); 

And similar to other store, This is working and updated price respectively to all store view.

But default values showing price 0.00 in magento admin grid. Why below code is not working?

$product = Mage::getModel('catalog/product')->load($id);
$product->setPrice(ceil($product_price))->getResource()->saveAttribute($product, 'price');

How to do that?

  • Check you whether you are updating price for configurable product id. – Nitin Pawar Nov 11 '16 at 12:41
  • My product is Virtual type. – Vinaya Maheshwari Nov 11 '16 at 12:42
  • Set break points to check the correct product is loading and also the $product_price in the program. Your syntax is seems to valid. – Nitin Pawar Nov 11 '16 at 12:45
  • Yes I checked, 'product_id' is same and my code/syntax is valid. product price for all three store view updated by my code and on frontend product showing correct price on all store but default value showing in admin is 0.00 still. – Vinaya Maheshwari Nov 11 '16 at 12:51
  • It is working now after adding Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); in my file. – Vinaya Maheshwari Nov 11 '16 at 13:14
0

We need to add admin permission if we try to save default values for product from any external file as below :

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STOR‌​E_ID);

It also remove any integrity violation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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