CartController   A
last analyzed

Complexity

Total Complexity 22

Size/Duplication

Total Lines 128
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 60
c 2
b 1
f 0
dl 0
loc 128
rs 10
wmc 22

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getBasketDialog() 0 3 1
A postProduct() 0 20 2
A deleteProduct() 0 9 2
A getPaymentMethodsList() 0 7 2
A updateAmountProduct() 0 24 4
B getIndex() 0 26 7
A getTotalReload() 0 12 2
A updateSendingMethod() 0 4 1
A updatePaymentMethod() 0 4 1
1
<?php namespace App\Http\Controllers\Frontend;
2
3
use App\Http\Controllers\Controller;
4
use Illuminate\Http\Request;
5
use Hideyo\Ecommerce\Framework\Services\SendingMethod\SendingMethodFacade as SendingMethodService;
6
use Hideyo\Ecommerce\Framework\Services\PaymentMethod\PaymentMethodFacade as PaymentMethodService;
7
use Hideyo\Ecommerce\Framework\Services\Shop\ShopFacade as ShopService;
8
use Browser;
0 ignored issues
show
Bug introduced by
The type Browser 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...
9
use Cart;
10
11
class CartController extends Controller
12
{
13
    public function getIndex()
14
    {
15
        $sendingMethodsList = SendingMethodService::selectAllActiveByShopId(config()->get('app.shop_id'));
16
        $paymentMethodsList = $this->getPaymentMethodsList($sendingMethodsList);
17
  
18
        if (!Cart::getContent()->count()) {
19
            return redirect()->to('cart');
20
        }
21
            
22
        if($sendingMethodsList->count() AND !Cart::getConditionsByType('sending_method')->count()) {
23
            self::updateSendingMethod($sendingMethodsList->first()->id);
0 ignored issues
show
Bug Best Practice introduced by
The method App\Http\Controllers\Fro...::updateSendingMethod() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
            self::/** @scrutinizer ignore-call */ 
24
                  updateSendingMethod($sendingMethodsList->first()->id);
Loading history...
24
        }      
25
26
        if ($paymentMethodsList AND !Cart::getConditionsByType('payment_method')->count()) {
27
            Cart::updatePaymentMethod($paymentMethodsList->first()->id);
28
        }
29
30
        $template = "frontend.cart.index";
31
32
        if (Browser::isMobile()) {
33
            $template = "frontend.cart.index-mobile";
34
        }
35
36
        return view($template)->with(array( 
37
            'user' => auth('web')->user(), 
38
            'sendingMethodsList' => $sendingMethodsList
39
        ));
40
    }
41
42
    public function getPaymentMethodsList($sendingMethodsList) 
43
    {
44
        if ($sendingMethodsList->first()) {     
45
            return $paymentMethodsList = $sendingMethodsList->first()->relatedPaymentMethods;
0 ignored issues
show
Unused Code introduced by
The assignment to $paymentMethodsList is dead and can be removed.
Loading history...
46
        }
47
        
48
        return $paymentMethodsList = PaymentMethodService::selectAllActiveByShopId(config()->get('app.shop_id'));       
49
    }
50
51
    public function postProduct(Request $request, $productId, $productCombinationId = false)
0 ignored issues
show
Unused Code introduced by
The parameter $productId is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

51
    public function postProduct(Request $request, /** @scrutinizer ignore-unused */ $productId, $productCombinationId = false)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
52
    {
53
        $result = Cart::postProduct(
54
            $request->get('product_id'), 
55
            $productCombinationId, 
56
            $request->get('leading_attribute_id'), 
57
            $request->get('product_attribute_id'),
58
            $request->get('amount')
59
        );
60
61
        if($result){
62
            return response()->json(array(
63
                'result' => true, 
64
                'producttotal' => Cart::getContent()->count(),
65
                'total_inc_tax_number_format' => Cart::getTotalWithTax(),
66
                'total_ex_tax_number_format' => Cart::getTotalWithoutTax()
67
            ));
68
        }
69
        
70
        return response()->json(false);
71
    }
72
73
    public function deleteProduct($productId)
74
    {
75
        $result = Cart::remove($productId);
76
77
        if (Cart::getContent()->count()) {
78
            return response()->json(array('result' => $result, 'totals' => true, 'producttotal' => Cart::getContent()->count()));
79
        }
80
        
81
        return response()->json(false);        
82
    }
83
84
    public function updateAmountProduct(Request $request, $productId, $amount)
85
    {
86
        Cart::updateAmountProduct($productId, $amount, $request->get('leading_attribute_id'), $request->get('product_attribute_id'));
87
88
        if (Cart::getContent()->count() AND Cart::get($productId)) {
89
            $product = Cart::get($productId);
90
            $amountNa = false;
91
92
            if($product->quantity < $amount) {
93
                $amountNa = view('frontend.cart.amount-na')->with(array('product' => $product))->render();
94
            }
95
            
96
            return response()->json(
97
                array(
98
                    'amountNa' => $amountNa,
99
                    'product_id' => $productId,
100
                    'product' => $product, 
101
                    'total_price_inc_tax_number_format' => $product->getOriginalPriceWithTaxSum(),
102
                    'total_price_ex_tax_number_format' => $product->getOriginalPriceWithoutTaxSum()
103
                )
104
            );
105
        }
106
        
107
        return response()->json(false);
108
    }
109
110
    public function getBasketDialog()
111
    {        
112
        return view('frontend.cart.basket-dialog');
113
    }
114
115
    public function getTotalReload()
116
    {
117
        $sendingMethodsList = SendingMethodService::selectAllActiveByShopId(config()->get('app.shop_id'));
118
        $paymentMethodsList = $this->getPaymentMethodsList($sendingMethodsList);
0 ignored issues
show
Unused Code introduced by
The assignment to $paymentMethodsList is dead and can be removed.
Loading history...
119
        
120
        $template = "frontend.cart._totals";
0 ignored issues
show
Unused Code introduced by
The assignment to $template is dead and can be removed.
Loading history...
121
        
122
        if (Browser::isMobile()) {
123
            $template = "frontend.cart._totals-mobile";
124
        }
125
126
        return view('frontend.cart._totals')->with(array('sendingMethodsList' => $sendingMethodsList));  
127
    }
128
129
    public function updateSendingMethod($sendingMethodId)
130
    {
131
        Cart::updateSendingMethod($sendingMethodId);
132
        return response()->json(array('sending_method' => Cart::getConditionsByType('sending_method')));
133
    }
134
135
    public function updatePaymentMethod($paymentMethodId)
136
    {
137
        Cart::updatePaymentMethod($paymentMethodId);
138
        return response()->json(array('payment_method' => Cart::getConditionsByType('payment_method')));
139
    }
140
}