Mygento_Metrika_Block_Tracker_Product   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 0
cbo 0
dl 0
loc 36
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B _toHtml() 0 32 4
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_Product extends Mage_Core_Block_Template
10
{
11
12
    protected function _toHtml()
13
    {
14
        $currentProduct = Mage::registry('current_product');
15
        if (!$currentProduct || !Mage::getStoreConfig('metrika/metrika/ecommerce')) {
16
            return '';
17
        }
18
19
        $prod_data = array(
20
            'id' => $currentProduct->getSku(),
21
            'name' => $currentProduct->getName(),
22
            'price' => round($currentProduct->getFinalPrice(), 2),
23
        );
24
        if (Mage::registry('current_category')) {
25
            // TODO CATEGORY BREADCRUMBS
26
            // "category": "Одежда/Мужская одежда/Футболки",
27
            $prod_data['category'] = Mage::registry('current_category')->getName();
28
        }
29
        // TODO brand and variant
30
        //'brand' => '',
31
        //'variant' => '',
32
        $data = array(
33
            'ecommerce' => array(
34
                'detail' => array(
35
                    'products' => array(
36
                        $prod_data
37
                    )
38
                )
39
            )
40
        );
41
42
        return '<script>dataLayer.push(' . Mage::helper('core')->jsonEncode($data) . ');</script>' . "\n";
43
    }
44
}
45