Reputation: 10790
I pretty idea on whats going on. I have no clue on how to fix it. Since I asked paypal to include line items, it calculates the total line items but they do not match up with the grand total.
<sales>
<quote>
<totals>
<biddiscount>
<class>winints/biddiscount</class>
<before>subtotal</before>
</biddiscount>
<globaldiscount>
<class>winints/globaldiscount</class>
<before>subtotal</before>
</globaldiscount>
</totals>
</quote>
</sales>
<?php
/**
* Created by PhpStorm.
* User: numerical25
* Date: 5/17/14
* Time: 7:49 PM
*/
class Superior_WinInts_Model_Globaldiscount extends Mage_Sales_Model_Quote_Address_Total_Subtotal {
protected $amount = 0;
protected $set = 0;
public function collect(Mage_Sales_Model_Quote_Address $address) {
if ($address->getData('address_type') == 'billing')
return $this;
$discount = Mage::app()->getRequest()->getParam('global_discount_amount');
$grandTotal = $address->getGrandTotal();
$baseGrandTotal = $address->getBaseGrandTotal();
if(Mage::getSingleton('customer/session')->isLoggedIn() && $discount) {
$customer = Mage::getModel('customer/customer')->load(Mage::getSingleton('customer/session')->getId());
$credit = Mage::getModel("winints/wallet")
->getCustomerStoreCreditTotal($customer->getId());
if($credit >= $discount) {
$this->amount = $discount;
}
Mage::getSingleton('core/session')->setGlobalDiscount($discount);
$totals = array_sum($address->getAllTotalAmounts());
$baseTotals = array_sum($address->getAllBaseTotalAmounts());
//You have to set Grand and Base Grand Total for this crap to work
$address->setDiscountAmount(-$discount);
$address->setBaseDiscountAmount(-$discount);
$address->setGrandTotal($grandTotal - $discount);
$address->setBaseGrandTotal($baseGrandTotal - $discount);
$address->setSubtotal($baseGrandTotal - $discount);
} else if (Mage::getSingleton('core/session')->getGlobalDiscount()) {
$discount = Mage::getSingleton('core/session')->getGlobalDiscount();
$this->amount = Mage::getSingleton('core/session')->getGlobalDiscount();
$address->setDiscountAmount(-$discount);
$address->setBaseDiscountAmount(-$discount);
$address->setGrandTotal($grandTotal - $discount);
$address->setBaseGrandTotal($baseGrandTotal - $discount);
$address->setSubtotal($baseGrandTotal - $discount);
}
return $this;
}
public function fetch(Mage_Sales_Model_Quote_Address $address)
{
if(Mage::getSingleton('core/session')->getGlobalDiscount()) {
if(!$this->set) {
$address->addTotal(array(
'code'=>$this->getCode(),
'title'=>Mage::helper('catalog')->__('Global Discount (-)'),
'value'=> $this->amount
));
$this->set = 1;
}
}
return $this;
}
}
I've done everything that the tutorials told me, I tried to update the base total, grand total, subtotal, everything. It still doesnt match up correctly
What I am I doing wrong ??
There are other post but they are not clear. Clearly the line items calculate incorrectly from the grand total. .
Upvotes: 0
Views: 443
Reputation: 10790
Figured it out and YES the references online are incorrect.
In your config xml
<globaldiscount>
<class>winints/globaldiscount</class>
<before>subtotal</before>
</globaldiscount>
change the before to and value within the tag should be "grand_total"
<after>grand_total</after>
If you place it before or after subtotal, your discount will not take notice of the grand total because the grand total is calculated last.
So your code might calculate the subtotal but not calculate a grand total which could give a inaccurate estimate to paypal
Upvotes: 1