Reputation: 325
I need to change the value of all the products in the following fashion store.
Current value = 1,000
Coefficient = 0.85
Current value / coefficient = new value
in the example would be
1000 / 0.85 = 1176.47
How to change that in all areas of Magento (cart, checkout, admin, etc.) to the new value?
Upvotes: 1
Views: 62
Reputation: 726
There are three options, Either you can do this with magento product promotions form back-end by providing promotions or by using magento core modules.
If you have lets say 10K of products you can do this by just import/export options in magento admin dashboard. so after exporting the products csv you can add or make calculation in csv.
Or
just using simple sql queries on magento db you can get your result.
magneto db table which store product price-
catalog_product_entity_decimal
catalog_product_entity_group_price
catalog_product_entity_tier_price
Or
Now finally with the magento core modules. you can use this code ..
$product = Mage::getModel('catalog/product');
$product->load($productId);
$product->setSpecialPrice($price);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$product->save();
Mage::app()->setCurrentStore(Mage_Core_Model_App::DISTRO_STORE_ID);
$cart = Mage::getSingleton('checkout/cart');
$cart->addProduct($product, array('qty' => $quantity));
$cart->save();
Upvotes: 1
Reputation: 808
Assuming this is just a one-off task, then I'd suggest something like the following:
$products = Mage::getModel('catalog/product')->getCollection();
$products->setPageSize(100);
$pages = $products->getLastPageNumber();
$currentPage = 1;
$batchNumber = 0;
do {
$products->setCurPage($currentPage);
$products->load();
foreach($products as $product) {
$origPrice = $product->getPrice();
$newPrice = $origPrice / 0.875;
$product->setPrice($newPrice)->save();
}
$products->clear();
$currentPage++;
} while ($currentPage <= $pages);
Upvotes: 0