Completed
Push — 1.0 ( 7a7d48...309b8e )
by Nikita
06:17
created

addToCartComplete()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 1 Features 1
Metric Value
c 4
b 1
f 1
dl 0
loc 25
rs 8.8571
cc 3
eloc 16
nc 2
nop 1
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_Model_Observer
10
{
11
12
    public function addToCartComplete($observer)
13
    {
14
        $product = $observer->getProduct();
15
        $params = $observer->getRequest()->getParams();
16
        if (!isset($params['qty']) || $params['qty'] == 0) {
17
            $qty = 0;
18
        } else {
19
            $qty = $params['qty'];
20
        }
21
        $data = array(
22
            'ecommerce' => array(
23
                'add' => array(
24
                    'products' => array(
25
                        'id' => $product->getSku(),
26
                        'name' => $product->getName(),
27
                        'price' => $product->getPrice(),
28
                        //'brand' => 'Яндекс / Яndex',
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
29
                        //'category' => 'Аксессуары/Сумки',
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
30
                        'quantity' => $qty,
31
                    )
32
                )
33
            )
34
        );
35
        Mage::helper('metrika')->setSessionData($data);
36
    }
37
38
    public function removeFromCartComplete($observer)
39
    {
40
        $product = $observer->getQuoteItem()->getProduct();
41
        $data = array(
42
            'ecommerce' => array(
43
                'remove' => array(
44
                    'products' => array(
45
                        'id' => $product->getSku(),
46
                        'name' => $product->getName(),
47
                    )
48
                )
49
            )
50
        );
51
        Mage::helper('metrika')->setSessionData($data);
52
    }
53
54
    public function removeDomainPolicyHeader($observer)
55
    {
56
        /** @var Mage_Core_Controller->getCurrentAreaDomainPolicy_Varien_Action $action */
57
        $action = $observer->getControllerAction();
58
59
        if ('frontend' == $action->getLayout()->getArea()) {
60
            /** @var Mage_Core_Controller_Response_Http $response */
61
            $response = $action->getResponse();
62
            // @codingStandardsIgnoreStart
63
            $url = parse_url(Mage::helper('core/http')->getHttpReferer());
64
            // codingStandardsIgnoreEnd
65
            if ($url && isset($url['host']) && $url['host'] == 'webvisor.com') {
66
                $response->clearHeader('X-Frame-Options');
67
            }
68
        }
69
70
        return $this;
71
    }
72
}
73