@@ -45,12 +45,15 @@ protected function _getOrdersTrackingCode()
45
45
foreach ($ order ->getAllVisibleItems () as $ item ) {
46
46
47
47
//get category name
48
- $ product_id = $ item ->product_id ;
49
- $ _product = Mage::getModel ('catalog/product ' )->load ($ product_id );
50
- $ cats = $ _product ->getCategoryIds ();
51
- $ category_id = $ cats [0 ]; // just grab the first id
52
- $ category = Mage::getModel ('catalog/category ' )->load ($ category_id );
53
- $ category_name = $ category ->getName ();
48
+ $ productId = $ item ->product_id ;
49
+ $ product = Mage::getModel ('catalog/product ' )->load ($ productId );
50
+ $ categoryName = '' ;
51
+ $ categoryIds = $ product ->getCategoryIds ();
52
+ if (!empty ($ categoryIds )) {
53
+ $ categoryId = $ categoryIds [0 ];
54
+ $ category = Mage::getModel ('catalog/category ' )->load ($ categoryId );
55
+ $ categoryName = $ category ->getName ();
56
+ }
54
57
55
58
56
59
if ($ item ->getQtyOrdered ()) {
@@ -61,7 +64,7 @@ protected function _getOrdersTrackingCode()
61
64
$ result [] = sprintf ("_paq.push(['addEcommerceItem', '%s', '%s', '%s', %s, %s]); " ,
62
65
$ this ->jsQuoteEscape ($ item ->getSku ()),
63
66
$ this ->jsQuoteEscape ($ item ->getName ()),
64
- $ category_name ,
67
+ $ categoryName ,
65
68
$ item ->getBasePrice (),
66
69
$ qty
67
70
);
@@ -101,12 +104,13 @@ protected function _getEcommerceCartUpdate()
101
104
//get category name
102
105
$ productId = $ cartItem ->product_id ;
103
106
$ product = Mage::getModel ('catalog/product ' )->load ($ productId );
104
- $ cats = $ product ->getCategoryIds ();
105
- if (isset ($ cats )) {
106
- $ categoryId = $ cats [0 ];
107
- } // just grab the first id
108
- $ category = Mage::getModel ('catalog/category ' )->load ($ categoryId );
109
- $ categoryName = $ category ->getName ();
107
+ $ categoryName = '' ;
108
+ $ categoryIds = $ product ->getCategoryIds ();
109
+ if (!empty ($ categoryIds )) {
110
+ $ categoryId = $ categoryIds [0 ];
111
+ $ category = Mage::getModel ('catalog/category ' )->load ($ categoryId );
112
+ $ categoryName = $ category ->getName ();
113
+ }
110
114
$ productName = $ cartItem ->getName ();
111
115
$ productName = str_replace ('" ' , "" , $ productName );
112
116
@@ -142,12 +146,13 @@ protected function _getProductPageview()
142
146
143
147
$ productId = $ currentProduct ->getId ();
144
148
$ product = Mage::getModel ('catalog/product ' )->load ($ productId );
145
- $ cats = $ product ->getCategoryIds ();
146
- //$category_id = $cats[0]; grabs first category
147
- // $category_id = below fix when no catgeories
148
- if (isset ($ cats [0 ])) {$ categoryId = $ cats [0 ];} else {$ categoryId = null ;}
149
- $ category = Mage::getModel ('catalog/category ' )->load ($ categoryId );
150
- $ categoryName = $ category ->getName ();
149
+ $ categoryName = '' ;
150
+ $ categoryIds = $ product ->getCategoryIds ();
151
+ if (!empty ($ categoryIds )) {
152
+ $ categoryId = $ categoryIds [0 ];
153
+ $ category = Mage::getModel ('catalog/category ' )->load ($ categoryId );
154
+ $ categoryName = $ category ->getName ();
155
+ }
151
156
$ productName = $ currentProduct ->getName ();
152
157
153
158
echo "_paq.push(['setEcommerceView', " . json_encode ($ currentProduct ->getSku ()) . ", " . json_encode ($ productName ) . ", " . json_encode ($ categoryName ) . ", " . $ currentProduct ->getPrice () . " ]); " ;
0 commit comments