Skip to content

Commit 5a13f52

Browse files
committed
More fixes to shopping cart items tagging
1 parent bccc52a commit 5a13f52

File tree

1 file changed

+33
-38
lines changed
  • app/code/local/Smashmetrics/Rekko/Block

1 file changed

+33
-38
lines changed

app/code/local/Smashmetrics/Rekko/Block/Rekko.php

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function getOrderDetails()
4444
//Only tag shopping cart pages.
4545
if ($module != 'checkout') {
4646
Mage::log("Not in a cart module. No need to tag order details");
47-
return $orderDet;
47+
return Null;
4848
}
4949

5050
//If this is an order confirmation page.
@@ -140,58 +140,53 @@ public function getCartItems()
140140
$action = $request->getActionName();
141141
$cart = Mage::getSingleton('checkout/session');
142142

143-
$product = array();
144-
145143
//Only tag on checkout pages.
146144
if ($module != 'checkout') {
147-
Mage::log("Not in a cart module. No need to tag order details");
148-
return $product;
145+
Mage::log("Not in a cart module. No need to tag order details returning an empty array");
146+
return Null;
149147
}
150148

151149
//If this is an order confirmation page.
152150
if ($controller == 'onepage' && $action == 'success') {
153151
Mage::log("Getting cart items on confirmation page.");
154152
$orderId = $cart->getLastOrderId();
155153
$order = Mage::getModel('sales/order')->load($orderId);
156-
$ordered_items = $order->getAllItems();
157-
$i = 0;
158-
foreach ($ordered_items as $item) {
159-
$product[$i]['productId'] = $item->getProductId();
160-
$product[$i]['sku'] = $item->getSku();
161-
$product[$i]['name'] = $item->getName();
162-
$product[$i]['qty'] = $item->getQtyOrdered();
163-
$product[$i]['price'] = $item->getPrice();
164-
$_product = Mage::getModel('catalog/product')->load($product[$i]['productId']);
165-
$category = array();
166-
$catIds = $_product->getCategoryIds();
167-
foreach ($catIds AS $cid) {
168-
$category[] = Mage::getModel('catalog/category')->load($cid)->getName();
169-
}
170-
$product[$i]['category'] = implode(',', $category);
171-
172-
$i++;
173-
}
154+
//Get all the visible items (this means parent skus only)
155+
$cartItems = $order->getAllVisibleItems();
174156
} else {
157+
//We are in the checkout process so get teh quote instead.
175158
//We must be still in the checkout process.
176159
Mage::log("Getting cart items on the checkout process (before confirmation page)");
177-
$i = 0;
178-
foreach ($cart->getQuote()->getAllItems() as $item) {
179-
$product[$i]['productId'] = $item->getProductId();
180-
$product[$i]['sku'] = $item->getSku();
181-
$product[$i]['name'] = $item->getName();
182-
$product[$i]['qty'] = $item->getQty();
183-
$product[$i]['price'] = $item->getPrice();
184-
$catIds = $item->getProduct()->getCategoryIds();
185-
$category = array();
186-
foreach ($catIds AS $cid) {
187-
$category[] = Mage::getModel('catalog/category')->load($cid)->getName();
188-
}
189-
$product[$i]['category'] = implode(',', $category);
190-
$i++;
160+
//Get all the visible items (this means parent skus only)
161+
$cartItems = $cart->getQuote()->getAllVisibleItems();
162+
}
163+
$items = array();
164+
$i = 0;
165+
166+
foreach ($cartItems as $item) {
167+
$items[$i]['productId'] = $item->getProductId();
168+
$items[$i]['sku'] = $item->getSku();
169+
$items[$i]['name'] = $item->getName();
170+
//When we are on the confirmation page the method is called getQtyOrdered
171+
//During checkout it is called getQty
172+
if (method_exists($item, "getQtyOrdered")) {
173+
$items[$i]['qty'] = $item->getQtyOrdered();
174+
} else {
175+
$items[$i]['qty'] = $item->getQty();
176+
}
177+
$items[$i]['price'] = $item->getPrice();
178+
$_product = Mage::getModel('catalog/product')->load($items[$i]['productId']);
179+
$category = array();
180+
$catIds = $_product->getCategoryIds();
181+
foreach ($catIds AS $cid) {
182+
$category[] = Mage::getModel('catalog/category')->load($cid)->getName();
191183
}
184+
$items[$i]['category'] = implode(',', $category);
185+
186+
$i++;
192187
}
193188

194-
return $product;
189+
return $items;
195190
}
196191

197192
}

0 commit comments

Comments
 (0)