From 766fdc0f05c32eecf48f936bc755e7d9ec72b4ae Mon Sep 17 00:00:00 2001 From: Will Palmer Date: Thu, 26 Nov 2015 02:00:12 +0000 Subject: [PATCH] Only output transactionShippingMethod for non-virtual Orders transactionShippingMethod was unconditionally attempting to output the shipping "Carrier Code". This is fine in most cases, but for "virtual" orders, no CarrierCode is defined, resulting in an illegal offset error (internal to Magento) when the non-existent carrier information is requested. To avoid this, add a ->getIsVirtual() check on the $order, and only request Shipping Carrier information for non-Virtual orders. This is the same logic (though not exactly the same method) used within core Magento code within the Checkout process, and so appears to be an expected condition for accessing such data. --- app/code/community/CVM/GoogleTagManager/Block/Gtm.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/community/CVM/GoogleTagManager/Block/Gtm.php b/app/code/community/CVM/GoogleTagManager/Block/Gtm.php index fc8859e..76c1c24 100644 --- a/app/code/community/CVM/GoogleTagManager/Block/Gtm.php +++ b/app/code/community/CVM/GoogleTagManager/Block/Gtm.php @@ -89,7 +89,7 @@ protected function _getTransactionData() 'transactionTax' => round($order->getBaseTaxAmount(),2), 'transactionPaymentType' => $order->getPayment()->getMethodInstance()->getTitle(), 'transactionCurrency' => $order->getOrderCurrencyCode(), - 'transactionShippingMethod' => $order->getShippingCarrier()->getCarrierCode(), + 'transactionShippingMethod' => ($order->getIsVirtual() ? '' : $order->getShippingCarrier()->getCarrierCode()), 'transactionPromoCode' => $order->getCouponCode(), 'transactionProducts' => array() ); @@ -99,7 +99,7 @@ protected function _getTransactionData() $data['transactionTotal'] += $order->getBaseGrandTotal(); $data['transactionShipping'] += $order->getBaseShippingAmount(); $data['transactionTax'] += $order->getBaseTaxAmount(); - $data['transactionShippingMethod'] .= '|'.$order->getShippingCarrier()->getCarrierCode(); + $data['transactionShippingMethod'] .= '|'.($order->getIsVirtual() ? '' : $order->getShippingCarrier()->getCarrierCode()); } // Build products array.