ProductExtraFieldValueController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 16
c 2
b 0
f 1
dl 0
loc 29
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A store() 0 4 1
A index() 0 19 3
1
<?php namespace App\Http\Controllers\Backend;
2
3
4
/**
5
 * ProductExtraFieldValueController
6
 *
7
 * This is the controller of the product extra field values of the shop
8
 * @author Matthijs Neijenhuijs <[email protected]>
9
 * @version 0.1
10
 */
11
12
use App\Http\Controllers\Controller;
13
use Hideyo\Ecommerce\Framework\Services\Product\ProductExtraFieldValueFacade as ProductExtraFieldValueService;
14
use Hideyo\Ecommerce\Framework\Services\Product\ProductFacade as ProductService;
15
use Hideyo\Ecommerce\Framework\Services\ExtraField\ExtraFieldFacade as ExtraFieldService;
16
use Illuminate\Http\Request;
17
18
class ProductExtraFieldValueController extends Controller
19
{
20
    public function index($productId)
21
    {
22
        $product = ProductService::find($productId);
23
        $extraFieldsData = ProductExtraFieldValueService::selectAllByProductId($productId);
24
        $newExtraFieldsData = array();
25
        if ($extraFieldsData->count()) {
26
            foreach ($extraFieldsData as $row) {
27
                $newExtraFieldsData[$row->extra_field_id] = array(
28
                    'value' => $row->value,
29
                    'extra_field_default_value_id' => $row->extra_field_default_value_id
30
                );
31
            }
32
        }
33
   
34
        return view('backend.product-extra-field-value.index')->with(
35
            array(
36
                'extraFields' =>  ExtraFieldService::selectAllByAllProductsAndProductCategoryId($product->product_category_id),
37
                'product' => ProductService::find($productId),
38
                'populateData' => $newExtraFieldsData
39
            )
40
        );
41
    }
42
43
    public function store($productId, Request $request)
44
    {
45
        $result  = ProductExtraFieldValueService::create($request->all(), $productId);
46
         return ProductExtraFieldValueService::notificationRedirect(array('product.product-extra-field-value.index', $productId), $result, 'The product extra fields are updated.');
47
    }
48
}
49