| Conditions | 3 |
| Paths | 3 |
| Total Lines | 29 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | protected function _toHtml() |
||
| 13 | { |
||
| 14 | if (!Mage::getStoreConfig('metrika/metrika/ecommerce')) { |
||
| 15 | return ''; |
||
| 16 | } |
||
| 17 | $lastid = Mage::getSingleton('checkout/type_onepage')->getCheckout()->getLastOrderId(); |
||
| 18 | $order = Mage::getSingleton('sales/order')->load($lastid); |
||
| 19 | $prod_data = array(); |
||
| 20 | foreach ($order->getAllVisibleItems() as $item) { |
||
| 21 | $prod_data[] = array( |
||
| 22 | 'id' => $item->getSku(), |
||
| 23 | 'name' => $item->getName(), |
||
| 24 | 'price' => $item->getPrice(), |
||
| 25 | 'quantity' => (int) $item->getQtyOrdered() |
||
| 26 | ); |
||
| 27 | } |
||
| 28 | $data = array( |
||
| 29 | 'ecommerce' => array( |
||
| 30 | 'purchase' => array( |
||
| 31 | 'actionField' => array( |
||
| 32 | 'id' => (string) $order->getIncrementId(), |
||
| 33 | 'shipping' => $order->getShippingAmount(), |
||
| 34 | ), |
||
| 35 | 'products' => $prod_data, |
||
| 36 | ) |
||
| 37 | ) |
||
| 38 | ); |
||
| 39 | return '<script>dataLayer.push(' . Mage::helper('core')->jsonEncode($data) . ');</script>' . "\n"; |
||
| 40 | } |
||
| 41 | } |
||
| 42 |