diff --git a/app/code/Magento/CatalogRule/Block/Adminhtml/Promo/Catalog/Edit/Tab/Actions.php b/app/code/Magento/CatalogRule/Block/Adminhtml/Promo/Catalog/Edit/Tab/Actions.php index 9f4273421911f..6f98f46c62d3a 100644 --- a/app/code/Magento/CatalogRule/Block/Adminhtml/Promo/Catalog/Edit/Tab/Actions.php +++ b/app/code/Magento/CatalogRule/Block/Adminhtml/Promo/Catalog/Edit/Tab/Actions.php @@ -98,44 +98,6 @@ protected function _prepareForm() ] ); - $fieldset->addField( - 'sub_is_enable', - 'select', - [ - 'name' => 'sub_is_enable', - 'label' => __('Subproduct discounts'), - 'title' => __('Subproduct discounts'), - 'onchange' => 'hideShowSubproductOptions(this);', - 'values' => [0 => __('No'), 1 => __('Yes')] - ] - ); - - $fieldset->addField( - 'sub_simple_action', - 'select', - [ - 'label' => __('Apply'), - 'name' => 'sub_simple_action', - 'options' => [ - 'by_percent' => __('Apply as percentage of original'), - 'by_fixed' => __('Apply as fixed amount'), - 'to_percent' => __('Adjust final price to this percentage'), - 'to_fixed' => __('Adjust final price to discount value'), - ] - ] - ); - - $fieldset->addField( - 'sub_discount_amount', - 'text', - [ - 'name' => 'sub_discount_amount', - 'required' => true, - 'class' => 'validate-not-negative-number', - 'label' => __('Discount Amount') - ] - ); - $fieldset->addField( 'stop_rules_processing', 'select', diff --git a/app/code/Magento/CatalogRule/Model/Indexer/IndexBuilder.php b/app/code/Magento/CatalogRule/Model/Indexer/IndexBuilder.php index c145cd9afe2a0..a3571b4d81431 100644 --- a/app/code/Magento/CatalogRule/Model/Indexer/IndexBuilder.php +++ b/app/code/Magento/CatalogRule/Model/Indexer/IndexBuilder.php @@ -274,8 +274,6 @@ protected function applyRule(Rule $rule, $product) $actionOperator = $rule->getSimpleAction(); $actionAmount = $rule->getDiscountAmount(); $actionStop = $rule->getStopRulesProcessing(); - $subActionOperator = $rule->getSubIsEnable() ? $rule->getSubSimpleAction() : ''; - $subActionAmount = $rule->getSubDiscountAmount(); $rows = []; try { @@ -292,8 +290,6 @@ protected function applyRule(Rule $rule, $product) 'action_amount' => $actionAmount, 'action_stop' => $actionStop, 'sort_order' => $sortOrder, - 'sub_simple_action' => $subActionOperator, - 'sub_discount_amount' => $subActionAmount, ]; if (count($rows) == $this->batchCount) { @@ -368,8 +364,6 @@ protected function updateRuleProductData(Rule $rule) $sortOrder = (int)$rule->getSortOrder(); $actionOperator = $rule->getSimpleAction(); $actionAmount = $rule->getDiscountAmount(); - $subActionOperator = $rule->getSubIsEnable() ? $rule->getSubSimpleAction() : ''; - $subActionAmount = $rule->getSubDiscountAmount(); $actionStop = $rule->getStopRulesProcessing(); $rows = []; @@ -391,8 +385,6 @@ protected function updateRuleProductData(Rule $rule) 'action_amount' => $actionAmount, 'action_stop' => $actionStop, 'sort_order' => $sortOrder, - 'sub_simple_action' => $subActionOperator, - 'sub_discount_amount' => $subActionAmount, ]; if (count($rows) == $this->batchCount) { diff --git a/app/code/Magento/CatalogRule/Model/Rule.php b/app/code/Magento/CatalogRule/Model/Rule.php index d89b7d6e4c143..023a5dbfe9fd6 100644 --- a/app/code/Magento/CatalogRule/Model/Rule.php +++ b/app/code/Magento/CatalogRule/Model/Rule.php @@ -352,11 +352,6 @@ public function validateData(\Magento\Framework\DataObject $dataObject) $action = $dataObject->getData('simple_action'); $discount = $dataObject->getData('discount_amount'); $result = array_merge($result, $this->validateDiscount($action, $discount)); - if ($dataObject->getData('sub_is_enable') == 1) { - $action = $dataObject->getData('sub_simple_action'); - $discount = $dataObject->getData('sub_discount_amount'); - $result = array_merge($result, $this->validateDiscount($action, $discount)); - } return !empty($result) ? $result : true; } @@ -418,15 +413,7 @@ public function calcProductPriceRule(Product $product, $price) if ($rulesData) { foreach ($rulesData as $ruleData) { if ($product->getParentId()) { - if (!empty($ruleData['sub_simple_action'])) { - $priceRules = $this->_catalogRuleData->calcPriceRule( - $ruleData['sub_simple_action'], - $ruleData['sub_discount_amount'], - $priceRules ? $priceRules : $price - ); - } else { - $priceRules = $priceRules ? $priceRules : $price; - } + $priceRules = $priceRules ? $priceRules : $price; if ($ruleData['action_stop']) { break; } diff --git a/app/code/Magento/CatalogRule/Setup/UpgradeSchema.php b/app/code/Magento/CatalogRule/Setup/UpgradeSchema.php new file mode 100644 index 0000000000000..1decf934e476e --- /dev/null +++ b/app/code/Magento/CatalogRule/Setup/UpgradeSchema.php @@ -0,0 +1,58 @@ +startSetup(); + + if (version_compare($context->getVersion(), '2.0.1', '<')) { + $this->removeSubProductDiscounts($setup); + } + + $setup->endSetup(); + } + + /** + * Remove Sub Product Discounts + * @param SchemaSetupInterface $setup + * @return void + */ + private function removeSubProductDiscounts(SchemaSetupInterface $setup) + { + $connection = $setup->getConnection(); + $data = [ + 'catalogrule' => [ + 'sub_is_enable', + 'sub_simple_action', + 'sub_discount_amount', + ], + 'catalogrule_product' => [ + 'sub_simple_action', + 'sub_discount_amount', + ], + ]; + + foreach ($data as $table => $fields) { + foreach ($fields as $field) { + $connection->dropColumn($setup->getTable($table), $field); + } + } + } +} diff --git a/app/code/Magento/CatalogRule/Test/Unit/Model/RuleTest.php b/app/code/Magento/CatalogRule/Test/Unit/Model/RuleTest.php index bb8b7521642ab..03c4bb1ae47d9 100644 --- a/app/code/Magento/CatalogRule/Test/Unit/Model/RuleTest.php +++ b/app/code/Magento/CatalogRule/Test/Unit/Model/RuleTest.php @@ -232,9 +232,6 @@ public function validateDataDataProvider() [ 'simple_action' => 'by_fixed', 'discount_amount' => '123', - 'sub_is_enable' => '0', - 'sub_simple_action' => 'by_percent', - 'sub_discount_amount' => '123', ], true ], @@ -242,42 +239,22 @@ public function validateDataDataProvider() [ 'simple_action' => 'by_percent', 'discount_amount' => '9,99', - 'sub_is_enable' => '0', ], true ], - [ - [ - 'simple_action' => 'by_fixed', - 'discount_amount' => '123', - 'sub_is_enable' => '1', - 'sub_simple_action' => 'by_percent', - 'sub_discount_amount' => '123', - ], - [ - 'Percentage discount should be between 0 and 100.', - ] - ], [ [ 'simple_action' => 'by_percent', 'discount_amount' => '123.12', - 'sub_is_enable' => '1', - 'sub_simple_action' => 'to_percent', - 'sub_discount_amount' => '123.001', ], [ 'Percentage discount should be between 0 and 100.', - 'Percentage discount should be between 0 and 100.', ] ], [ [ 'simple_action' => 'to_percent', 'discount_amount' => '-12', - 'sub_is_enable' => '1', - 'sub_simple_action' => 'to_fixed', - 'sub_discount_amount' => '567.8901', ], [ 'Percentage discount should be between 0 and 100.', @@ -287,20 +264,15 @@ public function validateDataDataProvider() [ 'simple_action' => 'to_fixed', 'discount_amount' => '-1234567890', - 'sub_is_enable' => '1', - 'sub_simple_action' => 'by_fixed', - 'sub_discount_amount' => '-5', ], [ 'Discount value should be 0 or greater.', - 'Discount value should be 0 or greater.', ] ], [ [ 'simple_action' => 'invalid action', 'discount_amount' => '12', - 'sub_is_enable' => '0', ], [ 'Unknown action.', diff --git a/app/code/Magento/CatalogRule/etc/module.xml b/app/code/Magento/CatalogRule/etc/module.xml index 19dfacb2cc3bd..868765ce17862 100644 --- a/app/code/Magento/CatalogRule/etc/module.xml +++ b/app/code/Magento/CatalogRule/etc/module.xml @@ -6,7 +6,7 @@ */ --> - + diff --git a/app/code/Magento/CatalogRule/view/adminhtml/templates/promo/js.phtml b/app/code/Magento/CatalogRule/view/adminhtml/templates/promo/js.phtml index a3604faa6d38c..1feb2f1cc693f 100644 --- a/app/code/Magento/CatalogRule/view/adminhtml/templates/promo/js.phtml +++ b/app/code/Magento/CatalogRule/view/adminhtml/templates/promo/js.phtml @@ -7,26 +7,6 @@ diff --git a/dev/tests/integration/testsuite/Magento/CatalogRule/Model/RuleTest.php b/dev/tests/integration/testsuite/Magento/CatalogRule/Model/RuleTest.php index 40ee3643f05ec..0bcea6e411fe9 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogRule/Model/RuleTest.php +++ b/dev/tests/integration/testsuite/Magento/CatalogRule/Model/RuleTest.php @@ -51,7 +51,7 @@ public function testCalcProductPriceRule() ); $this->assertEquals($this->_object->calcProductPriceRule($product, 100), 45); $product->setParentId(true); - $this->assertEquals($this->_object->calcProductPriceRule($product, 50), 5); + $this->assertEquals($this->_object->calcProductPriceRule($product, 50), 50); } /** @@ -64,16 +64,12 @@ protected function _getCatalogRulesFixtures() return [ [ 'action_operator' => 'by_percent', - 'action_amount' => '10.0000', - 'sub_simple_action' => 'by_percent', - 'sub_discount_amount' => '90.0000', - 'action_stop' => '0', + 'action_amount' => '50.0000', + 'action_stop' => '0' ], [ 'action_operator' => 'by_percent', - 'action_amount' => '50.0000', - 'sub_simple_action' => '', - 'sub_discount_amount' => '0.0000', + 'action_amount' => '10.0000', 'action_stop' => '0' ] ]; diff --git a/setup/src/Magento/Setup/Fixtures/CatalogPriceRulesFixture.php b/setup/src/Magento/Setup/Fixtures/CatalogPriceRulesFixture.php index 29134e5a06e1a..ec83f33944f3e 100644 --- a/setup/src/Magento/Setup/Fixtures/CatalogPriceRulesFixture.php +++ b/setup/src/Magento/Setup/Fixtures/CatalogPriceRulesFixture.php @@ -100,9 +100,6 @@ public function execute() ], 'simple_action' => 'by_percent', 'discount_amount' => '15', - 'sub_is_enable' => '0', - 'sub_simple_action' => 'by_percent', - 'sub_discount_amount' => '0', 'stop_rules_processing' => '0', 'page' => '1', 'limit' => '20',