Install_Helper_Product::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 7
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
class Install_Helper_Product {
3
4
    private $kernel;
5
    private $db;
6
7
    public function __construct($kernel, $db) {
8
        $this->kernel = $kernel;
9
        $this->db = $db;
10
11
        Intraface_Doctrine_Intranet::singleton(1);
12
    }
13
14 View Code Duplication
    public function create()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
    {
16
        require_once 'Intraface/modules/product/Product.php';
17
        $product = new Product($this->kernel);
18
19
        return $product->save(array('name' => 'Product 1', 'price' => 100, 'unit' => 1));
20
    }
21
22 View Code Duplication
    public function createVisibleInShop()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
23
    {
24
        require_once 'Intraface/modules/product/Product.php';
25
        $product = new Product($this->kernel);
26
        $product->save(array('name' => 'Product 1', 'price' => '100,10', 'unit' => 1, 'do_show' => 1));
27
28
        return $product;
29
    }
30
31
    public function createVisibleInShopForPaging()
32
    {
33
        for ($i = 0; $i <= 20; $i++) {
34
            $this->createVisibleInShop();
35
        }
36
    }
37
38
    public function createVisibleInShopWithCategories()
39
    {
40
        $product = $this->createVisibleInShop();
41
42
        require 'Shop.php';
43
        $shop = new Install_Helper_Shop($this->kernel, $this->db);
44
45
        $category = $shop->createCategory('Category 1', 'category1', 0);
46
        $appender = $category->getAppender($product->get('id'));
47
48
        $category = $shop->createCategory('Category 2', 'category2', 1);
49
        $appender->add($category);
50
51
        $category = $shop->createCategory('Category 3', 'category3', 0);
52
        $appender->add($category);
53
54
        return $product;
55
    }
56
57
    public function createAttributes()
58
    {
59
        $group = new Intraface_modules_product_Attribute_Group;
60
61
        $group->name = 'Size';
62
        $group->attribute[0]->name = 'Small';
63
        $group->attribute[0]->position = 1;
64
        $group->attribute[1]->name = 'Medium';
65
        $group->attribute[1]->position = 2;
66
        $group->attribute[2]->name = 'Large';
67
        $group->attribute[2]->position = 3;
68
        $group->save();
69
70
        $group = new Intraface_modules_product_Attribute_Group;
71
72
        $group->name = 'Color';
73
        $group->attribute[0]->name = 'Blue';
74
        $group->attribute[0]->position = 1;
75
        $group->attribute[1]->name = 'Black';
76
        $group->attribute[1]->position = 2;
77
        $group->attribute[2]->name = 'Red';
78
        $group->attribute[2]->position = 3;
79
        $group->save();
80
    }
81
82
    public function createWithVariations()
83
    {
84
        $this->createAttributes();
85
        require_once 'Intraface/modules/product/Product.php';
86
        $product = new Product($this->kernel);
87
88
        $product->save(array('name' => 'Product 1', 'price' => 100, 'unit' => 2, 'has_variation' => 1, 'do_show' => 1, 'weight' => 110));
89
        $product->setAttributeGroup(1);
90
        $product->setAttributeGroup(2);
91
        foreach (array(1, 2, 3) AS $a1) {
0 ignored issues
show
Coding Style introduced by
AS keyword must be lowercase; expected "as" but found "AS"
Loading history...
Coding Style introduced by
As per coding-style, PHP keywords should be in lowercase; expected as, but found AS.
Loading history...
92
            foreach (array(4, 5, 6) AS $a2) {
0 ignored issues
show
Coding Style introduced by
AS keyword must be lowercase; expected "as" but found "AS"
Loading history...
Coding Style introduced by
As per coding-style, PHP keywords should be in lowercase; expected as, but found AS.
Loading history...
93
                $variation = $product->getVariation();
94
                $variation->setAttributesFromArray(array('attribute1' => $a1, 'attribute2' => $a2));
95
                $variation->save();
96
                $variation->load();
97
                $detail = $variation->getDetail();
98
                $detail->price_difference = 0; /* Can be reimplemented: ($a1 * $a2); */
99
                $detail->weight_difference = -1*($a1 * $a2);
100
                $detail->save();
101
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
102
            }
103
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
104
        }
105
    }
106
}
107