@@ -2,30 +2,30 @@ |
||
2 | 2 | |
3 | 3 | class StoreSettingsTest extends FS_Test{ |
4 | 4 | |
5 | - protected static $use_draft_site = true; |
|
5 | + protected static $use_draft_site = true; |
|
6 | 6 | |
7 | - function setUp(){ |
|
8 | - parent::setUp(); |
|
7 | + function setUp(){ |
|
8 | + parent::setUp(); |
|
9 | 9 | |
10 | - $siteConf = SiteConfig::current_site_config(); |
|
11 | - $siteConf->StoreName = 'foxystripe'; |
|
10 | + $siteConf = SiteConfig::current_site_config(); |
|
11 | + $siteConf->StoreName = 'foxystripe'; |
|
12 | 12 | $siteConf->requireDefaultRecords(); |
13 | - $siteConf->write(); |
|
14 | - } |
|
13 | + $siteConf->write(); |
|
14 | + } |
|
15 | 15 | |
16 | - function testStoreKey(){ |
|
17 | - $pref = FoxyCart::getKeyPrefix(); |
|
18 | - $siteConf = SiteConfig::current_site_config(); |
|
16 | + function testStoreKey(){ |
|
17 | + $pref = FoxyCart::getKeyPrefix(); |
|
18 | + $siteConf = SiteConfig::current_site_config(); |
|
19 | 19 | |
20 | - $this->assertTrue(ctype_alnum($siteConf->StoreKey)); |
|
20 | + $this->assertTrue(ctype_alnum($siteConf->StoreKey)); |
|
21 | 21 | $this->assertEquals(strlen($siteConf->StoreKey), 60); |
22 | 22 | $this->assertEquals(substr($siteConf->StoreKey, 0, 6), $pref); |
23 | - } |
|
23 | + } |
|
24 | 24 | |
25 | - function testStoreName(){ |
|
26 | - $siteConf = SiteConfig::current_site_config(); |
|
25 | + function testStoreName(){ |
|
26 | + $siteConf = SiteConfig::current_site_config(); |
|
27 | 27 | |
28 | 28 | $this->assertEquals($siteConf->StoreName, 'foxystripe'); |
29 | - } |
|
29 | + } |
|
30 | 30 | |
31 | 31 | } |
@@ -2,79 +2,79 @@ |
||
2 | 2 | |
3 | 3 | class ProductDiscountTierTest extends FS_Test{ |
4 | 4 | |
5 | - protected static $use_draft_site = true; |
|
5 | + protected static $use_draft_site = true; |
|
6 | 6 | |
7 | - function setUp(){ |
|
8 | - parent::setUp(); |
|
7 | + function setUp(){ |
|
8 | + parent::setUp(); |
|
9 | 9 | |
10 | - $productHolder = ProductHolder::create(); |
|
11 | - $productHolder->Title = 'Product Holder'; |
|
12 | - $productHolder->write(); |
|
10 | + $productHolder = ProductHolder::create(); |
|
11 | + $productHolder->Title = 'Product Holder'; |
|
12 | + $productHolder->write(); |
|
13 | 13 | |
14 | - $product = $this->objFromFixture('ProductPage', 'product1'); |
|
15 | - $product->ParentID = $productHolder->ID; |
|
16 | - $product->write(); |
|
17 | - } |
|
14 | + $product = $this->objFromFixture('ProductPage', 'product1'); |
|
15 | + $product->ParentID = $productHolder->ID; |
|
16 | + $product->write(); |
|
17 | + } |
|
18 | 18 | |
19 | - public function testProductDiscountTierCreation(){ |
|
20 | - $this->logInWithPermission('Product_CANCRUD'); |
|
19 | + public function testProductDiscountTierCreation(){ |
|
20 | + $this->logInWithPermission('Product_CANCRUD'); |
|
21 | 21 | |
22 | - $discount = ProductPage::get()->first(); |
|
22 | + $discount = ProductPage::get()->first(); |
|
23 | 23 | |
24 | - $tier = $this->objFromFixture('ProductDiscountTier', 'fiveforten'); |
|
25 | - $tier->ProductPageID = $discount->ID; |
|
26 | - $tier->write(); |
|
27 | - $tierID = $tier->ID; |
|
24 | + $tier = $this->objFromFixture('ProductDiscountTier', 'fiveforten'); |
|
25 | + $tier->ProductPageID = $discount->ID; |
|
26 | + $tier->write(); |
|
27 | + $tierID = $tier->ID; |
|
28 | 28 | |
29 | - $checkTier = ProductDiscountTier::get()->byID($tierID); |
|
29 | + $checkTier = ProductDiscountTier::get()->byID($tierID); |
|
30 | 30 | |
31 | - $this->assertEquals($checkTier->Quantity, 5); |
|
32 | - $this->assertEquals($checkTier->Percentage, 10); |
|
31 | + $this->assertEquals($checkTier->Quantity, 5); |
|
32 | + $this->assertEquals($checkTier->Percentage, 10); |
|
33 | 33 | |
34 | - $this->logOut(); |
|
35 | - } |
|
34 | + $this->logOut(); |
|
35 | + } |
|
36 | 36 | |
37 | - public function testProductDiscountTierEdit(){ |
|
38 | - $this->logInWithPermission('ADMIN'); |
|
37 | + public function testProductDiscountTierEdit(){ |
|
38 | + $this->logInWithPermission('ADMIN'); |
|
39 | 39 | |
40 | - $discount = ProductPage::get()->first(); |
|
40 | + $discount = ProductPage::get()->first(); |
|
41 | 41 | |
42 | - $tier = $this->objFromFixture('ProductDiscountTier', 'fiveforten'); |
|
43 | - $tier->ProductPageID = $discount->ID; |
|
44 | - $tier->write(); |
|
45 | - $tierID = $tier->ID; |
|
46 | - $this->logInWithPermission('Product_CANCRUD'); |
|
42 | + $tier = $this->objFromFixture('ProductDiscountTier', 'fiveforten'); |
|
43 | + $tier->ProductPageID = $discount->ID; |
|
44 | + $tier->write(); |
|
45 | + $tierID = $tier->ID; |
|
46 | + $this->logInWithPermission('Product_CANCRUD'); |
|
47 | 47 | |
48 | - $tier->Quantity = 2; |
|
49 | - $tier->Percentage = 5; |
|
50 | - $tier->write(); |
|
48 | + $tier->Quantity = 2; |
|
49 | + $tier->Percentage = 5; |
|
50 | + $tier->write(); |
|
51 | 51 | |
52 | - $checkTier = ProductDiscountTier::get()->byID($tierID); |
|
52 | + $checkTier = ProductDiscountTier::get()->byID($tierID); |
|
53 | 53 | |
54 | - $this->assertEquals($checkTier->Quantity, 2); |
|
55 | - $this->assertEquals($checkTier->Percentage, 5); |
|
54 | + $this->assertEquals($checkTier->Quantity, 2); |
|
55 | + $this->assertEquals($checkTier->Percentage, 5); |
|
56 | 56 | |
57 | - $this->logOut(); |
|
58 | - } |
|
57 | + $this->logOut(); |
|
58 | + } |
|
59 | 59 | |
60 | - public function testProductDiscountTierDeletion(){ |
|
61 | - $this->logInWithPermission('ADMIN'); |
|
60 | + public function testProductDiscountTierDeletion(){ |
|
61 | + $this->logInWithPermission('ADMIN'); |
|
62 | 62 | |
63 | - $discount = ProductPage::get()->first(); |
|
63 | + $discount = ProductPage::get()->first(); |
|
64 | 64 | |
65 | - $tier = $this->objFromFixture('ProductDiscountTier', 'fiveforten'); |
|
66 | - $tier->ProductPageID = $discount->ID; |
|
67 | - $tier->write(); |
|
68 | - $tierID = $tier->ID; |
|
65 | + $tier = $this->objFromFixture('ProductDiscountTier', 'fiveforten'); |
|
66 | + $tier->ProductPageID = $discount->ID; |
|
67 | + $tier->write(); |
|
68 | + $tierID = $tier->ID; |
|
69 | 69 | |
70 | - $this->logOut(); |
|
70 | + $this->logOut(); |
|
71 | 71 | |
72 | - $this->logInWithPermission('Product_CANCRUD'); |
|
72 | + $this->logInWithPermission('Product_CANCRUD'); |
|
73 | 73 | |
74 | - $tier->delete(); |
|
75 | - $this->assertTrue(!ProductDiscountTier::get()->byID($tierID)); |
|
74 | + $tier->delete(); |
|
75 | + $this->assertTrue(!ProductDiscountTier::get()->byID($tierID)); |
|
76 | 76 | |
77 | - $this->logOut(); |
|
78 | - } |
|
77 | + $this->logOut(); |
|
78 | + } |
|
79 | 79 | |
80 | 80 | } |
@@ -2,193 +2,193 @@ |
||
2 | 2 | |
3 | 3 | class ProductPageTest extends FunctionalTest { |
4 | 4 | |
5 | - protected static $use_draft_site = true; |
|
5 | + protected static $use_draft_site = true; |
|
6 | 6 | |
7 | - function setUp(){ |
|
7 | + function setUp(){ |
|
8 | 8 | |
9 | - $groupForItem = OptionGroup::create(); |
|
10 | - $groupForItem->Title = 'Sample-Group'; |
|
11 | - $groupForItem->write(); |
|
9 | + $groupForItem = OptionGroup::create(); |
|
10 | + $groupForItem->Title = 'Sample-Group'; |
|
11 | + $groupForItem->write(); |
|
12 | 12 | |
13 | - $productHolder = ProductHolder::create(); |
|
14 | - $productHolder->Title = 'Product Holder'; |
|
15 | - $productHolder->write(); |
|
16 | - } |
|
13 | + $productHolder = ProductHolder::create(); |
|
14 | + $productHolder->Title = 'Product Holder'; |
|
15 | + $productHolder->write(); |
|
16 | + } |
|
17 | 17 | |
18 | - function testProductCreation(){ |
|
18 | + function testProductCreation(){ |
|
19 | 19 | |
20 | - $this->logInWithPermission('Product_CANCRUD'); |
|
21 | - $default = $this->objFromFixture('ProductCategory', 'default'); |
|
22 | - $default->write(); |
|
23 | - $product1 = $this->objFromFixture('ProductPage', 'product1'); |
|
24 | - $product1->ParentID = ProductHolder::get()->first()->ID; |
|
20 | + $this->logInWithPermission('Product_CANCRUD'); |
|
21 | + $default = $this->objFromFixture('ProductCategory', 'default'); |
|
22 | + $default->write(); |
|
23 | + $product1 = $this->objFromFixture('ProductPage', 'product1'); |
|
24 | + $product1->ParentID = ProductHolder::get()->first()->ID; |
|
25 | 25 | |
26 | - $product1->doPublish(); |
|
27 | - $this->assertTrue($product1->isPublished()); |
|
26 | + $product1->doPublish(); |
|
27 | + $this->assertTrue($product1->isPublished()); |
|
28 | 28 | |
29 | - } |
|
29 | + } |
|
30 | 30 | |
31 | - function testProductDeletion(){ |
|
31 | + function testProductDeletion(){ |
|
32 | 32 | |
33 | - $this->logInWithPermission('Product_CANCRUD'); |
|
34 | - $product2 = $this->objFromFixture('ProductPage', 'product2'); |
|
35 | - $product2->ParentID = ProductHolder::get()->first()->ID; |
|
36 | - $productID = $product2->ID; |
|
33 | + $this->logInWithPermission('Product_CANCRUD'); |
|
34 | + $product2 = $this->objFromFixture('ProductPage', 'product2'); |
|
35 | + $product2->ParentID = ProductHolder::get()->first()->ID; |
|
36 | + $productID = $product2->ID; |
|
37 | 37 | |
38 | - $product2->doPublish(); |
|
39 | - $this->assertTrue($product2->isPublished()); |
|
38 | + $product2->doPublish(); |
|
39 | + $this->assertTrue($product2->isPublished()); |
|
40 | 40 | |
41 | - $versions = DB::query('Select * FROM "ProductPage_versions" WHERE "RecordID" = '. $productID); |
|
42 | - $versionsPostPublish = array(); |
|
43 | - foreach($versions as $versionRow) $versionsPostPublish[] = $versionRow; |
|
41 | + $versions = DB::query('Select * FROM "ProductPage_versions" WHERE "RecordID" = '. $productID); |
|
42 | + $versionsPostPublish = array(); |
|
43 | + foreach($versions as $versionRow) $versionsPostPublish[] = $versionRow; |
|
44 | 44 | |
45 | - $product2->delete(); |
|
46 | - $this->assertTrue(!$product2->isPublished()); |
|
45 | + $product2->delete(); |
|
46 | + $this->assertTrue(!$product2->isPublished()); |
|
47 | 47 | |
48 | - $versions = DB::query('Select * FROM "ProductPage_versions" WHERE "RecordID" = '. $productID); |
|
49 | - $versionsPostDelete = array(); |
|
50 | - foreach($versions as $versionRow) $versionsPostDelete[] = $versionRow; |
|
48 | + $versions = DB::query('Select * FROM "ProductPage_versions" WHERE "RecordID" = '. $productID); |
|
49 | + $versionsPostDelete = array(); |
|
50 | + foreach($versions as $versionRow) $versionsPostDelete[] = $versionRow; |
|
51 | 51 | |
52 | - $this->assertTrue($versionsPostPublish == $versionsPostDelete); |
|
52 | + $this->assertTrue($versionsPostPublish == $versionsPostDelete); |
|
53 | 53 | |
54 | - } |
|
54 | + } |
|
55 | 55 | |
56 | - function testProductTitleLeadingWhiteSpace(){ |
|
56 | + function testProductTitleLeadingWhiteSpace(){ |
|
57 | 57 | |
58 | - $this->logInWithPermission('ADMIN'); |
|
59 | - $product = $this->objFromFixture('ProductPage', 'product1'); |
|
60 | - $product->Title = " Test with leading space"; |
|
61 | - $product->ParentID = ProductHolder::get()->first()->ID; |
|
62 | - $product->doPublish(); |
|
58 | + $this->logInWithPermission('ADMIN'); |
|
59 | + $product = $this->objFromFixture('ProductPage', 'product1'); |
|
60 | + $product->Title = " Test with leading space"; |
|
61 | + $product->ParentID = ProductHolder::get()->first()->ID; |
|
62 | + $product->doPublish(); |
|
63 | 63 | |
64 | - $this->assertTrue($product->Title == 'Test with leading space'); |
|
64 | + $this->assertTrue($product->Title == 'Test with leading space'); |
|
65 | 65 | |
66 | - } |
|
66 | + } |
|
67 | 67 | |
68 | - function testProductTitleTrailingWhiteSpace(){ |
|
68 | + function testProductTitleTrailingWhiteSpace(){ |
|
69 | 69 | |
70 | - $this->logInWithPermission('ADMIN'); |
|
71 | - $product = $this->objFromFixture('ProductPage', 'product1'); |
|
72 | - $product->Title = "Test with trailing space "; |
|
73 | - $product->ParentID = ProductHolder::get()->first()->ID; |
|
74 | - $product->doPublish(); |
|
70 | + $this->logInWithPermission('ADMIN'); |
|
71 | + $product = $this->objFromFixture('ProductPage', 'product1'); |
|
72 | + $product->Title = "Test with trailing space "; |
|
73 | + $product->ParentID = ProductHolder::get()->first()->ID; |
|
74 | + $product->doPublish(); |
|
75 | 75 | |
76 | - $this->assertTrue($product->Title == 'Test with trailing space'); |
|
76 | + $this->assertTrue($product->Title == 'Test with trailing space'); |
|
77 | 77 | |
78 | - } |
|
78 | + } |
|
79 | 79 | |
80 | - function testProductCategoryCreation(){ |
|
80 | + function testProductCategoryCreation(){ |
|
81 | 81 | |
82 | - $this->logInWithPermission('Product_CANCRUD'); |
|
83 | - $category = $this->objFromFixture('ProductCategory', 'apparel'); |
|
84 | - $category->write(); |
|
85 | - $categoryID = $category->ID; |
|
82 | + $this->logInWithPermission('Product_CANCRUD'); |
|
83 | + $category = $this->objFromFixture('ProductCategory', 'apparel'); |
|
84 | + $category->write(); |
|
85 | + $categoryID = $category->ID; |
|
86 | 86 | |
87 | - $productCategory = ProductCategory::get()->filter(array('Code'=>'APPAREL'))->first(); |
|
87 | + $productCategory = ProductCategory::get()->filter(array('Code'=>'APPAREL'))->first(); |
|
88 | 88 | |
89 | - $this->assertTrue($categoryID == $productCategory->ID); |
|
89 | + $this->assertTrue($categoryID == $productCategory->ID); |
|
90 | 90 | |
91 | - } |
|
91 | + } |
|
92 | 92 | |
93 | - function testProductCategoryDeletion(){ |
|
93 | + function testProductCategoryDeletion(){ |
|
94 | 94 | |
95 | - $this->logInWithPermission('Product_CANCRUD'); |
|
96 | - $category = $this->objFromFixture('ProductCategory', 'default'); |
|
97 | - $category->write(); |
|
95 | + $this->logInWithPermission('Product_CANCRUD'); |
|
96 | + $category = $this->objFromFixture('ProductCategory', 'default'); |
|
97 | + $category->write(); |
|
98 | 98 | |
99 | - $this->assertFalse($category->canDelete()); |
|
99 | + $this->assertFalse($category->canDelete()); |
|
100 | 100 | |
101 | - $category2 = $this->objFromFixture('ProductCategory', 'apparel'); |
|
102 | - $category2->write(); |
|
103 | - $category2ID = $category2->ID; |
|
101 | + $category2 = $this->objFromFixture('ProductCategory', 'apparel'); |
|
102 | + $category2->write(); |
|
103 | + $category2ID = $category2->ID; |
|
104 | 104 | |
105 | - $this->assertTrue($category2->canDelete()); |
|
105 | + $this->assertTrue($category2->canDelete()); |
|
106 | 106 | |
107 | - $this->logOut(); |
|
107 | + $this->logOut(); |
|
108 | 108 | |
109 | - $this->logInWithPermission('ADMIN'); |
|
109 | + $this->logInWithPermission('ADMIN'); |
|
110 | 110 | |
111 | - $this->assertFalse($category->canDelete()); |
|
112 | - $this->assertTrue($category2->canDelete()); |
|
111 | + $this->assertFalse($category->canDelete()); |
|
112 | + $this->assertTrue($category2->canDelete()); |
|
113 | 113 | |
114 | - $this->logOut(); |
|
115 | - $this->logInWithPermission('Product_CANCRUD'); |
|
114 | + $this->logOut(); |
|
115 | + $this->logInWithPermission('Product_CANCRUD'); |
|
116 | 116 | |
117 | - $category2->delete(); |
|
117 | + $category2->delete(); |
|
118 | 118 | |
119 | - $this->assertFalse(in_array($category2ID,ProductCategory::get()->column('ID'))); |
|
119 | + $this->assertFalse(in_array($category2ID,ProductCategory::get()->column('ID'))); |
|
120 | 120 | |
121 | - } |
|
121 | + } |
|
122 | 122 | |
123 | - function testOptionGroupCreation(){ |
|
123 | + function testOptionGroupCreation(){ |
|
124 | 124 | |
125 | - $this->logInWithPermission('Product_CANCRUD'); |
|
126 | - $group = $this->objFromFixture('OptionGroup', 'size'); |
|
127 | - $group->write(); |
|
125 | + $this->logInWithPermission('Product_CANCRUD'); |
|
126 | + $group = $this->objFromFixture('OptionGroup', 'size'); |
|
127 | + $group->write(); |
|
128 | 128 | |
129 | - $this->assertNotNull(OptionGroup::get()->first()); |
|
129 | + $this->assertNotNull(OptionGroup::get()->first()); |
|
130 | 130 | |
131 | - } |
|
131 | + } |
|
132 | 132 | |
133 | - function testOptionGroupDeletion(){ |
|
133 | + function testOptionGroupDeletion(){ |
|
134 | 134 | |
135 | - $this->logInWithPermission('ADMIN'); |
|
136 | - $group = $this->objFromFixture('OptionGroup', 'color'); |
|
137 | - $group->write(); |
|
138 | - $groupID = $group->ID; |
|
135 | + $this->logInWithPermission('ADMIN'); |
|
136 | + $group = $this->objFromFixture('OptionGroup', 'color'); |
|
137 | + $group->write(); |
|
138 | + $groupID = $group->ID; |
|
139 | 139 | |
140 | - $this->assertTrue($group->canDelete()); |
|
140 | + $this->assertTrue($group->canDelete()); |
|
141 | 141 | |
142 | - $this->logOut(); |
|
143 | - $this->logInWithPermission('Product_CANCRUD'); |
|
142 | + $this->logOut(); |
|
143 | + $this->logInWithPermission('Product_CANCRUD'); |
|
144 | 144 | |
145 | - $this->assertTrue($group->canDelete()); |
|
146 | - $group->delete(); |
|
145 | + $this->assertTrue($group->canDelete()); |
|
146 | + $group->delete(); |
|
147 | 147 | |
148 | - $this->assertFalse(in_array($groupID, OptionGroup::get()->column('ID'))); |
|
148 | + $this->assertFalse(in_array($groupID, OptionGroup::get()->column('ID'))); |
|
149 | 149 | |
150 | - } |
|
150 | + } |
|
151 | 151 | |
152 | - function testOptionItemCreation(){ |
|
152 | + function testOptionItemCreation(){ |
|
153 | 153 | |
154 | - $this->logInWithPermission('Product_CANCRUD'); |
|
155 | - $optionGroup = OptionGroup::get()->filter(array('Title' => 'Sample-Group'))->first(); |
|
156 | - $option = $this->objFromFixture('OptionItem', 'large'); |
|
157 | - $option->ProductOptionGroupID = $optionGroup->ID; |
|
158 | - $option->write(); |
|
159 | - $optionID = $option->ID; |
|
154 | + $this->logInWithPermission('Product_CANCRUD'); |
|
155 | + $optionGroup = OptionGroup::get()->filter(array('Title' => 'Sample-Group'))->first(); |
|
156 | + $option = $this->objFromFixture('OptionItem', 'large'); |
|
157 | + $option->ProductOptionGroupID = $optionGroup->ID; |
|
158 | + $option->write(); |
|
159 | + $optionID = $option->ID; |
|
160 | 160 | |
161 | - $optionItem = OptionItem::get()->filter(array('ProductOptionGroupID' => $optionGroup->ID))->first(); |
|
161 | + $optionItem = OptionItem::get()->filter(array('ProductOptionGroupID' => $optionGroup->ID))->first(); |
|
162 | 162 | |
163 | - $this->assertEquals($optionID, $optionItem->ID); |
|
163 | + $this->assertEquals($optionID, $optionItem->ID); |
|
164 | 164 | |
165 | - } |
|
165 | + } |
|
166 | 166 | |
167 | - function testOptionItemDeletion(){ |
|
167 | + function testOptionItemDeletion(){ |
|
168 | 168 | |
169 | - $this->logInWithPermission('ADMIN'); |
|
170 | - $optionGroup = (OptionGroup::get()->first()) |
|
171 | - ? OptionGroup::get()->first() |
|
172 | - : OptionGroup::create(); |
|
173 | - if($optionGroup->ID == 0){ |
|
174 | - $optionGroup->Title = 'Size'; |
|
175 | - $optionGroup->write(); |
|
176 | - } |
|
177 | - $option = $this->objFromFixture('OptionItem', 'small'); |
|
178 | - $option->ProductOptionGroupID = $optionGroup->ID; |
|
179 | - $option->write(); |
|
180 | - $optionID = $option->ID; |
|
169 | + $this->logInWithPermission('ADMIN'); |
|
170 | + $optionGroup = (OptionGroup::get()->first()) |
|
171 | + ? OptionGroup::get()->first() |
|
172 | + : OptionGroup::create(); |
|
173 | + if($optionGroup->ID == 0){ |
|
174 | + $optionGroup->Title = 'Size'; |
|
175 | + $optionGroup->write(); |
|
176 | + } |
|
177 | + $option = $this->objFromFixture('OptionItem', 'small'); |
|
178 | + $option->ProductOptionGroupID = $optionGroup->ID; |
|
179 | + $option->write(); |
|
180 | + $optionID = $option->ID; |
|
181 | 181 | |
182 | - $this->assertTrue($option->canDelete()); |
|
182 | + $this->assertTrue($option->canDelete()); |
|
183 | 183 | |
184 | - $this->logOut(); |
|
185 | - $this->logInWithPermission('Product_CANCRUD'); |
|
184 | + $this->logOut(); |
|
185 | + $this->logInWithPermission('Product_CANCRUD'); |
|
186 | 186 | |
187 | - $this->assertTrue($option->canDelete()); |
|
188 | - $option->delete(); |
|
187 | + $this->assertTrue($option->canDelete()); |
|
188 | + $option->delete(); |
|
189 | 189 | |
190 | - $this->assertFalse(in_array($optionID, OptionItem::get()->column('ID'))); |
|
190 | + $this->assertFalse(in_array($optionID, OptionItem::get()->column('ID'))); |
|
191 | 191 | |
192 | - } |
|
192 | + } |
|
193 | 193 | |
194 | 194 | } |
@@ -50,41 +50,41 @@ |
||
50 | 50 | */ |
51 | 51 | class FoxyStripeDropdownField extends DropdownField{ |
52 | 52 | |
53 | - /** |
|
54 | - * Mark certain elements as disabled, |
|
55 | - * regardless of the {@link setDisabled()} settings. |
|
56 | - * |
|
57 | - * @param array $items Collection of array keys, as defined in the $source array |
|
53 | + /** |
|
54 | + * Mark certain elements as disabled, |
|
55 | + * regardless of the {@link setDisabled()} settings. |
|
56 | + * |
|
57 | + * @param array $items Collection of array keys, as defined in the $source array |
|
58 | 58 | * @return $this |
59 | - */ |
|
60 | - public function setDisabledItems($items){ |
|
61 | - $controller = Controller::curr(); |
|
62 | - $code = $controller->data()->Code; |
|
63 | - $updated = []; |
|
64 | - if(is_array($items) && !empty($items)){ |
|
65 | - foreach($items as $item){ |
|
66 | - array_push($updated, FoxyStripeProduct::getGeneratedValue($code, $this->getName(), $item, 'value')); |
|
67 | - } |
|
68 | - } |
|
69 | - $this->disabledItems = $updated; |
|
70 | - return $this; |
|
71 | - } |
|
59 | + */ |
|
60 | + public function setDisabledItems($items){ |
|
61 | + $controller = Controller::curr(); |
|
62 | + $code = $controller->data()->Code; |
|
63 | + $updated = []; |
|
64 | + if(is_array($items) && !empty($items)){ |
|
65 | + foreach($items as $item){ |
|
66 | + array_push($updated, FoxyStripeProduct::getGeneratedValue($code, $this->getName(), $item, 'value')); |
|
67 | + } |
|
68 | + } |
|
69 | + $this->disabledItems = $updated; |
|
70 | + return $this; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * @param array $source |
|
73 | + /** |
|
74 | + * @param array $source |
|
75 | 75 | * @return $this |
76 | - */ |
|
77 | - public function setSource($source) { |
|
78 | - $controller = Controller::curr(); |
|
79 | - $code = $controller->data()->Code; |
|
80 | - $updated = []; |
|
81 | - if(is_array($source) && !empty($source)){ |
|
82 | - foreach($source as $key => $val){ |
|
83 | - $updated[FoxyStripeProduct::getGeneratedValue($code, $this->getName(), $key, 'value')] = $val; |
|
84 | - } |
|
85 | - } |
|
86 | - $this->source = $updated; |
|
87 | - return $this; |
|
88 | - } |
|
76 | + */ |
|
77 | + public function setSource($source) { |
|
78 | + $controller = Controller::curr(); |
|
79 | + $code = $controller->data()->Code; |
|
80 | + $updated = []; |
|
81 | + if(is_array($source) && !empty($source)){ |
|
82 | + foreach($source as $key => $val){ |
|
83 | + $updated[FoxyStripeProduct::getGeneratedValue($code, $this->getName(), $key, 'value')] = $val; |
|
84 | + } |
|
85 | + } |
|
86 | + $this->source = $updated; |
|
87 | + return $this; |
|
88 | + } |
|
89 | 89 | |
90 | 90 | } |
@@ -7,25 +7,25 @@ discard block |
||
7 | 7 | |
8 | 8 | class ProductImage extends DataObject{ |
9 | 9 | |
10 | - private static $db = array( |
|
11 | - 'Title' => 'Text', |
|
12 | - 'SortOrder' => 'Int' |
|
13 | - ); |
|
10 | + private static $db = array( |
|
11 | + 'Title' => 'Text', |
|
12 | + 'SortOrder' => 'Int' |
|
13 | + ); |
|
14 | 14 | |
15 | - private static $has_one = array( |
|
16 | - 'Image' => 'Image', |
|
17 | - 'Product' => 'FoxyStripeProduct' |
|
18 | - ); |
|
15 | + private static $has_one = array( |
|
16 | + 'Image' => 'Image', |
|
17 | + 'Product' => 'FoxyStripeProduct' |
|
18 | + ); |
|
19 | 19 | |
20 | - private static $default_sort = 'SortOrder'; |
|
20 | + private static $default_sort = 'SortOrder'; |
|
21 | 21 | |
22 | - private static $summary_fields = array( |
|
23 | - 'Image.CMSThumbnail' => 'Image', |
|
24 | - 'Title' => 'Caption' |
|
25 | - ); |
|
22 | + private static $summary_fields = array( |
|
23 | + 'Image.CMSThumbnail' => 'Image', |
|
24 | + 'Title' => 'Caption' |
|
25 | + ); |
|
26 | 26 | |
27 | - public function getCMSFields(){ |
|
28 | - $fields = FieldList::create( |
|
27 | + public function getCMSFields(){ |
|
28 | + $fields = FieldList::create( |
|
29 | 29 | TextField::create('Title') |
30 | 30 | ->setTitle(_t('ProductImage.Title', 'Product Image Title')), |
31 | 31 | UploadField::create('Image') |
@@ -34,25 +34,25 @@ discard block |
||
34 | 34 | ->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png')) |
35 | 35 | ); |
36 | 36 | |
37 | - $this->extend('updateCMSFields', $fields); |
|
37 | + $this->extend('updateCMSFields', $fields); |
|
38 | 38 | |
39 | 39 | return $fields; |
40 | - } |
|
40 | + } |
|
41 | 41 | |
42 | - public function canView($member = false) { |
|
43 | - return true; |
|
44 | - } |
|
42 | + public function canView($member = false) { |
|
43 | + return true; |
|
44 | + } |
|
45 | 45 | |
46 | - public function canEdit($member = null) { |
|
47 | - return Permission::check('Product_CANCRUD'); |
|
48 | - } |
|
46 | + public function canEdit($member = null) { |
|
47 | + return Permission::check('Product_CANCRUD'); |
|
48 | + } |
|
49 | 49 | |
50 | - public function canDelete($member = null) { |
|
51 | - return Permission::check('Product_CANCRUD'); |
|
52 | - } |
|
50 | + public function canDelete($member = null) { |
|
51 | + return Permission::check('Product_CANCRUD'); |
|
52 | + } |
|
53 | 53 | |
54 | - public function canCreate($member = null) { |
|
55 | - return Permission::check('Product_CANCRUD'); |
|
56 | - } |
|
54 | + public function canCreate($member = null) { |
|
55 | + return Permission::check('Product_CANCRUD'); |
|
56 | + } |
|
57 | 57 | |
58 | 58 | } |
@@ -7,84 +7,84 @@ discard block |
||
7 | 7 | |
8 | 8 | class OptionItem extends DataObject{ |
9 | 9 | |
10 | - private static $db = array( |
|
11 | - 'Title' => 'Text', |
|
12 | - 'WeightModifier' => 'Int', |
|
13 | - 'CodeModifier' => 'Text', |
|
14 | - 'PriceModifier' => 'Currency', |
|
15 | - 'WeightModifierAction' => "Enum('Add,Subtract,Set','Add')", |
|
16 | - 'CodeModifierAction' => "Enum('Add,Subtract,Set','Add')", |
|
17 | - 'PriceModifierAction' => "Enum('Add,Subtract,Set','Add')", |
|
18 | - 'Available' => 'Boolean', |
|
19 | - 'SortOrder' => 'Int' |
|
20 | - ); |
|
21 | - |
|
22 | - private static $has_one = array( |
|
23 | - 'Product' => 'FoxyStripeProduct', |
|
24 | - 'ProductOptionGroup' => 'OptionGroup', |
|
25 | - ); |
|
10 | + private static $db = array( |
|
11 | + 'Title' => 'Text', |
|
12 | + 'WeightModifier' => 'Int', |
|
13 | + 'CodeModifier' => 'Text', |
|
14 | + 'PriceModifier' => 'Currency', |
|
15 | + 'WeightModifierAction' => "Enum('Add,Subtract,Set','Add')", |
|
16 | + 'CodeModifierAction' => "Enum('Add,Subtract,Set','Add')", |
|
17 | + 'PriceModifierAction' => "Enum('Add,Subtract,Set','Add')", |
|
18 | + 'Available' => 'Boolean', |
|
19 | + 'SortOrder' => 'Int' |
|
20 | + ); |
|
21 | + |
|
22 | + private static $has_one = array( |
|
23 | + 'Product' => 'FoxyStripeProduct', |
|
24 | + 'ProductOptionGroup' => 'OptionGroup', |
|
25 | + ); |
|
26 | 26 | |
27 | 27 | private static $belongs_many_many = array( |
28 | 28 | 'OrderDetails' => 'OrderDetail' |
29 | 29 | ); |
30 | 30 | |
31 | 31 | private static $defaults = array( |
32 | - 'Available' => true |
|
33 | - ); |
|
32 | + 'Available' => true |
|
33 | + ); |
|
34 | 34 | |
35 | - private static $summary_fields = array( |
|
36 | - 'Title' => 'Title', |
|
37 | - 'ProductOptionGroup.Title' => 'Group', |
|
35 | + private static $summary_fields = array( |
|
36 | + 'Title' => 'Title', |
|
37 | + 'ProductOptionGroup.Title' => 'Group', |
|
38 | 38 | 'Available.Nice' => 'Available' |
39 | - ); |
|
39 | + ); |
|
40 | 40 | |
41 | - private static $default_sort = 'SortOrder'; |
|
41 | + private static $default_sort = 'SortOrder'; |
|
42 | 42 | |
43 | - public function getCMSFields(){ |
|
44 | - $fields = FieldList::create( |
|
45 | - new Tabset('Root', |
|
46 | - new Tab('Main'), |
|
47 | - new Tab('Modifiers') |
|
48 | - ) |
|
49 | - ); |
|
43 | + public function getCMSFields(){ |
|
44 | + $fields = FieldList::create( |
|
45 | + new Tabset('Root', |
|
46 | + new Tab('Main'), |
|
47 | + new Tab('Modifiers') |
|
48 | + ) |
|
49 | + ); |
|
50 | 50 | |
51 | - // set variables from Product |
|
51 | + // set variables from Product |
|
52 | 52 | $productID = ($this->ProductID != 0) ? $this->ProductID : Session::get('CMSMain.currentPage'); |
53 | 53 | $product = ProductPage::get()->byID($productID); |
54 | 54 | |
55 | - $parentPrice = $product->obj('Price')->Nice(); |
|
56 | - $parentWeight = $product->Weight; |
|
57 | - $parentCode = $product->Code; |
|
58 | - |
|
59 | - // ProductOptionGroup Dropdown field w/ add new |
|
60 | - $groups = function(){ |
|
61 | - return OptionGroup::get()->map()->toArray(); |
|
62 | - }; |
|
63 | - $groupFields = singleton('OptionGroup')->getCMSFields(); |
|
64 | - $groupField = DropdownField::create('ProductOptionGroupID', _t("OptionItem.Group", "Group"), $groups()) |
|
65 | - ->setEmptyString('') |
|
55 | + $parentPrice = $product->obj('Price')->Nice(); |
|
56 | + $parentWeight = $product->Weight; |
|
57 | + $parentCode = $product->Code; |
|
58 | + |
|
59 | + // ProductOptionGroup Dropdown field w/ add new |
|
60 | + $groups = function(){ |
|
61 | + return OptionGroup::get()->map()->toArray(); |
|
62 | + }; |
|
63 | + $groupFields = singleton('OptionGroup')->getCMSFields(); |
|
64 | + $groupField = DropdownField::create('ProductOptionGroupID', _t("OptionItem.Group", "Group"), $groups()) |
|
65 | + ->setEmptyString('') |
|
66 | 66 | ->setDescription(_t('OptionItem.GroupDescription', 'Name of this group of options. Managed in <a href="admin/settings">Settings > FoxyStripe > Option Groups</a>')); |
67 | - if (class_exists('QuickAddNewExtension')) $groupField->useAddNew('OptionGroup', $groups, $groupFields); |
|
67 | + if (class_exists('QuickAddNewExtension')) $groupField->useAddNew('OptionGroup', $groups, $groupFields); |
|
68 | 68 | |
69 | 69 | $fields->addFieldsToTab('Root.Main', array( |
70 | - HeaderField::create('DetailsHD', _t("OptionItem.DetailsHD", "Product Option Details"), 2), |
|
71 | - Textfield::create('Title') |
|
70 | + HeaderField::create('DetailsHD', _t("OptionItem.DetailsHD", "Product Option Details"), 2), |
|
71 | + Textfield::create('Title') |
|
72 | 72 | ->setTitle(_t("OptionItem.Title", "Product Option Name")), |
73 | - CheckboxField::create('Available') |
|
74 | - ->setTitle( _t("OptionItem.Available", "Available for purchase")) |
|
73 | + CheckboxField::create('Available') |
|
74 | + ->setTitle( _t("OptionItem.Available", "Available for purchase")) |
|
75 | 75 | ->setDescription(_t('OptionItem.AvailableDescription', "If unchecked, will disable this option in the drop down menu")), |
76 | - $groupField |
|
77 | - )); |
|
76 | + $groupField |
|
77 | + )); |
|
78 | 78 | |
79 | - $fields->addFieldsToTab('Root.Modifiers', array( |
|
80 | - HeaderField::create('ModifyHD', _t('OptionItem.ModifyHD', 'Product Option Modifiers'), 2), |
|
79 | + $fields->addFieldsToTab('Root.Modifiers', array( |
|
80 | + HeaderField::create('ModifyHD', _t('OptionItem.ModifyHD', 'Product Option Modifiers'), 2), |
|
81 | 81 | |
82 | - // Weight Modifier Fields |
|
83 | - HeaderField::create('WeightHD', _t('OptionItem.WeightHD', 'Modify Weight'), 3), |
|
84 | - NumericField::create('WeightModifier') |
|
82 | + // Weight Modifier Fields |
|
83 | + HeaderField::create('WeightHD', _t('OptionItem.WeightHD', 'Modify Weight'), 3), |
|
84 | + NumericField::create('WeightModifier') |
|
85 | 85 | ->setTitle(_t('OptionItem.WeightModifier', 'Weight')), |
86 | - DropdownField::create('WeightModifierAction', _t('OptionItem.WeightModifierAction', 'Weight Modification'), |
|
87 | - array( |
|
86 | + DropdownField::create('WeightModifierAction', _t('OptionItem.WeightModifierAction', 'Weight Modification'), |
|
87 | + array( |
|
88 | 88 | 'Add' => _t( |
89 | 89 | 'OptionItem.WeightAdd', |
90 | 90 | "Add to Base Weight ({weight})", |
@@ -98,56 +98,56 @@ discard block |
||
98 | 98 | array('weight' => $parentWeight) |
99 | 99 | ), |
100 | 100 | 'Set' => _t('OptionItem.WeightSet', 'Set as a new Weight') |
101 | - ) |
|
102 | - )->setEmptyString('') |
|
103 | - ->setDescription(_t('OptionItem.WeightDescription', 'Does weight modify or replace base weight?')), |
|
101 | + ) |
|
102 | + )->setEmptyString('') |
|
103 | + ->setDescription(_t('OptionItem.WeightDescription', 'Does weight modify or replace base weight?')), |
|
104 | 104 | |
105 | - // Price Modifier FIelds |
|
106 | - HeaderField::create('PriceHD', _t('OptionItem.PriceHD', 'Modify Price'), 3), |
|
107 | - CurrencyField::create('PriceModifier') |
|
105 | + // Price Modifier FIelds |
|
106 | + HeaderField::create('PriceHD', _t('OptionItem.PriceHD', 'Modify Price'), 3), |
|
107 | + CurrencyField::create('PriceModifier') |
|
108 | 108 | ->setTitle(_t('OptionItem.PriceModifier', 'Price')), |
109 | - DropdownField::create('PriceModifierAction', _t('OptionItem.PriceModifierAction', 'Price Modification'), |
|
110 | - array( |
|
111 | - 'Add' => _t( |
|
109 | + DropdownField::create('PriceModifierAction', _t('OptionItem.PriceModifierAction', 'Price Modification'), |
|
110 | + array( |
|
111 | + 'Add' => _t( |
|
112 | 112 | 'OptionItem.PriceAdd', |
113 | 113 | "Add to Base Price ({price})", |
114 | 114 | 'Add to price', |
115 | 115 | array('price' => $parentPrice) |
116 | 116 | ), |
117 | - 'Subtract' => _t( |
|
117 | + 'Subtract' => _t( |
|
118 | 118 | 'OptionItem.PriceSubtract', |
119 | 119 | "Subtract from Base Price ({price})", |
120 | 120 | 'Subtract from price', |
121 | 121 | array('price' => $parentPrice) |
122 | 122 | ), |
123 | - 'Set' => _t('OptionItem.PriceSet', 'Set as a new Price') |
|
124 | - ) |
|
125 | - )->setEmptyString('') |
|
126 | - ->setDescription(_t('OptionItem.PriceDescription', 'Does price modify or replace base price?')), |
|
127 | - |
|
128 | - // Code Modifier Fields |
|
129 | - HeaderField::create('CodeHD', _t('OptionItem.CodeHD', 'Modify Code'), 3), |
|
130 | - TextField::create('CodeModifier') |
|
123 | + 'Set' => _t('OptionItem.PriceSet', 'Set as a new Price') |
|
124 | + ) |
|
125 | + )->setEmptyString('') |
|
126 | + ->setDescription(_t('OptionItem.PriceDescription', 'Does price modify or replace base price?')), |
|
127 | + |
|
128 | + // Code Modifier Fields |
|
129 | + HeaderField::create('CodeHD', _t('OptionItem.CodeHD', 'Modify Code'), 3), |
|
130 | + TextField::create('CodeModifier') |
|
131 | 131 | ->setTitle(_t('OptionItem.CodeModifier', 'Code')), |
132 | - DropdownField::create('CodeModifierAction', _t('OptionItem.CodeModifierAction', 'Code Modification'), |
|
133 | - array( |
|
134 | - 'Add' => _t( |
|
132 | + DropdownField::create('CodeModifierAction', _t('OptionItem.CodeModifierAction', 'Code Modification'), |
|
133 | + array( |
|
134 | + 'Add' => _t( |
|
135 | 135 | 'OptionItem.CodeAdd', |
136 | 136 | "Add to Base Code ({code})", |
137 | 137 | 'Add to code', |
138 | 138 | array('code' => $parentCode) |
139 | 139 | ), |
140 | - 'Subtract' => _t( |
|
140 | + 'Subtract' => _t( |
|
141 | 141 | 'OptionItem.CodeSubtract', |
142 | 142 | 'Subtract from Base Code ({code})', |
143 | 143 | 'Subtract from code', |
144 | 144 | array('code' => $parentCode) |
145 | 145 | ), |
146 | - 'Set' => _t('OptionItem.CodeSet', 'Set as a new Code') |
|
147 | - ) |
|
148 | - )->setEmptyString('') |
|
149 | - ->setDescription(_t('OptionItem.CodeDescription', 'Does code modify or replace base code?')) |
|
150 | - )); |
|
146 | + 'Set' => _t('OptionItem.CodeSet', 'Set as a new Code') |
|
147 | + ) |
|
148 | + )->setEmptyString('') |
|
149 | + ->setDescription(_t('OptionItem.CodeDescription', 'Does code modify or replace base code?')) |
|
150 | + )); |
|
151 | 151 | |
152 | 152 | /* |
153 | 153 | // Cateogry Dropdown field w/ add new |
@@ -166,85 +166,85 @@ discard block |
||
166 | 166 | */ |
167 | 167 | |
168 | 168 | // allow CMS fields to be extended |
169 | - $this->extend('getCMSFields', $fields); |
|
170 | - |
|
171 | - return $fields; |
|
172 | - } |
|
173 | - |
|
174 | - public function validate(){ |
|
175 | - $result = parent::validate(); |
|
176 | - |
|
177 | - if($this->ProductOptionGroupID == 0){ |
|
178 | - $result->error('Must set a Group prior to saving'); |
|
179 | - } |
|
180 | - |
|
181 | - return $result; |
|
182 | - } |
|
183 | - |
|
184 | - public static function getOptionModifierActionSymbol($oma, $returnWithOnlyPlusMinus=false){ |
|
185 | - switch($oma){ |
|
186 | - case 'Subtract': |
|
187 | - $symbol = '-'; |
|
188 | - break; |
|
189 | - case 'Set': |
|
190 | - $symbol = ($returnWithOnlyPlusMinus) ? '' : ':'; |
|
191 | - break; |
|
192 | - default: |
|
193 | - $symbol = '+'; |
|
194 | - } |
|
195 | - return $symbol; |
|
196 | - } |
|
197 | - |
|
198 | - public function getWeightModifierWithSymbol(){ |
|
199 | - return self::getOptionModifierActionSymbol($this->WeightModifierAction).$this->WeightModifier; |
|
200 | - } |
|
201 | - |
|
202 | - public function getPriceModifierWithSymbol(){ |
|
203 | - return self::getOptionModifierActionSymbol($this->PriceModifierAction).$this->PriceModifier; |
|
204 | - } |
|
205 | - |
|
206 | - public function getCodeModifierWithSymbol(){ |
|
207 | - return self::getOptionModifierActionSymbol($this->CodeModifierAction).$this->CodeModifier; |
|
208 | - } |
|
209 | - |
|
210 | - public function getProductOptionGroupTitle(){ |
|
211 | - return $this->ProductOptionGroup()->Title; |
|
212 | - } |
|
213 | - |
|
214 | - public function getGeneratedValue(){ |
|
215 | - $modPrice = ($this->PriceModifier) ? (string)$this->PriceModifier : '0'; |
|
216 | - $modPriceWithSymbol = OptionItem::getOptionModifierActionSymbol($this->PriceModifierAction).$modPrice; |
|
217 | - $modWeight = ($this->WeightModifier) ? (string)$this->WeightModifier : '0'; |
|
218 | - $modWeight = OptionItem::getOptionModifierActionSymbol($this->WeightModifierAction).$modWeight; |
|
219 | - $modCode = OptionItem::getOptionModifierActionSymbol($this->CodeModifierAction).$this->CodeModifier; |
|
220 | - return $this->Title.'{p'.$modPriceWithSymbol.'|w'.$modWeight.'|c'.$modCode.'}'; |
|
221 | - } |
|
222 | - |
|
223 | - public function getGeneratedTitle(){ |
|
224 | - $modPrice = ($this->PriceModifier) ? (string)$this->PriceModifier : '0'; |
|
225 | - $title = $this->Title; |
|
226 | - $title .= ($this->PriceModifier != 0) ? ': ('.OptionItem::getOptionModifierActionSymbol($this->PriceModifierAction, $returnWithOnlyPlusMinus=true).'$'.$modPrice.')' : ''; |
|
227 | - return $title; |
|
228 | - } |
|
229 | - |
|
230 | - public function getAvailability(){ |
|
231 | - return ($this->Available == 0) ? true : false ; |
|
232 | - } |
|
233 | - |
|
234 | - public function canView($member = false) { |
|
235 | - return true; |
|
236 | - } |
|
237 | - |
|
238 | - public function canEdit($member = null) { |
|
239 | - return Permission::check('Product_CANCRUD'); |
|
240 | - } |
|
241 | - |
|
242 | - public function canDelete($member = null) { |
|
243 | - return Permission::check('Product_CANCRUD'); |
|
244 | - } |
|
245 | - |
|
246 | - public function canCreate($member = null) { |
|
247 | - return Permission::check('Product_CANCRUD'); |
|
248 | - } |
|
169 | + $this->extend('getCMSFields', $fields); |
|
170 | + |
|
171 | + return $fields; |
|
172 | + } |
|
173 | + |
|
174 | + public function validate(){ |
|
175 | + $result = parent::validate(); |
|
176 | + |
|
177 | + if($this->ProductOptionGroupID == 0){ |
|
178 | + $result->error('Must set a Group prior to saving'); |
|
179 | + } |
|
180 | + |
|
181 | + return $result; |
|
182 | + } |
|
183 | + |
|
184 | + public static function getOptionModifierActionSymbol($oma, $returnWithOnlyPlusMinus=false){ |
|
185 | + switch($oma){ |
|
186 | + case 'Subtract': |
|
187 | + $symbol = '-'; |
|
188 | + break; |
|
189 | + case 'Set': |
|
190 | + $symbol = ($returnWithOnlyPlusMinus) ? '' : ':'; |
|
191 | + break; |
|
192 | + default: |
|
193 | + $symbol = '+'; |
|
194 | + } |
|
195 | + return $symbol; |
|
196 | + } |
|
197 | + |
|
198 | + public function getWeightModifierWithSymbol(){ |
|
199 | + return self::getOptionModifierActionSymbol($this->WeightModifierAction).$this->WeightModifier; |
|
200 | + } |
|
201 | + |
|
202 | + public function getPriceModifierWithSymbol(){ |
|
203 | + return self::getOptionModifierActionSymbol($this->PriceModifierAction).$this->PriceModifier; |
|
204 | + } |
|
205 | + |
|
206 | + public function getCodeModifierWithSymbol(){ |
|
207 | + return self::getOptionModifierActionSymbol($this->CodeModifierAction).$this->CodeModifier; |
|
208 | + } |
|
209 | + |
|
210 | + public function getProductOptionGroupTitle(){ |
|
211 | + return $this->ProductOptionGroup()->Title; |
|
212 | + } |
|
213 | + |
|
214 | + public function getGeneratedValue(){ |
|
215 | + $modPrice = ($this->PriceModifier) ? (string)$this->PriceModifier : '0'; |
|
216 | + $modPriceWithSymbol = OptionItem::getOptionModifierActionSymbol($this->PriceModifierAction).$modPrice; |
|
217 | + $modWeight = ($this->WeightModifier) ? (string)$this->WeightModifier : '0'; |
|
218 | + $modWeight = OptionItem::getOptionModifierActionSymbol($this->WeightModifierAction).$modWeight; |
|
219 | + $modCode = OptionItem::getOptionModifierActionSymbol($this->CodeModifierAction).$this->CodeModifier; |
|
220 | + return $this->Title.'{p'.$modPriceWithSymbol.'|w'.$modWeight.'|c'.$modCode.'}'; |
|
221 | + } |
|
222 | + |
|
223 | + public function getGeneratedTitle(){ |
|
224 | + $modPrice = ($this->PriceModifier) ? (string)$this->PriceModifier : '0'; |
|
225 | + $title = $this->Title; |
|
226 | + $title .= ($this->PriceModifier != 0) ? ': ('.OptionItem::getOptionModifierActionSymbol($this->PriceModifierAction, $returnWithOnlyPlusMinus=true).'$'.$modPrice.')' : ''; |
|
227 | + return $title; |
|
228 | + } |
|
229 | + |
|
230 | + public function getAvailability(){ |
|
231 | + return ($this->Available == 0) ? true : false ; |
|
232 | + } |
|
233 | + |
|
234 | + public function canView($member = false) { |
|
235 | + return true; |
|
236 | + } |
|
237 | + |
|
238 | + public function canEdit($member = null) { |
|
239 | + return Permission::check('Product_CANCRUD'); |
|
240 | + } |
|
241 | + |
|
242 | + public function canDelete($member = null) { |
|
243 | + return Permission::check('Product_CANCRUD'); |
|
244 | + } |
|
245 | + |
|
246 | + public function canCreate($member = null) { |
|
247 | + return Permission::check('Product_CANCRUD'); |
|
248 | + } |
|
249 | 249 | |
250 | 250 | } |
@@ -2,67 +2,67 @@ discard block |
||
2 | 2 | |
3 | 3 | class ProductDiscountTier extends DataObject { |
4 | 4 | |
5 | - private static $singular_name = 'Discount Tier'; |
|
6 | - private static $plural_name = 'Discount Tiers'; |
|
7 | - private static $description = 'A discount tier for a Product Discount'; |
|
8 | - |
|
9 | - private static $db = array( |
|
10 | - 'Quantity' => 'Int', |
|
11 | - 'Percentage' => 'Int' |
|
12 | - ); |
|
13 | - private static $has_one = array( |
|
14 | - 'Product' => 'FoxyStripeProduct' |
|
15 | - ); |
|
16 | - private static $has_many = array(); |
|
17 | - private static $many_many = array(); |
|
18 | - private static $many_many_extraFields = array(); |
|
19 | - private static $belongs_many_many = array(); |
|
20 | - |
|
21 | - private static $casting = array(); |
|
22 | - private static $defaults = array(); |
|
23 | - private static $default_sort = array( |
|
24 | - 'Quantity' |
|
25 | - ); |
|
26 | - |
|
27 | - |
|
28 | - private static $summary_fields = array( |
|
29 | - 'Quantity', |
|
30 | - 'DiscountPercentage' |
|
31 | - ); |
|
32 | - private static $searchable_fields = array(); |
|
33 | - private static $field_labels = array( |
|
34 | - 'Quantity' => 'Quantity', |
|
35 | - 'DiscountPercentage' => 'Discount' |
|
36 | - ); |
|
37 | - private static $indexes = array(); |
|
38 | - |
|
39 | - public function getCMSFields(){ |
|
40 | - $fields = parent::getCMSFields(); |
|
41 | - |
|
42 | - $fields->removeByName('ProductPageID'); |
|
43 | - |
|
44 | - $quantity = $fields->dataFieldByName('Quantity'); |
|
45 | - $quantity->setTitle('Quantity to trigger discount'); |
|
46 | - $percentage = $fields->dataFieldByName('Percentage'); |
|
47 | - $percentage->setTitle('Percent discount'); |
|
48 | - |
|
49 | - $this->extend('updateCMSFields', $fields); |
|
50 | - return $fields; |
|
51 | - } |
|
52 | - |
|
53 | - public function getCMSValidator() { |
|
54 | - return new RequiredFields(array('Quantity', 'Percentage')); |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @return ValidationResult |
|
59 | - * |
|
60 | - * TODO implement validation to ensure values aren't duplicated in multiple tiers |
|
61 | - */ |
|
62 | - public function validate(){ |
|
63 | - $result = parent::validate(); |
|
64 | - |
|
65 | - /*$tierQuantity = ProductDiscountTier::get() |
|
5 | + private static $singular_name = 'Discount Tier'; |
|
6 | + private static $plural_name = 'Discount Tiers'; |
|
7 | + private static $description = 'A discount tier for a Product Discount'; |
|
8 | + |
|
9 | + private static $db = array( |
|
10 | + 'Quantity' => 'Int', |
|
11 | + 'Percentage' => 'Int' |
|
12 | + ); |
|
13 | + private static $has_one = array( |
|
14 | + 'Product' => 'FoxyStripeProduct' |
|
15 | + ); |
|
16 | + private static $has_many = array(); |
|
17 | + private static $many_many = array(); |
|
18 | + private static $many_many_extraFields = array(); |
|
19 | + private static $belongs_many_many = array(); |
|
20 | + |
|
21 | + private static $casting = array(); |
|
22 | + private static $defaults = array(); |
|
23 | + private static $default_sort = array( |
|
24 | + 'Quantity' |
|
25 | + ); |
|
26 | + |
|
27 | + |
|
28 | + private static $summary_fields = array( |
|
29 | + 'Quantity', |
|
30 | + 'DiscountPercentage' |
|
31 | + ); |
|
32 | + private static $searchable_fields = array(); |
|
33 | + private static $field_labels = array( |
|
34 | + 'Quantity' => 'Quantity', |
|
35 | + 'DiscountPercentage' => 'Discount' |
|
36 | + ); |
|
37 | + private static $indexes = array(); |
|
38 | + |
|
39 | + public function getCMSFields(){ |
|
40 | + $fields = parent::getCMSFields(); |
|
41 | + |
|
42 | + $fields->removeByName('ProductPageID'); |
|
43 | + |
|
44 | + $quantity = $fields->dataFieldByName('Quantity'); |
|
45 | + $quantity->setTitle('Quantity to trigger discount'); |
|
46 | + $percentage = $fields->dataFieldByName('Percentage'); |
|
47 | + $percentage->setTitle('Percent discount'); |
|
48 | + |
|
49 | + $this->extend('updateCMSFields', $fields); |
|
50 | + return $fields; |
|
51 | + } |
|
52 | + |
|
53 | + public function getCMSValidator() { |
|
54 | + return new RequiredFields(array('Quantity', 'Percentage')); |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @return ValidationResult |
|
59 | + * |
|
60 | + * TODO implement validation to ensure values aren't duplicated in multiple tiers |
|
61 | + */ |
|
62 | + public function validate(){ |
|
63 | + $result = parent::validate(); |
|
64 | + |
|
65 | + /*$tierQuantity = ProductDiscountTier::get() |
|
66 | 66 | ->filter( |
67 | 67 | array( |
68 | 68 | 'ProductDiscountID' => $this->ProductDiscountID, |
@@ -85,31 +85,31 @@ discard block |
||
85 | 85 | $result->error($this->Percentage." is already used in another discount tier. Please use a different percentage"); |
86 | 86 | }*/ |
87 | 87 | |
88 | - return $result; |
|
89 | - } |
|
88 | + return $result; |
|
89 | + } |
|
90 | 90 | |
91 | - public function getTitle(){ |
|
92 | - return "{$this->Quantity} at {$this->Percentage}%"; |
|
93 | - } |
|
91 | + public function getTitle(){ |
|
92 | + return "{$this->Quantity} at {$this->Percentage}%"; |
|
93 | + } |
|
94 | 94 | |
95 | - public function getDiscountPercentage(){ |
|
96 | - return "{$this->Percentage}%"; |
|
97 | - } |
|
95 | + public function getDiscountPercentage(){ |
|
96 | + return "{$this->Percentage}%"; |
|
97 | + } |
|
98 | 98 | |
99 | - public function canView($member = false) { |
|
100 | - return true; |
|
101 | - } |
|
99 | + public function canView($member = false) { |
|
100 | + return true; |
|
101 | + } |
|
102 | 102 | |
103 | - public function canEdit($member = null) { |
|
104 | - return Permission::check('Product_CANCRUD'); |
|
105 | - } |
|
103 | + public function canEdit($member = null) { |
|
104 | + return Permission::check('Product_CANCRUD'); |
|
105 | + } |
|
106 | 106 | |
107 | - public function canDelete($member = null) { |
|
108 | - return Permission::check('Product_CANCRUD'); |
|
109 | - } |
|
107 | + public function canDelete($member = null) { |
|
108 | + return Permission::check('Product_CANCRUD'); |
|
109 | + } |
|
110 | 110 | |
111 | - public function canCreate($member = null) { |
|
112 | - return Permission::check('Product_CANCRUD'); |
|
113 | - } |
|
111 | + public function canCreate($member = null) { |
|
112 | + return Permission::check('Product_CANCRUD'); |
|
113 | + } |
|
114 | 114 | |
115 | 115 | } |