Categories: How To

How to Override Configurable Product Price with Simple Product Price in Magento

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

  1. Put following code in config.xml for observer.
  2. magecomp/observersimpleProductPrice
  3. Add following functions in Model/Observer.php.
  4. 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!

Click to rate this post!
[Total: 6 Average: 5]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate 🎖️ Certified Magento Developer👨‍💻. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.🏏

View Comments

  • 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.

Recent Posts

How to Integrate ChatGPT with Laravel Application?

In this guide, we'll explore how to integrate ChatGPT, an AI-powered chatbot, with a Laravel…

2 days ago

What are Net Sales? How to Calculate Your Net Sales?

In the world of business, understanding financial metrics is crucial for making informed decisions and…

4 days ago

Magento 2 Extensions Digest April 2024 (New Release & Updates)

Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…

4 days ago

The ABCs of Geofencing: Definition, Features and Uses

In this era, businesses are always on the lookout for ways to engage with their…

5 days ago

How to Delete Product Variant in a Shopify Remix App using GraphQL Mutations?

Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…

6 days ago

6 Innovative Tools Revolutionizing E-Commerce Operations

E-commerce has transformed the way consumers shop for products and services and interact with businesses.…

1 week ago