Skip to content

Instantly share code, notes, and snippets.

@pkdavies
Created March 4, 2013 09:29
Show Gist options
  • Save pkdavies/5081065 to your computer and use it in GitHub Desktop.
Save pkdavies/5081065 to your computer and use it in GitHub Desktop.
First please revert the previous patch we sent you by running the command below from within your Magento directory: patch -p0 -R < SUPEE-991_EE_1.12.0.2_v1.patch Once that has been completed, upload the new patch in your Magento (root) directory, log in via SSH and cd /magento (or root). Once there, run the following command: sh PATCH_SUPEE-991…
#!/bin/bash
# Patch apllying tool template
# v0.1.2
# (c) Copyright 2013. Magento Inc.
#
# DO NOT CHANGE ANY LINE IN THIS FILE.
# 1. Check required system tools
_check_installed_tools() {
local missed=""
until [ -z "$1" ]; do
type -t $1 >/dev/null 2>/dev/null
if (( $? != 0 )); then
missed="$missed $1"
fi
shift
done
echo $missed
}
REQUIRED_UTILS='sed patch'
MISSED_REQUIRED_TOOLS=`_check_installed_tools $REQUIRED_UTILS`
if (( `echo $MISSED_REQUIRED_TOOLS | wc -w` > 0 ));
then
echo -e "Error! Some required system tools, that are utilized in this sh script, are not installed:\nTool(s) \"$MISSED_REQUIRED_TOOLS\" is(are) missed, please install it(them)."
exit 1
fi
# 2. Determine bin path for system tools
CAT_BIN=`which cat`
PATCH_BIN=`which patch`
SED_BIN=`which sed`
PWD_BIN=`which pwd`
BASENAME_BIN=`which basename`
BASE_NAME=`$BASENAME_BIN "$0"`
# 3. Help menu
if [ "$1" = "-?" -o "$1" = "-h" -o "$1" = "--help" ]
then
$CAT_BIN << EOFH
Usage: sh $BASE_NAME [--help] [-R|--revert] [--list]
Apply embedded patch.
-R, --revert Revert previously applied embedded patch
--list Show list of applied patches
--help Show this help message
EOFH
exit 0
fi
# 4. Get "revert" flag and "list applied patches" flag
REVERT_FLAG=
SHOW_APPLIED_LIST=0
if [ "$1" = "-R" -o "$1" = "--revert" ]
then
REVERT_FLAG=-R
fi
if [ "$1" = "--list" ]
then
SHOW_APPLIED_LIST=1
fi
# 5. File pathes
CURRENT_DIR=`$PWD_BIN`/
APP_ETC_DIR=`echo "$CURRENT_DIR""app/etc/"`
APPLIED_PATCHES_LIST_FILE=`echo "$APP_ETC_DIR""applied.patches.list"`
# 6. Show applied patches list if requested
if [ "$SHOW_APPLIED_LIST" -eq 1 ] ; then
echo -e "Applied/reverted patches list:"
if [ -e "$APPLIED_PATCHES_LIST_FILE" ]
then
if [ ! -r "$APPLIED_PATCHES_LIST_FILE" ]
then
echo "ERROR: \"$APPLIED_PATCHES_LIST_FILE\" must be readable so applied patches list can be shown."
exit 1
else
$SED_BIN -n "/SUP-\|SUPEE-/p" $APPLIED_PATCHES_LIST_FILE
fi
else
echo "<empty>"
fi
exit 0
fi
# 7. Check applied patches track file and its directory
_check_files() {
if [ ! -e "$APP_ETC_DIR" ]
then
echo "ERROR: \"$APP_ETC_DIR\" must exist for proper tool work."
exit 1
fi
if [ ! -w "$APP_ETC_DIR" ]
then
echo "ERROR: \"$APP_ETC_DIR\" must be writeable for proper tool work."
exit 1
fi
if [ -e "$APPLIED_PATCHES_LIST_FILE" ]
then
if [ ! -w "$APPLIED_PATCHES_LIST_FILE" ]
then
echo "ERROR: \"$APPLIED_PATCHES_LIST_FILE\" must be writeable for proper tool work."
exit 1
fi
fi
}
_check_files
# 8. Apply/revert patch
# Note: there is no need to check files permissions for files to be patched.
# "patch" tool will not modify any file if there is not enough permissions for all files to be modified.
# Get start points for additional information and patch data
SKIP_LINES=$((`$SED_BIN -n "/^__PATCHFILE_FOLLOWS__$/=" "$CURRENT_DIR""$BASE_NAME"` + 1))
ADDITIONAL_INFO_LINE=$(($SKIP_LINES - 3))p
_apply_revert_patch() {
DRY_RUN_FLAG=
if [ "$1" = "dry-run" ]
then
DRY_RUN_FLAG=" --dry-run"
echo "Checking if patch can be applied/reverted successfully..."
fi
PATCH_APPLY_REVERT_RESULT=`$SED_BIN -e '1,/^__PATCHFILE_FOLLOWS__$/d' "$CURRENT_DIR""$BASE_NAME" | $PATCH_BIN $DRY_RUN_FLAG $REVERT_FLAG -p0`
PATCH_APPLY_REVERT_STATUS=$?
if [ $PATCH_APPLY_REVERT_STATUS -eq 1 ] ; then
echo -e "ERROR: Patch can't be applied/reverted successfully.\n\n$PATCH_APPLY_REVERT_RESULT"
exit 1
fi
if [ $PATCH_APPLY_REVERT_STATUS -eq 2 ] ; then
echo -e "ERROR: Patch can't be applied/reverted successfully."
exit 2
fi
}
REVERTED_PATCH_MARK=
if [ -n "$REVERT_FLAG" ]
then
REVERTED_PATCH_MARK=" | REVERTED"
fi
_apply_revert_patch dry-run
_apply_revert_patch
# 9. Track patch applying result
echo "Patch was applied/reverted successfully."
ADDITIONAL_INFO=`$SED_BIN -n ""$ADDITIONAL_INFO_LINE"" "$CURRENT_DIR""$BASE_NAME"`
APPLIED_REVERTED_ON_DATE=`date -u +"%F %T UTC"`
APPLIED_REVERTED_PATCH_INFO=`echo -n "$APPLIED_REVERTED_ON_DATE"" | ""$ADDITIONAL_INFO""$REVERTED_PATCH_MARK"`
echo -e "$APPLIED_REVERTED_PATCH_INFO\n$PATCH_APPLY_REVERT_RESULT\n\n" >> "$APPLIED_PATCHES_LIST_FILE"
exit 0
SUPEE-991 | EE_1.12.0.2 | v2 | 292b25f7c8544557848ab8f640bd0c5e4bdc9075 | Wed Feb 27 12:40:49 2013 +0200 | v1.12.0.2..SUPEE-991
__PATCHFILE_FOLLOWS__
diff --git app/code/core/Mage/Paypal/Model/Cart.php app/code/core/Mage/Paypal/Model/Cart.php
index 999d3b8..83f7ce9 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,6 +425,7 @@ 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();
@@ -431,19 +434,16 @@ class Mage_Paypal_Model_Cart
$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;
- }
- // 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) != $salesItem->getBaseRowTotal() || ($amount - round($amount, 2))) {
+ $amount = $salesItem->getBasePriceInclTax();
+ $subAggregatedLabel = Mage::helper('tax')->__(' (Incl. Tax)');
+ $salesItem->setExcludeTax($salesItem->getBaseTaxAmount());
}
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