Completed
Pull Request — master (#17)
by
unknown
11:07
created

CartTeaser   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 38
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 clearCart() 0 21 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
16
class CartTeaser extends \yii\base\Widget
17
{
18
    public function run()
19
    {
20
        return $this->render('CartTeaser', [
21
            'widget' => $this,
22
            'view'   => $this->getView(),
23
            'cart'   => $this->getModule()->getCart(),
24
        ]);
25
    }
26
27
    public function getModule()
28
    {
29
        return Module::getInstance();
30
    }
31
32
    public function clearCart()
33
    {
34
        $this->getView()->registerJs(<<<JS
35
$('.cart-remove, .cart-clear, .cart-remove > .fa').on('click', function(event) {
36
    var url = event.target.dataset.action;
37
    (url === undefined) ? (url = $(this).parent().attr('data-action')) : 0;
38
    $.ajax({
39
        url: url,
40
        type: 'POST',
41
        cache: false,
42
        success: function () {
43
            document.location.reload(true);
44
        },
45
        error: function(xhr, textStatus, thrownError) {
46
            console.log(textStatus);
47
        }
48
    });
49
});
50
JS
51
        );
52
    }
53
}
54