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);
}else{
$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;
$product->setFinalPrice($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.