CartTeaser   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 40
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 8 1
A getModule() 0 4 1
A registerCartClearJs() 0 23 1
1
<?php
2
3
/*
4
 * Cart module for Yii2
5
 *
6
 * @link      https://github.com/hiqdev/yii2-cart
7
 * @package   yii2-cart
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hiqdev\yii2\cart\widgets;
13
14
use hiqdev\yii2\cart\Module;
15
use Yii;
16
17
class CartTeaser extends \yii\base\Widget
18
{
19
    public function run()
20
    {
21
        return $this->render('CartTeaser', [
22
            'widget' => $this,
23
            'view'   => $this->getView(),
24
            'cart'   => $this->getModule()->getCart(),
25
        ]);
26
    }
27
28
    public function getModule()
29
    {
30
        return Module::getInstance();
31
    }
32
33
    public function registerCartClearJs(): void
34
    {
35
        $errorMessage = Yii::t('cart', 'Sorry, but now it is impossible to remove this position from cart now.');
36
37
        $this->getView()->registerJs(<<<JS
38
$('.cart-remove, .cart-clear, .cart-remove > .fa').on('click', function(event) {
39
    var url = event.target.dataset.action || $(this).parent().data('action');
40
    $.ajax({
41
        url: url,
42
        type: 'POST',
43
        cache: false,
44
        error: function() {
45
            hipanel.notify.error('$errorMessage');
46
        }
47
    });
48
    hipanel.updateCart(function() {
49
        $('.dropdown.notifications-cart a.dropdown-toggle').attr('aria-expanded', true);
50
        $("li.dropdown.notifications-menu.notifications-cart").addClass('open');
51
    });
52
});
53
JS
54
        );
55
    }
56
}
57