Skip to content

Commit

Permalink
Issue #7 - Undefined variable: items
Browse files Browse the repository at this point in the history
  • Loading branch information
srenon authored Jan 16, 2017
1 parent 825ada4 commit 605280f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions app/code/local/MagePal/GoogleTagManager/Model/DataLayer.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ protected function setCartDataLayer() {
$quote = $this->getQuote();
$cart = array();

$cart['hasItems'] = false;

if ($quote->getItemsCount()) {
$cart['hasItems'] = true;
$items = [];

// set items
foreach($quote->getAllVisibleItems() as $item){
Expand All @@ -161,7 +163,10 @@ protected function setCartDataLayer() {
);
}

$cart['items'] = $items;
if(count($items) > 0){
$cart['hasItems'] = true;
$cart['items'] = $items;
}
$cart['total'] = $this->formatPrice($quote->getGrandTotal());
$cart['itemCount'] = $quote->getItemsCount();

Expand All @@ -175,10 +180,8 @@ protected function setCartDataLayer() {
$cart['couponCode'] = $coupon;
}
}
else{
$cart['hasItems'] = false;
}
$this->addVariable('cart', $cart);

$this->addVariable('cart', $cart);

return $this;
}
Expand Down

0 comments on commit 605280f

Please sign in to comment.