1

I am addming a custom surcharge to certain items while following this guide: https://www.classyllama.com/blog/unravel-magento-collecttotal-intro

When looking at the cart now, I see the following (as an example)

Subtotal: 10.00$

Custom: 4.00 $

Grand Total: 10.00$

Clearly the Custom Surcharges are not adding to my total, this is my model:

class MyModel_CustomSurcharge_Model_Sales_Quote_Address_Total_Customsurcharge extends Mage_Sales_Model_Quote_Address_Total_Abstract {

public function __construct()
{
    $this->setCode('custom_surcharge');
}

public function collect(Mage_Sales_Model_Quote_Address $address)
{
    parent::collect($address);

    foreach ($this->_getAddressItems($address) as $item) {
        if (mylogic()) { // placeholder for my logic
             $this->_applyItemSurcharge($item);
        }
    }
    return $this;
}

protected function _applyItemSurcharge($item)
{

    $percentage = 0.06;

    $baseSurcharge = $item->getCustomPrice() * $percentage;

    $surcharge = Mage::app()->getStore()->convertPrice($baseSurcharge);


    $item->setBaseCustomSurchargeAmount($baseSurcharge);
    $item->setCustomSurchargeAmount($surcharge);

    $this->_addBaseAmount($baseSurcharge);
    $this->_addAmount($surcharge);


}

public function fetch(Mage_Sales_Model_Quote_Address $address)
{
    $amount = $address->getCustomSurchargeAmount();
    if ($amount!=0) {
        $address->addTotal(array(
                'code' => $this->getCode(),
                'title' => "Fees",
                'value' => $amount
        ));
    }
    return $this;
}
}

The database is populated with the right values, and also it is showing up in the cart, but is NOT added to the cart total.

any hint for me where the problem is? :)

1 Answer 1

0

I got the solution,

just add

$address->setGrandTotal($address->getGrandTotal() + $address->getCustomSurcharge());

in the _collect function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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