While dealing with configurable products in Magento, the price of associated simple products are completely omitted. Sometimes when working with complex products, you need to ignore the price difference set for associated simple products and rather want to override price of configurable product with simple ones. This task is a bit tricky and lead to custom code in Magento.
Here, I will share the code to Override Configurable Product Price with Simple Product Price in Magento
- Put following code in config.xml for observer.
- Add following functions in Model/Observer.php.
1 2 3 4 5 6 7 8 9 10 11 12 |
<global> <events> <catalog_product_get_final_price> <observers> <magecomp_catalog_product_get_final_price> <class>magecomp/observer</class> <method>simpleProductPrice</method> </magecomp_catalog_product_get_final_price> </observers> </catalog_product_get_final_price> </events> </global> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
public function simpleProductPrice(Varien_Event_Observer $observer) { $event = $observer->getEvent(); $product = $event->getProduct(); $qty = $event->getQty(); $selectedAttributes = array(); if ($product->getCustomOption('attributes')) { $selectedAttributes = unserialize($product->getCustomOption('attributes')->getValue()); } if (sizeof($selectedAttributes)) return $this->getSimpleProductPrice($qty, $product); } public function getSimpleProductPrice($qty=null, $product) { $cfgId = $product->getId(); $product->getTypeInstance(true) ->setStoreFilter($product->getStore(), $product); $attributes = $product->getTypeInstance(true) ->getConfigurableAttributes($product); $selectedAttributes = array(); if ($product->getCustomOption('attributes')) { $selectedAttributes = unserialize($product->getCustomOption('attributes')->getValue()); } $childProduct = Mage::getModel('catalog/product_type_configurable')->getProductByAttributes($selectedAttributes, $product); $id = $childProduct->getId(); return Mage::getModel("catalog/product")->load($id)->getFinalPrice($qty); } |
Hope this tutorial helped you to override configurable product prices with associated simple product prices. Let me know how you have used this functionality in your Magento and feel free to ask your questions through commenting, I’ll be glad to help you!
Can you tell me the exact route to where the code should go?
thanks!
Can you tell me the exact route to where the code should go?
thanks!
Does this set the prices of all configurable products across the store to that of their simple products – and similarly, does this take into account the tax of the simple product over that of the configurable product?
Thanks
This code take simple product price in calculation instead of configurable product price.
For Tax calculation, It considers according to main configurable product setting not based on simple product.
Does this set the prices of all configurable products across the store to that of their simple products – and similarly, does this take into account the tax of the simple product over that of the configurable product?
Thanks
This code take simple product price in calculation instead of configurable product price.
For Tax calculation, It considers according to main configurable product setting not based on simple product.