0

I need your help in solving one of my issue related to adding extra/custom price on subtotal on cart page. I have called a observer for checkout_cart_product_add_after and sales_convert_quote_item_to_order_item event and in which I am trying to add dynamic price from below code

$item->setCustomPrice($price);
$item->setOriginalCustomPrice($price);

This is allow me add in unit Price but I want to add in Subtotal of product. Also I have to tried to add price via custom options but it adds in Additional_optional field and not stored in info_buyrequest so might it not reflect to the subtotal price.

Please advise for suggestion.

Thanks

  • Can you do it using promotions->shopping cart price rules? You can define your rule there to add your extra price. – Kishor Mar 10 '15 at 5:37
  • No kishor! I want to add dynamically or product wise. So I need to do from observer. – Vick Mar 10 '15 at 5:38
  • Try mageworx multifee extension – ladle3000 Mar 10 '15 at 17:34
  • Hey! Its paid extension and I want to done by programmatically I have create some dynamic custom options based on products and their price. – Vick Mar 11 '15 at 5:18
  • Yeah, not everything is free in live. But maybe we cannot make it for less than what that kind of module cost. So it is either some kind of (payed) module or default Magento. Or create your own module – Jeroen Mar 12 '15 at 19:18
1

You can accomplished this by overriding Mage_Sales_Model_Quote_Item via modules config.xml:

<global>
    <models>
        <sales>
            <rewrite>                    
            <quote_item>Namespace_Module_Model_Quote_Item</quote_item>
            </rewrite>
        </sales>
    </models>
</global>

And then overriding the calcRowTotal()

class Namespace_Module_Model_Quote_Item extends Mage_Sales_Model_Quote_Item
{
    protected $customRowTotalPrice = null;

    public function setCustomRowTotalPrice($price)
    {
        $this->customRowTotalPrice = $price;
    }

    public function calcRowTotal()
    {
        if ($this->customRowTotalPrice !== null) {
            $this->setRowTotal($this->getStore()->roundPrice($this->customRowTotalPrice));
            $this->setBaseRowTotal($this->getStore()->roundPrice($this->customRowTotalPrice));
            return $this;
        }

        $qty = $this->getTotalQty();
        $total = $this->getStore()->roundPrice($this->getCalculationPriceOriginal()) * $qty;
        $baseTotal = $this->getStore()->roundPrice($this->getBaseCalculationPriceOriginal()) * $qty;

        $this->setRowTotal($this->getStore()->roundPrice($total));
        $this->setBaseRowTotal($this->getStore()->roundPrice($baseTotal));
        return $this;
    }

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.