Shopware_Controllers_Widgets_DnVariantSwitch   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 45
rs 10
c 2
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A variantSwitchFormAction() 0 23 3
A switchVariantAction() 0 18 3
1
<?php
2
3
class Shopware_Controllers_Widgets_DnVariantSwitch extends \Enlight_Controller_Action
0 ignored issues
show
Bug introduced by
The type Enlight_Controller_Action was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
4
{
5
    public function variantSwitchFormAction()
6
    {
7
        $basketID = $this->Request()->get('basketId');
8
        $articleID = $this->Request()->get('articleId');
9
        $number = $this->Request()->get('number');
10
        $quantity = $this->Request()->get('quantity');
11
        $offCanvas = $this->Request()->get('offCanvas');
12
13
        $context = $this->get('shopware_storefront.context_service')->getShopContext();
14
        $product = $this->get('shopware_storefront.list_product_service')->get($number, $context);
15
16
        /** @var \Shopware\Bundle\StoreFrontBundle\Struct\ListProduct $product */
17
        if (!$product || !$product->hasConfigurator()) {
0 ignored issues
show
introduced by
$product is of type Shopware\Bundle\StoreFro...ndle\Struct\ListProduct, thus it always evaluated to true.
Loading history...
18
            return;
19
        }
20
21
        $this->view->hasActiveVariants = true;
22
23
        $this->view->basketID = $basketID;
24
        $this->view->articleID = $articleID;
25
        $this->view->number = $number;
26
        $this->view->quantity = $quantity;
27
        $this->view->offCanvas = $offCanvas;
28
    }
29
30
    public function switchVariantAction()
31
    {
32
        $this->get('front')->Plugins()->ViewRenderer()->setNoRender();
33
34
        $number = $this->Request()->get('sAdd');
35
        $quantity = (int)$this->Request()->get('sQuantity');
36
        $basketID = (int)$this->Request()->get('detailId');
37
38
        if(!empty($number) && !empty($basketID)){
39
            $this->get('dn.variant_switch')->switchVariant(
40
                $number,
41
                $basketID,
42
                $this->get('modules')->Basket(),
43
                $quantity
44
            );
45
        }
46
47
        $this->Response()->setBody(json_encode(array('success' => true)));
48
    }
49
}