Mygento_Metrika_Block_Tracker_Success   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
c 3
b 0
f 0
lcom 0
cbo 0
dl 0
loc 33
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B _toHtml() 0 29 3
1
<?php
2
3
/**
4
 *
5
 * @category   Mygento
6
 * @package    Mygento_Metrika
7
 * @copyright  Copyright © 2015 NKS LLC. (http://www.mygento.ru)
8
 */
9
class Mygento_Metrika_Block_Tracker_Success extends Mage_Core_Block_Template
10
{
11
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