Created
January 31, 2013 09:45
-
-
Save pkdavies/4681728 to your computer and use it in GitHub Desktop.
workaround in case if item subtotal precision is not compatible with PayPal (.2)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git app/code/core/Mage/Paypal/Model/Cart.php app/code/core/Mage/Paypal/Model/Cart.php | |
index 999d3b8..4d625ca 100644 | |
--- app/code/core/Mage/Paypal/Model/Cart.php | |
+++ app/code/core/Mage/Paypal/Model/Cart.php | |
@@ -281,9 +281,11 @@ class Mage_Paypal_Model_Cart | |
// regular items from the sales entity | |
$this->_items = array(); | |
+ $excludeTaxSum = 0; | |
foreach ($this->_salesEntity->getAllItems() as $item) { | |
if (!$item->getParentItem()) { | |
$this->_addRegularItem($item); | |
+ $excludeTaxSum += $item->getExcludeTax(); | |
} | |
} | |
end($this->_items); | |
@@ -294,8 +296,8 @@ class Mage_Paypal_Model_Cart | |
if ($this->_salesEntity instanceof Mage_Sales_Model_Order) { | |
$shippingDescription = $this->_salesEntity->getShippingDescription(); | |
$this->_totals = array( | |
- self::TOTAL_SUBTOTAL => $this->_salesEntity->getBaseSubtotal(), | |
- self::TOTAL_TAX => $this->_salesEntity->getBaseTaxAmount(), | |
+ self::TOTAL_SUBTOTAL => $this->_salesEntity->getBaseSubtotal() + $excludeTaxSum, | |
+ self::TOTAL_TAX => $this->_salesEntity->getBaseTaxAmount() - $excludeTaxSum, | |
self::TOTAL_SHIPPING => $this->_salesEntity->getBaseShippingAmount(), | |
self::TOTAL_DISCOUNT => abs($this->_salesEntity->getBaseDiscountAmount()), | |
); | |
@@ -305,8 +307,8 @@ class Mage_Paypal_Model_Cart | |
$this->_salesEntity->getBillingAddress() : $this->_salesEntity->getShippingAddress(); | |
$shippingDescription = $address->getShippingDescription(); | |
$this->_totals = array ( | |
- self::TOTAL_SUBTOTAL => $this->_salesEntity->getBaseSubtotal(), | |
- self::TOTAL_TAX => $address->getBaseTaxAmount(), | |
+ self::TOTAL_SUBTOTAL => $this->_salesEntity->getBaseSubtotal() + $excludeTaxSum, | |
+ self::TOTAL_TAX => $address->getBaseTaxAmount() - $excludeTaxSum, | |
self::TOTAL_SHIPPING => $address->getBaseShippingAmount(), | |
self::TOTAL_DISCOUNT => abs($address->getBaseDiscountAmount()), | |
); | |
@@ -423,27 +425,38 @@ class Mage_Paypal_Model_Cart | |
*/ | |
protected function _addRegularItem(Varien_Object $salesItem) | |
{ | |
+ $subAggregatedLabel = ''; | |
if ($this->_salesEntity instanceof Mage_Sales_Model_Order) { | |
$qty = (int) $salesItem->getQtyOrdered(); | |
$amount = (float) $salesItem->getBasePrice(); | |
+ | |
+ $rowTotal = $salesItem->getBaseRowTotal(); | |
+ $priceIncTax = $salesItem->getBasePriceInclTax(); | |
+ $taxAmount = $salesItem->getBaseTaxAmount(); | |
// TODO: nominal item for order | |
} else { | |
+ /** | |
+ * now we have quote - regular place order process | |
+ */ | |
$qty = (int) $salesItem->getTotalQty(); | |
$amount = $salesItem->isNominal() ? 0 : (float) $salesItem->getBaseCalculationPrice(); | |
- } | |
- // workaround in case if item subtotal precision is not compatible with PayPal (.2) | |
- $subAggregatedLabel = ''; | |
- if ($amount - round($amount, 2)) { | |
- $amount = $amount * $qty; | |
- $subAggregatedLabel = ' x' . $qty; | |
- $qty = 1; | |
+ | |
+ $rowTotal = $salesItem->getRowTotal(); | |
+ $priceIncTax = $salesItem->getPriceInclTax(); | |
+ $taxAmount = $salesItem->getTaxAmount(); | |
} | |
- // aggregate item price if item qty * price does not match row total | |
- if (($amount * $qty) != $salesItem->getBaseRowTotal()) { | |
- $amount = (float) $salesItem->getBaseRowTotal(); | |
- $subAggregatedLabel = ' x' . $qty; | |
- $qty = 1; | |
+ /** | |
+ * aggregate item price if item qty * price does not match row total | |
+ * workaround in case if item subtotal precision is not compatible with PayPal (.2) | |
+ */ | |
+ $salesItem->setExcludeTax(0); | |
+ if (($amount * $qty) != $rowTotal | |
+ || ($amount - round($amount, 2)) | |
+ ) { | |
+ $amount = $priceIncTax; | |
+ $subAggregatedLabel = Mage::helper('tax')->__(' (Incl. Tax)'); | |
+ $salesItem->setExcludeTax($taxAmount); | |
} | |
return $this->addItem($salesItem->getName() . $subAggregatedLabel, $qty, $amount, $salesItem->getSku()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment