Update the Price of an item when adding to the cart

by dustbuster   Last Updated November 08, 2018 21:09 PM - source

So here's my project. Make our giftcard integration purchasable.

Basically I need to get an "Enter Custom Amount" input field to update the price of the item. What I have been told by our architect is that I should Update the MyCompany_GiftCard_Model_Product_Type_GiftCard class to extend Mage_Catalog_Model_Product_Type_Abstract

then override the _prepareProduct Method to use the value from the custom amount if defined. So. I made this method:

protected function _prepareProduct(Varien_Object $buyRequest, $product, $processMode) {
    $result = parent::_prepareProduct($buyRequest, $product, $processMode);
    $oRide = $buyRequest->getOverrideAmount();
    $stn_amt = $buyRequest->getAmount();
    $productGiftCard = $buyRequest->getGiftCard();

    if(isset($oRide) && ($oRide != '') && ($oRide != 0) && ($oRide != null)){
        $result[0]->addCustomOption('giftcard_amount', $oRide);
        $result[0]->addCustomOption('giftcard_amount', $amount);

    if (!empty($productGiftCard)) {
        return $result;
    return Mage::helper('catalog')->__('Please specify the required options of product.');

Then I was told to update the getFinalPrice() method to accept the new value from MyCompany_GiftCard_Model_Product_Type_GiftCard_Price

public function getFinalPrice($qty = null, $product)
    $finalPrice = parent::getFinalPrice($qty, $product);
    $amount = $product->getCustomOption('giftcard_amount'); // its an object or false
    if($amount) {
        $finalPrice = $qty * $amount->getValue();
    // echo '<br>finalPrice: '.$finalPrice;
    // echo $product->getData('final_price');
    // Mage_Sales_Model_Quote_Item_Abstract

    return max(0, $product->getData('final_price'));

Here's the thing. If you do: echo $product->getData('final_price')); It totally equals the price I want to be! If the custom amount is set, final_price == custom amount!

Does anyone have any ideas where I'm going wrong and why the GetFinalPrice is not the price for the item in checkout?

(I'm rather new to Magento, 3 months-ish, but our architect was quite adamant that updating the getFinalPrice() method directly update the price in the cart! He's unavailable right now, and I have a deadline. Wondering if any of you fine folks can help!


Related Questions

Set the price for gift option in magento1.9

Updated April 12, 2019 07:09 AM

How to filter gift cards by category

Updated June 21, 2018 15:09 PM

Ajax custom cart not applying shopping rule

Updated March 14, 2019 06:09 AM

Gift Card - Checkout

Updated April 27, 2017 13:09 PM

Magento gift card

Updated June 12, 2017 08:09 AM