ProductCategoryController::getItem()   B
last analyzed

Complexity

Conditions 7
Paths 14

Size

Total Lines 48
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
cc 7
eloc 25
c 3
b 1
f 0
nc 14
nop 2
dl 0
loc 48
rs 8.5866
1
<?php
2
3
namespace App\Http\Controllers\Frontend;
4
5
use App\Http\Controllers\Controller;
6
use Hideyo\Ecommerce\Framework\Services\Product\ProductFacade as ProductService;
7
use Hideyo\Ecommerce\Framework\Services\Product\ProductCombinationFacade as ProductCombinationService;
8
use Hideyo\Ecommerce\Framework\Services\ProductCategory\ProductCategoryFacade as ProductCategoryService;
9
use Illuminate\Http\Request;
10
11
class ProductCategoryController extends Controller
12
{    
13
    public function getItem(Request $request, $slug)
0 ignored issues
show
Unused Code introduced by
The parameter $request 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

13
    public function getItem(/** @scrutinizer ignore-unused */ Request $request, $slug)

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...
14
    {
15
        $category = ProductCategoryService::selectOneByShopIdAndSlug(config()->get('app.shop_id'), $slug);
16
17
        if ($category) {
18
19
            if ($category->refProductCategory) {
20
                return redirect()->to($category->refProductCategory->slug);
21
            }
22
23
            if ($category->ancestors()->count()) {
24
                //$request->session()->put('category_id', $category->ancestors()->first()->id);
25
            }
26
27
            $products = "";
28
            if ($category->products()->count()) {
29
                $products = ProductService::selectAllByShopIdAndProductCategoryId(config()->get('app.shop_id'), $category['id']);
30
            }
31
32
            if ($category->isLeaf()) {
33
                if ($category->isChild()) {
34
                    $childrenProductCategories = ProductCategoryService::selectCategoriesByParentId(config()->get('app.shop_id'), $category->parent_id);
35
                } else {
36
                    $childrenProductCategories = ProductCategoryService::selectAllByShopIdAndRoot(config()->get('app.shop_id'));
37
                }
38
39
                $attributes = ProductCombinationService::selectAllByProductCategoryId($category->id, config()->get('app.shop_id'));
0 ignored issues
show
Unused Code introduced by
The assignment to $attributes is dead and can be removed.
Loading history...
40
41
                return view('frontend.product_category.products')->with(
42
                    array(
43
                        'childrenProductCategories' => $childrenProductCategories,
44
                        'category' => $category,
45
                        'products' => $products,
46
                    )
47
                );
48
            }
49
50
            $childrenProductCategories = ProductCategoryService::selectCategoriesByParentId(config()->get('app.shop_id'), $category->id);
51
            
52
            return view('frontend.product_category.categories')->with(
53
                array(
54
                    'category' => $category,
55
                    'childrenProductCategories' => $childrenProductCategories
56
                )
57
            );
58
        }
59
    
60
        abort(404);    
61
    }
62
}