Magento Add Shopping Cart Total Price calculation realization method

Source: Internet
Author: User

Add a affiliate points project in.

It took a turn.

First, add in the configuration file

  code is as follows copy code

<global

* * * * * * *

<sales>
<quote>
<totals>
<**>
<class>**/*** </class>
<after>subtotal,freeshipping,tax_subtotal,shipping</after>
<before> Grand_total</before>
</**>
</totals>
<nominal_totals>
<nominal_**>
<class>**/**</class>
<sort_order>550</sort_order>
</nominal_**>
</nominal_totals>
</quote>
</sales>

* * *

</global>

The class under totals is modeled under model classes that must inherit from Mage_sales_model_quote_address_total_abstract, and Nominal_ The class under totals must inherit the class under totals.

The class under totals to implement 2 methods

The code is as follows Copy Code

Public function Collect (mage_sales_model_quote_address $address) {

Parent::collect ($address);

$items = $this->_getaddressitems ($address);
if (!count ($items)) {
return $this;
}

$address->setaffiliatepointsamount (10);
$address->setgrandtotal ($address->getgrandtotal () –10);
$address->setbasegrandtotal ($address->getbasegrandtotal () -10);

Return $this;
}

 

 

Public function fetch (mage_sales_model_quote_address $address)
{
$ Amount = $address->getaffiliatepointsamount ();
if ($amount!= 0) {
$title = Mage::helper (' affiliate ')->__ (' affiliate Points ');
$address->addtotal ( Array (
' code ' => $this->getcode (),
' title ' => $title,
' value ' =>-$amount
));
}

Return $this;
}

 

which

The code is as follows Copy Code
$items = $this->_getaddressitems ($address);
if (!count ($items)) {
return $this;
}

This must be judged, or it may result in a repetitive calculation of prices.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.