Skip to content

Commit 26a148a

Browse files
author
He, Joan(johe)
committed
Merge pull request #255 from magento-troll/MAGETWO-40061
[Troll] MAGETWO-40061
2 parents e7105f2 + 466d75d commit 26a148a

File tree

9 files changed

+64
-140
lines changed

9 files changed

+64
-140
lines changed

app/code/Magento/CatalogRule/Block/Adminhtml/Promo/Catalog/Edit/Tab/Actions.php

-38
Original file line numberDiff line numberDiff line change
@@ -98,44 +98,6 @@ protected function _prepareForm()
9898
]
9999
);
100100

101-
$fieldset->addField(
102-
'sub_is_enable',
103-
'select',
104-
[
105-
'name' => 'sub_is_enable',
106-
'label' => __('Subproduct discounts'),
107-
'title' => __('Subproduct discounts'),
108-
'onchange' => 'hideShowSubproductOptions(this);',
109-
'values' => [0 => __('No'), 1 => __('Yes')]
110-
]
111-
);
112-
113-
$fieldset->addField(
114-
'sub_simple_action',
115-
'select',
116-
[
117-
'label' => __('Apply'),
118-
'name' => 'sub_simple_action',
119-
'options' => [
120-
'by_percent' => __('Apply as percentage of original'),
121-
'by_fixed' => __('Apply as fixed amount'),
122-
'to_percent' => __('Adjust final price to this percentage'),
123-
'to_fixed' => __('Adjust final price to discount value'),
124-
]
125-
]
126-
);
127-
128-
$fieldset->addField(
129-
'sub_discount_amount',
130-
'text',
131-
[
132-
'name' => 'sub_discount_amount',
133-
'required' => true,
134-
'class' => 'validate-not-negative-number',
135-
'label' => __('Discount Amount')
136-
]
137-
);
138-
139101
$fieldset->addField(
140102
'stop_rules_processing',
141103
'select',

app/code/Magento/CatalogRule/Model/Indexer/IndexBuilder.php

-8
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,6 @@ protected function applyRule(Rule $rule, $product)
274274
$actionOperator = $rule->getSimpleAction();
275275
$actionAmount = $rule->getDiscountAmount();
276276
$actionStop = $rule->getStopRulesProcessing();
277-
$subActionOperator = $rule->getSubIsEnable() ? $rule->getSubSimpleAction() : '';
278-
$subActionAmount = $rule->getSubDiscountAmount();
279277

280278
$rows = [];
281279
try {
@@ -292,8 +290,6 @@ protected function applyRule(Rule $rule, $product)
292290
'action_amount' => $actionAmount,
293291
'action_stop' => $actionStop,
294292
'sort_order' => $sortOrder,
295-
'sub_simple_action' => $subActionOperator,
296-
'sub_discount_amount' => $subActionAmount,
297293
];
298294

299295
if (count($rows) == $this->batchCount) {
@@ -368,8 +364,6 @@ protected function updateRuleProductData(Rule $rule)
368364
$sortOrder = (int)$rule->getSortOrder();
369365
$actionOperator = $rule->getSimpleAction();
370366
$actionAmount = $rule->getDiscountAmount();
371-
$subActionOperator = $rule->getSubIsEnable() ? $rule->getSubSimpleAction() : '';
372-
$subActionAmount = $rule->getSubDiscountAmount();
373367
$actionStop = $rule->getStopRulesProcessing();
374368

375369
$rows = [];
@@ -391,8 +385,6 @@ protected function updateRuleProductData(Rule $rule)
391385
'action_amount' => $actionAmount,
392386
'action_stop' => $actionStop,
393387
'sort_order' => $sortOrder,
394-
'sub_simple_action' => $subActionOperator,
395-
'sub_discount_amount' => $subActionAmount,
396388
];
397389

398390
if (count($rows) == $this->batchCount) {

app/code/Magento/CatalogRule/Model/Rule.php

+1-14
Original file line numberDiff line numberDiff line change
@@ -352,11 +352,6 @@ public function validateData(\Magento\Framework\DataObject $dataObject)
352352
$action = $dataObject->getData('simple_action');
353353
$discount = $dataObject->getData('discount_amount');
354354
$result = array_merge($result, $this->validateDiscount($action, $discount));
355-
if ($dataObject->getData('sub_is_enable') == 1) {
356-
$action = $dataObject->getData('sub_simple_action');
357-
$discount = $dataObject->getData('sub_discount_amount');
358-
$result = array_merge($result, $this->validateDiscount($action, $discount));
359-
}
360355

361356
return !empty($result) ? $result : true;
362357
}
@@ -418,15 +413,7 @@ public function calcProductPriceRule(Product $product, $price)
418413
if ($rulesData) {
419414
foreach ($rulesData as $ruleData) {
420415
if ($product->getParentId()) {
421-
if (!empty($ruleData['sub_simple_action'])) {
422-
$priceRules = $this->_catalogRuleData->calcPriceRule(
423-
$ruleData['sub_simple_action'],
424-
$ruleData['sub_discount_amount'],
425-
$priceRules ? $priceRules : $price
426-
);
427-
} else {
428-
$priceRules = $priceRules ? $priceRules : $price;
429-
}
416+
$priceRules = $priceRules ? $priceRules : $price;
430417
if ($ruleData['action_stop']) {
431418
break;
432419
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\CatalogRule\Setup;
8+
9+
use Magento\Framework\Setup\UpgradeSchemaInterface;
10+
use Magento\Framework\Setup\ModuleContextInterface;
11+
use Magento\Framework\Setup\SchemaSetupInterface;
12+
13+
/**
14+
* Upgrade the CatalogRule module DB scheme
15+
*/
16+
class UpgradeSchema implements UpgradeSchemaInterface
17+
{
18+
/**
19+
* {@inheritdoc}
20+
*/
21+
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
22+
{
23+
$setup->startSetup();
24+
25+
if (version_compare($context->getVersion(), '2.0.1', '<')) {
26+
$this->removeSubProductDiscounts($setup);
27+
}
28+
29+
$setup->endSetup();
30+
}
31+
32+
/**
33+
* Remove Sub Product Discounts
34+
* @param SchemaSetupInterface $setup
35+
* @return void
36+
*/
37+
private function removeSubProductDiscounts(SchemaSetupInterface $setup)
38+
{
39+
$connection = $setup->getConnection();
40+
$data = [
41+
'catalogrule' => [
42+
'sub_is_enable',
43+
'sub_simple_action',
44+
'sub_discount_amount',
45+
],
46+
'catalogrule_product' => [
47+
'sub_simple_action',
48+
'sub_discount_amount',
49+
],
50+
];
51+
52+
foreach ($data as $table => $fields) {
53+
foreach ($fields as $field) {
54+
$connection->dropColumn($setup->getTable($table), $field);
55+
}
56+
}
57+
}
58+
}

app/code/Magento/CatalogRule/Test/Unit/Model/RuleTest.php

-28
Original file line numberDiff line numberDiff line change
@@ -232,52 +232,29 @@ public function validateDataDataProvider()
232232
[
233233
'simple_action' => 'by_fixed',
234234
'discount_amount' => '123',
235-
'sub_is_enable' => '0',
236-
'sub_simple_action' => 'by_percent',
237-
'sub_discount_amount' => '123',
238235
],
239236
true
240237
],
241238
[
242239
[
243240
'simple_action' => 'by_percent',
244241
'discount_amount' => '9,99',
245-
'sub_is_enable' => '0',
246242
],
247243
true
248244
],
249-
[
250-
[
251-
'simple_action' => 'by_fixed',
252-
'discount_amount' => '123',
253-
'sub_is_enable' => '1',
254-
'sub_simple_action' => 'by_percent',
255-
'sub_discount_amount' => '123',
256-
],
257-
[
258-
'Percentage discount should be between 0 and 100.',
259-
]
260-
],
261245
[
262246
[
263247
'simple_action' => 'by_percent',
264248
'discount_amount' => '123.12',
265-
'sub_is_enable' => '1',
266-
'sub_simple_action' => 'to_percent',
267-
'sub_discount_amount' => '123.001',
268249
],
269250
[
270251
'Percentage discount should be between 0 and 100.',
271-
'Percentage discount should be between 0 and 100.',
272252
]
273253
],
274254
[
275255
[
276256
'simple_action' => 'to_percent',
277257
'discount_amount' => '-12',
278-
'sub_is_enable' => '1',
279-
'sub_simple_action' => 'to_fixed',
280-
'sub_discount_amount' => '567.8901',
281258
],
282259
[
283260
'Percentage discount should be between 0 and 100.',
@@ -287,20 +264,15 @@ public function validateDataDataProvider()
287264
[
288265
'simple_action' => 'to_fixed',
289266
'discount_amount' => '-1234567890',
290-
'sub_is_enable' => '1',
291-
'sub_simple_action' => 'by_fixed',
292-
'sub_discount_amount' => '-5',
293267
],
294268
[
295269
'Discount value should be 0 or greater.',
296-
'Discount value should be 0 or greater.',
297270
]
298271
],
299272
[
300273
[
301274
'simple_action' => 'invalid action',
302275
'discount_amount' => '12',
303-
'sub_is_enable' => '0',
304276
],
305277
[
306278
'Unknown action.',

app/code/Magento/CatalogRule/etc/module.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9-
<module name="Magento_CatalogRule" setup_version="2.0.0">
9+
<module name="Magento_CatalogRule" setup_version="2.0.1">
1010
<sequence>
1111
<module name="Magento_Rule"/>
1212
<module name="Magento_Catalog"/>

app/code/Magento/CatalogRule/view/adminhtml/templates/promo/js.phtml

-40
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,6 @@
77
<script>
88
require(["jquery", "prototype"], function(jQuery){
99

10-
function hideShowSubproductOptions()
11-
{
12-
if ($('rule_sub_is_enable').value == 1) {
13-
$('rule_sub_simple_action').up('div.field').show();
14-
$('rule_sub_discount_amount').up('div.field').show();
15-
$('rule_sub_discount_amount').addClassName('required-entry validate-not-negative-number');
16-
changeValidationForSubDiscountPercent();
17-
} else {
18-
$('rule_sub_discount_amount').
19-
removeClassName('required-entry').
20-
removeClassName('validate-not-negative-number').
21-
removeClassName('validate-number-range').
22-
removeClassName('number-range-0.00-100.00');
23-
$('rule_sub_simple_action').up('div.field').hide();
24-
$('rule_sub_discount_amount').up('div.field').hide();
25-
}
26-
27-
return true;
28-
}
29-
3010
function changeValidationForDiscountPercent()
3111
{
3212
if ($('rule_simple_action').value == 'by_percent' || $('rule_simple_action').value == 'to_percent') {
@@ -38,28 +18,8 @@ function changeValidationForDiscountPercent()
3818
return true;
3919
}
4020

41-
function changeValidationForSubDiscountPercent()
42-
{
43-
if ($('rule_sub_is_enable').value == 1) {
44-
if ($('rule_sub_simple_action').value == 'by_percent' || $('rule_sub_simple_action').value == 'to_percent') {
45-
$('rule_sub_discount_amount').addClassName('validate-number-range number-range-0.00-100.00');
46-
} else {
47-
$('rule_sub_discount_amount').
48-
removeClassName('validate-number-range').
49-
removeClassName('number-range-0.00-100.00');
50-
}
51-
}
52-
53-
return true;
54-
}
55-
56-
jQuery(document).ready(hideShowSubproductOptions);
5721
jQuery(document).ready(changeValidationForDiscountPercent);
58-
jQuery(document).on('change', '#rule_sub_is_enable', hideShowSubproductOptions);
5922
jQuery(document).on('change', '#rule_simple_action', changeValidationForDiscountPercent);
60-
jQuery(document).on('change', '#rule_sub_simple_action', changeValidationForSubDiscountPercent);
61-
window.hideShowSubproductOptions = hideShowSubproductOptions;
6223
window.changeValidationForDiscountPercent = changeValidationForDiscountPercent;
63-
window.changeValidationForSubDiscountPercent = changeValidationForSubDiscountPercent;
6424
});
6525
</script>

dev/tests/integration/testsuite/Magento/CatalogRule/Model/RuleTest.php

+4-8
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function testCalcProductPriceRule()
5151
);
5252
$this->assertEquals($this->_object->calcProductPriceRule($product, 100), 45);
5353
$product->setParentId(true);
54-
$this->assertEquals($this->_object->calcProductPriceRule($product, 50), 5);
54+
$this->assertEquals($this->_object->calcProductPriceRule($product, 50), 50);
5555
}
5656

5757
/**
@@ -64,16 +64,12 @@ protected function _getCatalogRulesFixtures()
6464
return [
6565
[
6666
'action_operator' => 'by_percent',
67-
'action_amount' => '10.0000',
68-
'sub_simple_action' => 'by_percent',
69-
'sub_discount_amount' => '90.0000',
70-
'action_stop' => '0',
67+
'action_amount' => '50.0000',
68+
'action_stop' => '0'
7169
],
7270
[
7371
'action_operator' => 'by_percent',
74-
'action_amount' => '50.0000',
75-
'sub_simple_action' => '',
76-
'sub_discount_amount' => '0.0000',
72+
'action_amount' => '10.0000',
7773
'action_stop' => '0'
7874
]
7975
];

setup/src/Magento/Setup/Fixtures/CatalogPriceRulesFixture.php

-3
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ public function execute()
100100
],
101101
'simple_action' => 'by_percent',
102102
'discount_amount' => '15',
103-
'sub_is_enable' => '0',
104-
'sub_simple_action' => 'by_percent',
105-
'sub_discount_amount' => '0',
106103
'stop_rules_processing' => '0',
107104
'page' => '1',
108105
'limit' => '20',

0 commit comments

Comments
 (0)