Reputation: 31
Is it possible to change an existing bundle product from dynamic to fixed price via the database rather than having to create a new product?
Upvotes: 2
Views: 1423
Reputation: 6199
I hope you don't mean using raw SQL queries. Anyway you can do this using magento Models. These steps should do the job for you (although I did not test it myself!):
Load your product:
$bundleProduct = new Mage_Catalog_Model_Product();
$bundleProduct->load(YOUR_PRODUCT_ID);
Set the price type to 1:
$bundleProduct->setPriceType(1); // Price types => 0: dynamic, 1: fixed
Save your product:
$bundleProduct->save();
Here you can find all the attributes that you can change programmatically for a bundle product.
require_once ("app/Mage.php"); //Pass the exact path to Mage.php file here (e.g. the indicated path works if your script is under main magento installation folder)
Mage::setIsDeveloperMode(true);
umask(0);
Mage::app('admin');
Mage::register('isSecureArea', 1);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
error_reporting(E_ALL);
$bundleProduct = new Mage_Catalog_Model_Product();
$bundleProduct->load(YOUR_PRODUCT_ID); //Pass your bundle product ID here; you can get the ID from Magento admin panel
$bundleProduct->setPriceType(1); // Price types => 0: dynamic, 1: fixed
$bundleProduct->save();
Alternatively if you want to change this for all your exisiting bundle products use this:
$products = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*')
->addAttributeToSelect('type')
->addFieldToFilter('type_id', array('eq' => 'bundle'));
foreach ($products as $product) {
$product->setPriceType(1);
$product->save;
}
You can whether run your script using php command from command line or other methods (browser, wget, ..)
Upvotes: 1