How to get price for configurable product





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