How to get price for configurable product Planned maintenance scheduled April 17/18, 2019 at...

How many spell slots should a Fighter 11/Ranger 9 have?

Two different pronunciation of "понял"

What are the performance impacts of 'functional' Rust?

How should I respond to a player wanting to catch a sword between their hands?

How are presidential pardons supposed to be used?

If A makes B more likely then B makes A more likely"

How is simplicity better than precision and clarity in prose?

Does a C shift expression have unsigned type? Why would Splint warn about a right-shift?

Autumning in love

Replacing HDD with SSD; what about non-APFS/APFS?

What was the last x86 CPU that did not have the x87 floating-point unit built in?

What computer would be fastest for Mathematica Home Edition?

Problem when applying foreach loop

Active filter with series inductor and resistor - do these exist?

Am I ethically obligated to go into work on an off day if the reason is sudden?

Is it possible to ask for a hotel room without minibar/extra services?

Is above average number of years spent on PhD considered a red flag in future academia or industry positions?

Losing the Initialization Vector in Cipher Block Chaining

Can a zero nonce be safely used with AES-GCM if the key is random and never used again?

How did the aliens keep their waters separated?

Cold is to Refrigerator as warm is to?

Working around an AWS network ACL rule limit

Complexity of many constant time steps with occasional logarithmic steps

Why is there no army of Iron-Mans in the MCU?



How to get price for configurable product



Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?show different product price using observerCreate invoice and shipment in magento via cron based on store view and order ageExclude a specific categoryMagento: Adding block from observer programmaticallycatalog_product_load_before event gives getRequestedRouteName() errorcatalog_product_collection_load_after causing maximum nesting issue for configurable productsSet custom price of product when adding to cart code not workingHow to change dynamic attributes when simple product is selectedMagento 2 plugin change price of products that have a custom attribute with





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















I have configurable products like



enter image description here



I created observer and I got the price



Default price is for 1kg but customer can change the weight and flavor.



When customer changes weight and flavor price changes.



like



enter image description here



enter image description here



I created observer in that I have code like



public function saveProductMrpInOrder(Varien_Event_Observer $observer) {
$order = $observer->getEvent()->getOrder();
foreach($order->getAllItems() as $item) {
$price = Mage::getModel('catalog/product')->load($item->getId())->getPrice();
$item->setProductMrp($price);
}
return $this;
}

public function saveProductMrpInInvoice(Varien_Event_Observer $observer) {
$invoice = $observer->getEvent()->getInvoice();
foreach($invoice->getAllItems() as $item) {
$price = Mage::getModel('catalog/product')->load($item->getProductId())->getPrice();
$item->setProductMrp($price);
}
return $this;
}

public function saveProductMrpInShipment(Varien_Event_Observer $observer)
{
$shipment = $observer->getEvent()->getShipment();
foreach($shipment->getAllItems() as $item) {
$product = Mage::getModel('catalog/product')->load($item->getProductId());
$price = $product->getPrice();
$item->product_mrp = $price;
}
}


But in that I am getting default price which is for 1kg



But I want price for product according to attributes selected



How can I get that price.



Hope you understand.










share|improve this question
















bumped to the homepage by Community 3 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • I think you need the price of simple products. simple products are variant of configurable product

    – Moyed Ansari
    Mar 28 '16 at 6:49











  • How can I get price for that @MoyedAnsari

    – Jatin Raikwar
    Mar 28 '16 at 7:05


















0















I have configurable products like



enter image description here



I created observer and I got the price



Default price is for 1kg but customer can change the weight and flavor.



When customer changes weight and flavor price changes.



like



enter image description here



enter image description here



I created observer in that I have code like



public function saveProductMrpInOrder(Varien_Event_Observer $observer) {
$order = $observer->getEvent()->getOrder();
foreach($order->getAllItems() as $item) {
$price = Mage::getModel('catalog/product')->load($item->getId())->getPrice();
$item->setProductMrp($price);
}
return $this;
}

public function saveProductMrpInInvoice(Varien_Event_Observer $observer) {
$invoice = $observer->getEvent()->getInvoice();
foreach($invoice->getAllItems() as $item) {
$price = Mage::getModel('catalog/product')->load($item->getProductId())->getPrice();
$item->setProductMrp($price);
}
return $this;
}

public function saveProductMrpInShipment(Varien_Event_Observer $observer)
{
$shipment = $observer->getEvent()->getShipment();
foreach($shipment->getAllItems() as $item) {
$product = Mage::getModel('catalog/product')->load($item->getProductId());
$price = $product->getPrice();
$item->product_mrp = $price;
}
}


But in that I am getting default price which is for 1kg



But I want price for product according to attributes selected



How can I get that price.



Hope you understand.










share|improve this question
















bumped to the homepage by Community 3 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • I think you need the price of simple products. simple products are variant of configurable product

    – Moyed Ansari
    Mar 28 '16 at 6:49











  • How can I get price for that @MoyedAnsari

    – Jatin Raikwar
    Mar 28 '16 at 7:05














0












0








0








I have configurable products like



enter image description here



I created observer and I got the price



Default price is for 1kg but customer can change the weight and flavor.



When customer changes weight and flavor price changes.



like



enter image description here



enter image description here



I created observer in that I have code like



public function saveProductMrpInOrder(Varien_Event_Observer $observer) {
$order = $observer->getEvent()->getOrder();
foreach($order->getAllItems() as $item) {
$price = Mage::getModel('catalog/product')->load($item->getId())->getPrice();
$item->setProductMrp($price);
}
return $this;
}

public function saveProductMrpInInvoice(Varien_Event_Observer $observer) {
$invoice = $observer->getEvent()->getInvoice();
foreach($invoice->getAllItems() as $item) {
$price = Mage::getModel('catalog/product')->load($item->getProductId())->getPrice();
$item->setProductMrp($price);
}
return $this;
}

public function saveProductMrpInShipment(Varien_Event_Observer $observer)
{
$shipment = $observer->getEvent()->getShipment();
foreach($shipment->getAllItems() as $item) {
$product = Mage::getModel('catalog/product')->load($item->getProductId());
$price = $product->getPrice();
$item->product_mrp = $price;
}
}


But in that I am getting default price which is for 1kg



But I want price for product according to attributes selected



How can I get that price.



Hope you understand.










share|improve this question
















I have configurable products like



enter image description here



I created observer and I got the price



Default price is for 1kg but customer can change the weight and flavor.



When customer changes weight and flavor price changes.



like



enter image description here



enter image description here



I created observer in that I have code like



public function saveProductMrpInOrder(Varien_Event_Observer $observer) {
$order = $observer->getEvent()->getOrder();
foreach($order->getAllItems() as $item) {
$price = Mage::getModel('catalog/product')->load($item->getId())->getPrice();
$item->setProductMrp($price);
}
return $this;
}

public function saveProductMrpInInvoice(Varien_Event_Observer $observer) {
$invoice = $observer->getEvent()->getInvoice();
foreach($invoice->getAllItems() as $item) {
$price = Mage::getModel('catalog/product')->load($item->getProductId())->getPrice();
$item->setProductMrp($price);
}
return $this;
}

public function saveProductMrpInShipment(Varien_Event_Observer $observer)
{
$shipment = $observer->getEvent()->getShipment();
foreach($shipment->getAllItems() as $item) {
$product = Mage::getModel('catalog/product')->load($item->getProductId());
$price = $product->getPrice();
$item->product_mrp = $price;
}
}


But in that I am getting default price which is for 1kg



But I want price for product according to attributes selected



How can I get that price.



Hope you understand.







magento-1.9 configurable-product price event-observer






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 '16 at 12:34







Jatin Raikwar

















asked Mar 28 '16 at 6:35









Jatin RaikwarJatin Raikwar

224320




224320





bumped to the homepage by Community 3 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 3 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • I think you need the price of simple products. simple products are variant of configurable product

    – Moyed Ansari
    Mar 28 '16 at 6:49











  • How can I get price for that @MoyedAnsari

    – Jatin Raikwar
    Mar 28 '16 at 7:05



















  • I think you need the price of simple products. simple products are variant of configurable product

    – Moyed Ansari
    Mar 28 '16 at 6:49











  • How can I get price for that @MoyedAnsari

    – Jatin Raikwar
    Mar 28 '16 at 7:05

















I think you need the price of simple products. simple products are variant of configurable product

– Moyed Ansari
Mar 28 '16 at 6:49





I think you need the price of simple products. simple products are variant of configurable product

– Moyed Ansari
Mar 28 '16 at 6:49













How can I get price for that @MoyedAnsari

– Jatin Raikwar
Mar 28 '16 at 7:05





How can I get price for that @MoyedAnsari

– Jatin Raikwar
Mar 28 '16 at 7:05










2 Answers
2






active

oldest

votes


















0














Try this



if($_product->getTypeId() == "configurable"):
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
$simple_collection = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
foreach($simple_collection as $simple_product){
echo $simple_product->getSku() . " - " . $simple_product->getName() . " - " . Mage::helper('core')->currency($simple_product->getPrice()) . "<br>";
}
endif;





share|improve this answer
























  • Its not working. showing error Notice: Undefined variable: _product

    – Jatin Raikwar
    Mar 28 '16 at 12:25











  • where do you get product collection ?

    – Moyed Ansari
    Mar 28 '16 at 13:36











  • I call event as I putted code in question. Where should I put your code???

    – Jatin Raikwar
    Mar 29 '16 at 6:39



















0














From your question, it is not sure in which context you need to get the configurable product price.



In any context what you are missing is, you need to populate custom attribute options of the configurable product. After that, when you call getFinalPrice() on your configurable product instance you will get the correct price.



For more details, you can refer my blog post here. It shows how can populate custom attribute options of the configurable product if we have both configurable product and corresponding associated product.



For quick reference, I am adding the code snippet here.



$product        = Mage::getModel('catalog/product')->load(357); //configurable product
$optProduct = Mage::getModel('catalog/product')->load(282); //associated simple product
$confAttributes = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
$pdtOptValues = array();
foreach ($confAttributes as $attribute) {
$attrCode = $attribute['attribute_code'];
$attrId = $attribute['attribute_id'];
$optionValue = $optProduct->getData($attrCode);
$pdtOptValues[$attrId] = $optionValue;
}
$product->addCustomOption('attributes', serialize($pdtOptValues));
echo $product->getFinalPrice();





share|improve this answer
























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "479"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f108176%2fhow-to-get-price-for-configurable-product%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Try this



    if($_product->getTypeId() == "configurable"):
    $conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
    $simple_collection = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
    foreach($simple_collection as $simple_product){
    echo $simple_product->getSku() . " - " . $simple_product->getName() . " - " . Mage::helper('core')->currency($simple_product->getPrice()) . "<br>";
    }
    endif;





    share|improve this answer
























    • Its not working. showing error Notice: Undefined variable: _product

      – Jatin Raikwar
      Mar 28 '16 at 12:25











    • where do you get product collection ?

      – Moyed Ansari
      Mar 28 '16 at 13:36











    • I call event as I putted code in question. Where should I put your code???

      – Jatin Raikwar
      Mar 29 '16 at 6:39
















    0














    Try this



    if($_product->getTypeId() == "configurable"):
    $conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
    $simple_collection = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
    foreach($simple_collection as $simple_product){
    echo $simple_product->getSku() . " - " . $simple_product->getName() . " - " . Mage::helper('core')->currency($simple_product->getPrice()) . "<br>";
    }
    endif;





    share|improve this answer
























    • Its not working. showing error Notice: Undefined variable: _product

      – Jatin Raikwar
      Mar 28 '16 at 12:25











    • where do you get product collection ?

      – Moyed Ansari
      Mar 28 '16 at 13:36











    • I call event as I putted code in question. Where should I put your code???

      – Jatin Raikwar
      Mar 29 '16 at 6:39














    0












    0








    0







    Try this



    if($_product->getTypeId() == "configurable"):
    $conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
    $simple_collection = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
    foreach($simple_collection as $simple_product){
    echo $simple_product->getSku() . " - " . $simple_product->getName() . " - " . Mage::helper('core')->currency($simple_product->getPrice()) . "<br>";
    }
    endif;





    share|improve this answer













    Try this



    if($_product->getTypeId() == "configurable"):
    $conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
    $simple_collection = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
    foreach($simple_collection as $simple_product){
    echo $simple_product->getSku() . " - " . $simple_product->getName() . " - " . Mage::helper('core')->currency($simple_product->getPrice()) . "<br>";
    }
    endif;






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 28 '16 at 7:15









    Moyed AnsariMoyed Ansari

    1013




    1013













    • Its not working. showing error Notice: Undefined variable: _product

      – Jatin Raikwar
      Mar 28 '16 at 12:25











    • where do you get product collection ?

      – Moyed Ansari
      Mar 28 '16 at 13:36











    • I call event as I putted code in question. Where should I put your code???

      – Jatin Raikwar
      Mar 29 '16 at 6:39



















    • Its not working. showing error Notice: Undefined variable: _product

      – Jatin Raikwar
      Mar 28 '16 at 12:25











    • where do you get product collection ?

      – Moyed Ansari
      Mar 28 '16 at 13:36











    • I call event as I putted code in question. Where should I put your code???

      – Jatin Raikwar
      Mar 29 '16 at 6:39

















    Its not working. showing error Notice: Undefined variable: _product

    – Jatin Raikwar
    Mar 28 '16 at 12:25





    Its not working. showing error Notice: Undefined variable: _product

    – Jatin Raikwar
    Mar 28 '16 at 12:25













    where do you get product collection ?

    – Moyed Ansari
    Mar 28 '16 at 13:36





    where do you get product collection ?

    – Moyed Ansari
    Mar 28 '16 at 13:36













    I call event as I putted code in question. Where should I put your code???

    – Jatin Raikwar
    Mar 29 '16 at 6:39





    I call event as I putted code in question. Where should I put your code???

    – Jatin Raikwar
    Mar 29 '16 at 6:39













    0














    From your question, it is not sure in which context you need to get the configurable product price.



    In any context what you are missing is, you need to populate custom attribute options of the configurable product. After that, when you call getFinalPrice() on your configurable product instance you will get the correct price.



    For more details, you can refer my blog post here. It shows how can populate custom attribute options of the configurable product if we have both configurable product and corresponding associated product.



    For quick reference, I am adding the code snippet here.



    $product        = Mage::getModel('catalog/product')->load(357); //configurable product
    $optProduct = Mage::getModel('catalog/product')->load(282); //associated simple product
    $confAttributes = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
    $pdtOptValues = array();
    foreach ($confAttributes as $attribute) {
    $attrCode = $attribute['attribute_code'];
    $attrId = $attribute['attribute_id'];
    $optionValue = $optProduct->getData($attrCode);
    $pdtOptValues[$attrId] = $optionValue;
    }
    $product->addCustomOption('attributes', serialize($pdtOptValues));
    echo $product->getFinalPrice();





    share|improve this answer




























      0














      From your question, it is not sure in which context you need to get the configurable product price.



      In any context what you are missing is, you need to populate custom attribute options of the configurable product. After that, when you call getFinalPrice() on your configurable product instance you will get the correct price.



      For more details, you can refer my blog post here. It shows how can populate custom attribute options of the configurable product if we have both configurable product and corresponding associated product.



      For quick reference, I am adding the code snippet here.



      $product        = Mage::getModel('catalog/product')->load(357); //configurable product
      $optProduct = Mage::getModel('catalog/product')->load(282); //associated simple product
      $confAttributes = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
      $pdtOptValues = array();
      foreach ($confAttributes as $attribute) {
      $attrCode = $attribute['attribute_code'];
      $attrId = $attribute['attribute_id'];
      $optionValue = $optProduct->getData($attrCode);
      $pdtOptValues[$attrId] = $optionValue;
      }
      $product->addCustomOption('attributes', serialize($pdtOptValues));
      echo $product->getFinalPrice();





      share|improve this answer


























        0












        0








        0







        From your question, it is not sure in which context you need to get the configurable product price.



        In any context what you are missing is, you need to populate custom attribute options of the configurable product. After that, when you call getFinalPrice() on your configurable product instance you will get the correct price.



        For more details, you can refer my blog post here. It shows how can populate custom attribute options of the configurable product if we have both configurable product and corresponding associated product.



        For quick reference, I am adding the code snippet here.



        $product        = Mage::getModel('catalog/product')->load(357); //configurable product
        $optProduct = Mage::getModel('catalog/product')->load(282); //associated simple product
        $confAttributes = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
        $pdtOptValues = array();
        foreach ($confAttributes as $attribute) {
        $attrCode = $attribute['attribute_code'];
        $attrId = $attribute['attribute_id'];
        $optionValue = $optProduct->getData($attrCode);
        $pdtOptValues[$attrId] = $optionValue;
        }
        $product->addCustomOption('attributes', serialize($pdtOptValues));
        echo $product->getFinalPrice();





        share|improve this answer













        From your question, it is not sure in which context you need to get the configurable product price.



        In any context what you are missing is, you need to populate custom attribute options of the configurable product. After that, when you call getFinalPrice() on your configurable product instance you will get the correct price.



        For more details, you can refer my blog post here. It shows how can populate custom attribute options of the configurable product if we have both configurable product and corresponding associated product.



        For quick reference, I am adding the code snippet here.



        $product        = Mage::getModel('catalog/product')->load(357); //configurable product
        $optProduct = Mage::getModel('catalog/product')->load(282); //associated simple product
        $confAttributes = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
        $pdtOptValues = array();
        foreach ($confAttributes as $attribute) {
        $attrCode = $attribute['attribute_code'];
        $attrId = $attribute['attribute_id'];
        $optionValue = $optProduct->getData($attrCode);
        $pdtOptValues[$attrId] = $optionValue;
        }
        $product->addCustomOption('attributes', serialize($pdtOptValues));
        echo $product->getFinalPrice();






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Oct 14 '17 at 8:02









        Rajeev K TomyRajeev K Tomy

        14.6k54589




        14.6k54589






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f108176%2fhow-to-get-price-for-configurable-product%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            “%fieldName is a required field.”, in Magento2 REST API Call for GET Method Type The Next...

            How to change City field to a dropdown in Checkout step Magento 2Magento 2 : How to change UI field(s)...

            變成蝙蝠會怎樣? 參考資料 外部連結 导航菜单Thomas Nagel, "What is it like to be a...