diff --git a/app/code/Magento/OfflineShipping/Model/SalesRule/Calculator.php b/app/code/Magento/OfflineShipping/Model/SalesRule/Calculator.php index b57b0024d0f888fc9be9a7ddc5b570a8a12c99c8..7cd58adf412bf82efb393e9013d9d0171d0ebd27 100644 --- a/app/code/Magento/OfflineShipping/Model/SalesRule/Calculator.php +++ b/app/code/Magento/OfflineShipping/Model/SalesRule/Calculator.php @@ -28,7 +28,7 @@ class Calculator extends Validator $address = $item->getAddress(); $item->setFreeShipping(false); - foreach ($this->_getRules() as $rule) { + foreach ($this->_getRules($address) as $rule) { /* @var $rule \Magento\SalesRule\Model\Rule */ if (!$this->validatorUtility->canProcessRule($rule, $address)) { continue; diff --git a/app/code/Magento/OfflineShipping/Test/Unit/Model/SalesRule/CalculatorTest.php b/app/code/Magento/OfflineShipping/Test/Unit/Model/SalesRule/CalculatorTest.php index b809d32a1755d2d0c5eb1246f379ade5350ff17d..9d0737e9e47ecf1b849216eb1ffc4595a75c349d 100644 --- a/app/code/Magento/OfflineShipping/Test/Unit/Model/SalesRule/CalculatorTest.php +++ b/app/code/Magento/OfflineShipping/Test/Unit/Model/SalesRule/CalculatorTest.php @@ -8,7 +8,7 @@ namespace Magento\OfflineShipping\Test\Unit\Model\SalesRule; class CalculatorTest extends \PHPUnit_Framework_TestCase { /** - * @var \Magento\SalesRule\Model\Validator|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\OfflineShipping\Model\SalesRule\Calculator|\PHPUnit_Framework_MockObject_MockObject */ protected $_model; @@ -21,13 +21,20 @@ class CalculatorTest extends \PHPUnit_Framework_TestCase '', false ); - $this->_model->expects($this->any())->method('_getRules')->will($this->returnValue([])); } public function testProcessFreeShipping() { + $addressMock = $this->getMockBuilder('Magento\Quote\Model\Quote\Address') + ->disableOriginalConstructor() + ->getMock(); $item = $this->getMock('Magento\Quote\Model\Quote\Item', ['getAddress', '__wakeup'], [], '', false); - $item->expects($this->once())->method('getAddress')->will($this->returnValue(true)); + $item->expects($this->once())->method('getAddress')->will($this->returnValue($addressMock)); + + $this->_model->expects($this->once()) + ->method('_getRules') + ->with($addressMock) + ->will($this->returnValue([])); $this->assertInstanceOf( 'Magento\OfflineShipping\Model\SalesRule\Calculator', diff --git a/app/code/Magento/SalesRule/Model/Quote/Discount.php b/app/code/Magento/SalesRule/Model/Quote/Discount.php index 80356b4ef24e2172fb20f54afc5fe992b9a600b5..f5fb198289fce010080a820a10f2e2781eb457e0 100644 --- a/app/code/Magento/SalesRule/Model/Quote/Discount.php +++ b/app/code/Magento/SalesRule/Model/Quote/Discount.php @@ -85,7 +85,7 @@ class Discount extends \Magento\Quote\Model\Quote\Address\Total\AbstractTotal $this->calculator->initTotals($items, $address); $address->setDiscountDescription([]); - $items = $this->calculator->sortItemsByPriority($items); + $items = $this->calculator->sortItemsByPriority($items, $address); /** @var \Magento\Quote\Model\Quote\Item $item */ foreach ($items as $item) { @@ -201,6 +201,7 @@ class Discount extends \Magento\Quote\Model\Quote\Address\Total\AbstractTotal * @param \Magento\Quote\Model\Quote $quote * @param \Magento\Quote\Model\Quote\Address\Total $total * @return array|null + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total) { diff --git a/app/code/Magento/SalesRule/Model/ResourceModel/Rule/Collection.php b/app/code/Magento/SalesRule/Model/ResourceModel/Rule/Collection.php index 2eb253f0aa77343146d6271e402e51ecc771bbb6..84c629b7846c6a6c9aa2391543bf73afe036b5a6 100644 --- a/app/code/Magento/SalesRule/Model/ResourceModel/Rule/Collection.php +++ b/app/code/Magento/SalesRule/Model/ResourceModel/Rule/Collection.php @@ -8,6 +8,8 @@ namespace Magento\SalesRule\Model\ResourceModel\Rule; +use Magento\Quote\Model\Quote\Address; + /** * Sales Rules resource collection model * @@ -80,11 +82,18 @@ class Collection extends \Magento\Rule\Model\ResourceModel\Rule\Collection\Abstr * @param int $customerGroupId * @param string $couponCode * @param string|null $now + * @param Address $address allow extensions to further filter out rules based on quote address * @use $this->addWebsiteGroupDateFilter() + * @SuppressWarnings(PHPMD.UnusedFormalParameter) * @return $this */ - public function setValidationFilter($websiteId, $customerGroupId, $couponCode = '', $now = null) - { + public function setValidationFilter( + $websiteId, + $customerGroupId, + $couponCode = '', + $now = null, + Address $address = null + ) { if (!$this->getFlag('validation_filter')) { /* We need to overwrite joinLeft if coupon is applied */ $this->getSelect()->reset(); diff --git a/app/code/Magento/SalesRule/Model/Validator.php b/app/code/Magento/SalesRule/Model/Validator.php index f69e85931f4596f91cc7155257d5c4f55b70d929..9309ac0996ae6d4416de1398c9a96813eb07d14a 100644 --- a/app/code/Magento/SalesRule/Model/Validator.php +++ b/app/code/Magento/SalesRule/Model/Validator.php @@ -92,6 +92,13 @@ class Validator extends \Magento\Framework\Model\AbstractModel */ protected $messageManager; + /** + * Counter is used for assigning temporary id to quote address + * + * @var int + */ + protected $counter = 0; + /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry @@ -145,29 +152,56 @@ class Validator extends \Magento\Framework\Model\AbstractModel { $this->setWebsiteId($websiteId)->setCustomerGroupId($customerGroupId)->setCouponCode($couponCode); - $key = $websiteId . '_' . $customerGroupId . '_' . $couponCode; + return $this; + } + + /** + * Get rules collection for current object state + * + * @param Address|null $address + * @return \Magento\SalesRule\Model\ResourceModel\Rule\Collection + */ + protected function _getRules(Address $address = null) + { + $addressId = $this->getAddressId($address); + $key = $this->getWebsiteId() . '_' + . $this->getCustomerGroupId() . '_' + . $this->getCouponCode() . '_' + . $addressId; if (!isset($this->_rules[$key])) { $this->_rules[$key] = $this->_collectionFactory->create() ->setValidationFilter( - $websiteId, - $customerGroupId, - $couponCode + $this->getWebsiteId(), + $this->getCustomerGroupId(), + $this->getCouponCode(), + null, + $address ) ->addFieldToFilter('is_active', 1) ->load(); } - return $this; + return $this->_rules[$key]; } /** - * Get rules collection for current object state - * - * @return \Magento\SalesRule\Model\ResourceModel\Rule\Collection + * @param Address $address + * @return string */ - protected function _getRules() + protected function getAddressId(Address $address) { - $key = $this->getWebsiteId() . '_' . $this->getCustomerGroupId() . '_' . $this->getCouponCode(); - return $this->_rules[$key]; + if ($address == null) { + return ''; + } + if (!$address->hasData('address_sales_rule_id')) { + if ($address->hasData('address_id')) { + $address->setData('address_sales_rule_id', $address->getData('address_id')); + } else { + $type = $address->getAddressType(); + $tempId = $type . $this->counter++; + $address->setData('address_sales_rule_id', $tempId); + } + } + return $address->getData('address_sales_rule_id'); } /** @@ -191,7 +225,7 @@ class Validator extends \Magento\Framework\Model\AbstractModel public function canApplyRules(AbstractItem $item) { $address = $item->getAddress(); - foreach ($this->_getRules() as $rule) { + foreach ($this->_getRules($address) as $rule) { if (!$this->validatorUtility->canProcessRule($rule, $address) || !$rule->getActions()->validate($item)) { return false; } @@ -237,7 +271,7 @@ class Validator extends \Magento\Framework\Model\AbstractModel $appliedRuleIds = $this->rulesApplier->applyRules( $item, - $this->_getRules(), + $this->_getRules($item->getAddress()), $this->_skipActionsValidation, $this->getCouponCode() ); @@ -264,7 +298,7 @@ class Validator extends \Magento\Framework\Model\AbstractModel } $quote = $address->getQuote(); $appliedRuleIds = []; - foreach ($this->_getRules() as $rule) { + foreach ($this->_getRules($address) as $rule) { /* @var \Magento\SalesRule\Model\Rule $rule */ if (!$rule->getApplyToShipping() || !$this->validatorUtility->canProcessRule($rule, $address)) { continue; @@ -351,7 +385,7 @@ class Validator extends \Magento\Framework\Model\AbstractModel } /** @var \Magento\SalesRule\Model\Rule $rule */ - foreach ($this->_getRules() as $rule) { + foreach ($this->_getRules($address) as $rule) { if (\Magento\SalesRule\Model\Rule::CART_FIXED_ACTION == $rule->getSimpleAction() && $this->validatorUtility->canProcessRule($rule, $address) ) { @@ -463,13 +497,14 @@ class Validator extends \Magento\Framework\Model\AbstractModel * Return items list sorted by possibility to apply prioritized rules * * @param array $items + * @param Address $address * @return array $items */ - public function sortItemsByPriority($items) + public function sortItemsByPriority($items, Address $address = null) { $itemsSorted = []; /** @var $rule \Magento\SalesRule\Model\Rule */ - foreach ($this->_getRules() as $rule) { + foreach ($this->_getRules($address) as $rule) { foreach ($items as $itemKey => $itemValue) { if ($rule->getActions()->validate($itemValue)) { unset($items[$itemKey]); diff --git a/app/code/Magento/SalesRule/Test/Unit/Model/Quote/DiscountTest.php b/app/code/Magento/SalesRule/Test/Unit/Model/Quote/DiscountTest.php index 7c163d51f75f9516f61d9d0842383fd5825f27d0..a4605b786fdb4fb2495f77816148807a041014d3 100644 --- a/app/code/Magento/SalesRule/Test/Unit/Model/Quote/DiscountTest.php +++ b/app/code/Magento/SalesRule/Test/Unit/Model/Quote/DiscountTest.php @@ -116,7 +116,9 @@ class DiscountTest extends \PHPUnit_Framework_TestCase false ); $itemNoDiscount->expects($this->once())->method('getNoDiscount')->willReturn(true); - $this->validatorMock->expects($this->any())->method('sortItemsByPriority')->willReturnArgument(0); + $this->validatorMock->expects($this->once())->method('sortItemsByPriority') + ->with([$itemNoDiscount], $this->addressMock) + ->willReturnArgument(0); $storeMock = $this->getMock('Magento\Store\Model\Store', ['getStore', '__wakeup'], [], '', false); $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($storeMock); $quoteMock = $this->getMock('Magento\Quote\Model\Quote', [], [], '', false); @@ -145,7 +147,9 @@ class DiscountTest extends \PHPUnit_Framework_TestCase $itemWithParentId->expects($this->once())->method('getParentItem')->willReturn(true); $this->validatorMock->expects($this->any())->method('canApplyDiscount')->willReturn(true); - $this->validatorMock->expects($this->any())->method('sortItemsByPriority')->willReturnArgument(0); + $this->validatorMock->expects($this->any())->method('sortItemsByPriority') + ->with([$itemWithParentId], $this->addressMock) + ->willReturnArgument(0); $storeMock = $this->getMock('\Magento\Store\Model\Store', ['getStore', '__wakeup'], [], '', false); $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($storeMock); @@ -197,7 +201,9 @@ class DiscountTest extends \PHPUnit_Framework_TestCase } $this->validatorMock->expects($this->any())->method('canApplyDiscount')->willReturn(true); - $this->validatorMock->expects($this->any())->method('sortItemsByPriority')->willReturnArgument(0); + $this->validatorMock->expects($this->once())->method('sortItemsByPriority') + ->with([$itemWithChildren], $this->addressMock) + ->willReturnArgument(0); $this->validatorMock->expects($this->any())->method('canApplyRules')->willReturn(true); $storeMock = $this->getMockBuilder('Magento\Store\Model\Store') @@ -296,7 +302,9 @@ class DiscountTest extends \PHPUnit_Framework_TestCase $itemWithChildren->expects($this->once())->method('getHasChildren')->willReturn(false); $this->validatorMock->expects($this->any())->method('canApplyDiscount')->willReturn(true); - $this->validatorMock->expects($this->any())->method('sortItemsByPriority')->willReturnArgument(0); + $this->validatorMock->expects($this->once())->method('sortItemsByPriority') + ->with([$itemWithChildren], $this->addressMock) + ->willReturnArgument(0); $storeMock = $this->getMockBuilder('Magento\Store\Model\Store') ->disableOriginalConstructor() diff --git a/app/code/Magento/SalesRule/Test/Unit/Model/ValidatorTest.php b/app/code/Magento/SalesRule/Test/Unit/Model/ValidatorTest.php index 8959ca08e6a508676bd1c9bae6a641822063de5d..97585ebfc7dc030f200d0a4d51c6e63cc6079b31 100644 --- a/app/code/Magento/SalesRule/Test/Unit/Model/ValidatorTest.php +++ b/app/code/Magento/SalesRule/Test/Unit/Model/ValidatorTest.php @@ -26,6 +26,11 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase */ protected $item; + /** + * @var \Magento\Quote\Model\Quote\Address|\PHPUnit_Framework_MockObject_MockObject + */ + protected $addressMock; + /** * @var \Magento\SalesRule\Model\RulesApplier|\PHPUnit_Framework_MockObject_MockObject */ @@ -67,8 +72,23 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase false ); + $this->addressMock = $this->getMockBuilder('\Magento\Quote\Model\Quote\Address') + ->disableOriginalConstructor() + ->setMethods( + [ + 'getShippingAmountForDiscount', + 'getQuote', + 'getCustomAttributesCodes', + 'setCartFixedRules' + ] + ) + ->getMock(); + /** @var \Magento\Quote\Model\Quote\Item\AbstractItem|\PHPUnit_Framework_MockObject_MockObject $item */ - $this->item = $this->getMock('Magento\Quote\Model\Quote\Item', ['__wakeup'], [], '', false); + $this->item = $this->getMock('Magento\Quote\Model\Quote\Item', ['__wakeup', 'getAddress'], [], '', false); + $this->item->expects($this->any()) + ->method('getAddress') + ->willReturn($this->addressMock); $context = $this->getMock('Magento\Framework\Model\Context', [], [], '', false); $registry = $this->getMock('Magento\Framework\Registry', [], [], '', false); @@ -98,12 +118,14 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase $this->model->setWebsiteId(1); $this->model->setCustomerGroupId(2); $this->model->setCouponCode('code'); - $this->ruleCollection->expects($this->at(0)) + $this->ruleCollection->expects($this->any()) ->method('setValidationFilter') ->with( $this->model->getWebsiteId(), $this->model->getCustomerGroupId(), - $this->model->getCouponCode() + $this->model->getCouponCode(), + null, + $this->addressMock ) ->willReturnSelf(); } @@ -121,7 +143,7 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase '', false ); - $itemDownloadable->expects($this->any())->method('getAddress')->will($this->returnValue(new \stdClass())); + $itemDownloadable->expects($this->any())->method('getAddress')->will($this->returnValue($this->addressMock)); $itemSimple = $this->getMock( 'Magento\Quote\Model\Quote\Item', @@ -130,7 +152,7 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase '', false ); - $itemSimple->expects($this->any())->method('getAddress')->will($this->returnValue(new \stdClass())); + $itemSimple->expects($this->any())->method('getAddress')->will($this->returnValue($this->addressMock)); /** @var $quote \Magento\Quote\Model\Quote */ $quote = $this->getMock( @@ -312,7 +334,6 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase public function testInitTotalsCanApplyDiscount() { - $address = $this->getMock('Magento\Quote\Model\Quote\Address', [], [], '', false); $rule = $this->getMock( 'Magento\SalesRule\Model\Rule', ['getSimpleAction', 'getActions', 'getId'], @@ -367,7 +388,7 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase $this->model->getCustomerGroupId(), $this->model->getCouponCode() ); - $this->model->initTotals($items, $address); + $this->model->initTotals($items, $this->addressMock); $this->assertArrayHasKey('items_price', $this->model->getRuleItemTotalsInfo($rule->getId())); $this->assertArrayHasKey('base_items_price', $this->model->getRuleItemTotalsInfo($rule->getId())); $this->assertArrayHasKey('items_count', $this->model->getRuleItemTotalsInfo($rule->getId())); @@ -393,11 +414,11 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase */ protected function prepareRuleCollectionMock($ruleCollection) { - $this->ruleCollection->expects($this->once()) + $this->ruleCollection->expects($this->any()) ->method('addFieldToFilter') ->with('is_active', 1) ->will($this->returnSelf()); - $this->ruleCollection->expects($this->once()) + $this->ruleCollection->expects($this->any()) ->method('load') ->will($this->returnSelf()); @@ -406,7 +427,7 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); - $ruleCollectionFactoryMock->expects($this->once()) + $ruleCollectionFactoryMock->expects($this->any()) ->method('create') ->will($this->returnValue($ruleCollection)); return $ruleCollectionFactoryMock; @@ -425,7 +446,7 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase ); $this->assertInstanceOf( 'Magento\SalesRule\Model\Validator', - $this->model->processShippingAmount($this->getAddressMock()) + $this->model->processShippingAmount($this->setupAddressMock()) ); } @@ -446,7 +467,7 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase ); $this->assertInstanceOf( 'Magento\SalesRule\Model\Validator', - $this->model->processShippingAmount($this->getAddressMock()) + $this->model->processShippingAmount($this->setupAddressMock()) ); } @@ -488,7 +509,7 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase ); $this->assertInstanceOf( 'Magento\SalesRule\Model\Validator', - $this->model->processShippingAmount($this->getAddressMock(5)) + $this->model->processShippingAmount($this->setupAddressMock(5)) ); } @@ -507,7 +528,7 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase * @param null|int $shippingAmount * @return \PHPUnit_Framework_MockObject_MockObject */ - protected function getAddressMock($shippingAmount = null) + protected function setupAddressMock($shippingAmount = null) { $storeMock = $this->getMockBuilder('Magento\Store\Model\Store') ->disableOriginalConstructor() @@ -524,20 +545,16 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase ->method('setAppliedRuleIds') ->willReturnSelf(); - $addressMock = $this->getMockBuilder('Magento\Quote\Model\Quote\Address') - ->disableOriginalConstructor() - ->setMethods(['getShippingAmountForDiscount', 'getQuote', 'getCustomAttributesCodes']) - ->getMock(); - $addressMock->expects($this->any()) + $this->addressMock->expects($this->any()) ->method('getShippingAmountForDiscount') ->willReturn($shippingAmount); - $addressMock->expects($this->any()) + $this->addressMock->expects($this->any()) ->method('getQuote') ->willReturn($quoteMock); - $addressMock->expects($this->any()) + $this->addressMock->expects($this->any()) ->method('getCustomAttributesCodes') ->willReturn([]); - return $addressMock; + return $this->addressMock; } public function testReset() diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.xml b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.xml index 8b139628a11b7daaa1d720bb074c152bc6d6b153..5eba30f7f0837a7a885084a3a0009a3131b4d59d 100644 --- a/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.xml +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.xml @@ -349,5 +349,29 @@ <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleForm" /> <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleConditionIsApplied" /> </variation> + <variation name="CreateSalesRuleEntityTestVariation15"> + <data name="salesRule/data/name" xsi:type="string">Cart Price Rule15 %isolation%</data> + <data name="salesRule/data/description" xsi:type="string">Cart Price Rule Description %isolation%</data> + <data name="salesRule/data/is_active" xsi:type="string">Active</data> + <data name="salesRule/data/website_ids/0" xsi:type="string">Main Website</data> + <data name="salesRule/data/customer_group_ids/0" xsi:type="string">NOT LOGGED IN</data> + <data name="salesRule/data/coupon_type" xsi:type="string">No Coupon</data> + <data name="conditionEntity" xsi:type="string">category</data> + <data name="salesRule/data/conditions_serialized" xsi:type="string">{Product attribute combination:[Category|is not|%category_id%]}</data> + <data name="salesRule/data/simple_action" xsi:type="string">Percent of product price discount</data> + <data name="salesRule/data/discount_amount" xsi:type="string">50</data> + <data name="salesRule/data/apply_to_shipping" xsi:type="string">No</data> + <data name="salesRule/data/simple_free_shipping" xsi:type="string">No</data> + <data name="salesRule/data/store_labels/0" xsi:type="string">Product attribute combination - Category is not </data> + <data name="productForSalesRule1/dataset" xsi:type="string">simple_for_salesrule_1</data> + <data name="productForSalesRule2/dataset" xsi:type="string">simple_for_salesrule_2</data> + <data name="productQuantity/productForSalesRule1" xsi:type="string">1</data> + <data name="productQuantity/productForSalesRule2" xsi:type="string">1</data> + <data name="cartPrice/sub_total" xsi:type="string">150.00</data> + <data name="cartPrice/grand_total" xsi:type="string">85.00</data> + <data name="cartPrice/discount" xsi:type="string">75.00</data> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleSuccessSaveMessage" /> + <constraint name="Magento\SalesRule\Test\Constraint\AssertCartPriceRuleForm" /> + </variation> </testCase> </config> diff --git a/dev/tests/functional/tests/app/Magento/Ui/Test/Block/Adminhtml/AbstractFormContainers.php b/dev/tests/functional/tests/app/Magento/Ui/Test/Block/Adminhtml/AbstractFormContainers.php index 05995e1850a91463c471f28e9dc780ed98e03d64..6e6f084cf75a04685ac046c4a1ba8571c991be34 100644 --- a/dev/tests/functional/tests/app/Magento/Ui/Test/Block/Adminhtml/AbstractFormContainers.php +++ b/dev/tests/functional/tests/app/Magento/Ui/Test/Block/Adminhtml/AbstractFormContainers.php @@ -90,6 +90,7 @@ abstract class AbstractFormContainers extends Form if (null === $fixture) { foreach ($this->containers as $containerName => $containerData) { + $this->openContainer($containerName); $containerData = $this->getContainer($containerName)->getFieldsData(); $data = array_merge($data, $containerData); } diff --git a/dev/tests/integration/testsuite/Magento/Catalog/_files/categories_no_products.php b/dev/tests/integration/testsuite/Magento/Catalog/_files/categories_no_products.php new file mode 100644 index 0000000000000000000000000000000000000000..0600a966d0ddaf4265034b8d9749e850068d64f0 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Catalog/_files/categories_no_products.php @@ -0,0 +1,142 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + +/** + * After installation system has two categories: root one with ID:1 and Default category with ID:2 + */ +/** @var $category \Magento\Catalog\Model\Category */ +$category = $objectManager->create('Magento\Catalog\Model\Category'); +$category->isObjectNew(true); +$category->setId(3) + ->setName('Category 1') + ->setParentId(2) + ->setPath('1/2/3') + ->setLevel(2) + ->setAvailableSortBy('name') + ->setDefaultSortBy('name') + ->setIsActive(true) + ->setPosition(1) + ->save(); + +$category = $objectManager->create('Magento\Catalog\Model\Category'); +$category->isObjectNew(true); +$category->setId(4) + ->setName('Category 1.1') + ->setParentId(3) + ->setPath('1/2/3/4') + ->setLevel(3) + ->setAvailableSortBy('name') + ->setDefaultSortBy('name') + ->setIsActive(true) + ->setIsAnchor(true) + ->setPosition(1) + ->save(); + +$category = $objectManager->create('Magento\Catalog\Model\Category'); +$category->isObjectNew(true); +$category->setId(5) + ->setName('Category 1.1.1') + ->setParentId(4) + ->setPath('1/2/3/4/5') + ->setLevel(4) + ->setAvailableSortBy('name') + ->setDefaultSortBy('name') + ->setIsActive(true) + ->setPosition(1) + ->setCustomUseParentSettings(0) + ->setCustomDesign('Magento/blank') + ->save(); + +$category = $objectManager->create('Magento\Catalog\Model\Category'); +$category->isObjectNew(true); +$category->setId(6) + ->setName('Category 2') + ->setParentId(2) + ->setPath('1/2/6') + ->setLevel(2) + ->setAvailableSortBy('name') + ->setDefaultSortBy('name') + ->setIsActive(true) + ->setPosition(2) + ->save(); + +$category = $objectManager->create('Magento\Catalog\Model\Category'); +$category->isObjectNew(true); +$category->setId(7) + ->setName('Movable') + ->setParentId(2) + ->setPath('1/2/7') + ->setLevel(2) + ->setAvailableSortBy('name') + ->setDefaultSortBy('name') + ->setIsActive(true) + ->setPosition(3) + ->save(); + +$category = $objectManager->create('Magento\Catalog\Model\Category'); +$category->isObjectNew(true); +$category->setId(8) + ->setName('Inactive') + ->setParentId(2) + ->setPath('1/2/8') + ->setAvailableSortBy('name') + ->setDefaultSortBy('name') + ->setIsActive(false) + ->setPosition(4) + ->save(); + +$category = $objectManager->create('Magento\Catalog\Model\Category'); +$category->isObjectNew(true); +$category->setId(9) + ->setName('Movable Position 1') + ->setParentId(2) + ->setPath('1/2/9') + ->setLevel(2) + ->setAvailableSortBy('name') + ->setDefaultSortBy('name') + ->setIsActive(true) + ->setPosition(5) + ->save(); + +$category = $objectManager->create('Magento\Catalog\Model\Category'); +$category->isObjectNew(true); +$category->setId(10) + ->setName('Movable Position 2') + ->setParentId(2) + ->setPath('1/2/10') + ->setLevel(2) + ->setAvailableSortBy('name') + ->setDefaultSortBy('name') + ->setIsActive(true) + ->setPosition(6) + ->save(); + +$category = $objectManager->create('Magento\Catalog\Model\Category'); +$category->isObjectNew(true); +$category->setId(11) + ->setName('Movable Position 3') + ->setParentId(2) + ->setPath('1/2/11') + ->setLevel(2) + ->setAvailableSortBy('name') + ->setDefaultSortBy('name') + ->setIsActive(true) + ->setPosition(7) + ->save(); + +$category = $objectManager->create('Magento\Catalog\Model\Category'); +$category->isObjectNew(true); +$category->setId(12) + ->setName('Category 12') + ->setParentId(2) + ->setPath('1/2/12') + ->setLevel(2) + ->setAvailableSortBy('name') + ->setDefaultSortBy('name') + ->setIsActive(true) + ->setPosition(8) + ->save(); diff --git a/dev/tests/integration/testsuite/Magento/Catalog/_files/categories_no_products_rollback.php b/dev/tests/integration/testsuite/Magento/Catalog/_files/categories_no_products_rollback.php new file mode 100644 index 0000000000000000000000000000000000000000..458e35de74d4692a24d2091d8f6ee61d1d9cd0b5 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Catalog/_files/categories_no_products_rollback.php @@ -0,0 +1,23 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); +/** @var \Magento\Framework\Registry $registry */ +$registry = $objectManager->get('Magento\Framework\Registry'); + +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', true); + +//Remove categories +/** @var Magento\Catalog\Model\ResourceModel\Category\Collection $collection */ +$collection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Category\Collection'); +$collection + ->addAttributeToFilter('level', 2) + ->load() + ->delete(); + +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', false); diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_shipping_method_and_items_categories.php b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_shipping_method_and_items_categories.php new file mode 100644 index 0000000000000000000000000000000000000000..80e76feaac2babbf0720accf99f12a244eb59f7b --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_shipping_method_and_items_categories.php @@ -0,0 +1,93 @@ +<?php +/** + * Quote with simple product, shipping, billing addresses and shipping method fixture + * + * The quote is not saved inside the original fixture. It is later saved inside child fixtures, but along with some + * additional data which may break some tests. + * + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +require __DIR__ . '/../../Catalog/_files/categories_no_products.php'; +require __DIR__ . '/../../Checkout/_files/quote_with_shipping_method.php'; + +$quote->load('test_order_1', 'reserved_order_id'); +$quote->removeAllItems(); +$quote->setReservedOrderId('test_order_item_with_items'); + +/** @var $product \Magento\Catalog\Model\Product */ +$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\Catalog\Model\Product'); +$product->isObjectNew(true); +$product->setTypeId( + \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE +)->setId( + 333 +)->setAttributeSetId( + 4 +)->setStoreId( + 1 +)->setWebsiteIds( + [1] +)->setName( + 'Simple Product Cat Four' +)->setSku( + 'simple_cat_3' +)->setPrice( + 80 +)->setWeight( + 18 +)->setStockData( + ['use_config_manage_stock' => 0] +)->setCategoryIds( + [3] +)->setVisibility( + \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH +)->setStatus( + \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED +)->save(); + +$quote->addProduct($product->load($product->getIdBySku('simple_cat_3')), 1); + +/** @var $product \Magento\Catalog\Model\Product */ +$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\Catalog\Model\Product'); +$product->isObjectNew(true); +$product->setTypeId( + \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE +)->setId( + 444 +)->setAttributeSetId( + 5 +)->setStoreId( + 1 +)->setWebsiteIds( + [1] +)->setName( + 'Simple Product Cat Five' +)->setSku( + 'simple_cat_4' +)->setPrice( + 15 +)->setWeight( + 18 +)->setStockData( + ['use_config_manage_stock' => 0] +)->setCategoryIds( + [4] +)->setVisibility( + \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH +)->setStatus( + \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED +)->save(); + +$quote->addProduct($product->load($product->getIdBySku('simple_cat_4')), 1); + +//save quote with id +$quote->collectTotals()->save(); + +/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ +$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->create('Magento\Quote\Model\QuoteIdMaskFactory') + ->create(); +$quoteIdMask->setQuoteId($quote->getId()); +$quoteIdMask->setDataChanges(true); +$quoteIdMask->save(); diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/Model/ResourceModel/Rule/CollectionTest.php b/dev/tests/integration/testsuite/Magento/SalesRule/Model/ResourceModel/Rule/CollectionTest.php index a1ee14377450667662aac939e6814f03659989c5..ca19ec5eac5a40c25374e00a388a0d21ca3a72cc 100644 --- a/dev/tests/integration/testsuite/Magento/SalesRule/Model/ResourceModel/Rule/CollectionTest.php +++ b/dev/tests/integration/testsuite/Magento/SalesRule/Model/ResourceModel/Rule/CollectionTest.php @@ -8,12 +8,12 @@ namespace Magento\SalesRule\Model\ResourceModel\Rule; /** * @magentoDbIsolation enabled * @magentoAppIsolation enabled - * @magentoDataFixture Magento/SalesRule/_files/rules.php - * @magentoDataFixture Magento/SalesRule/_files/coupons.php */ class CollectionTest extends \PHPUnit_Framework_TestCase { /** + * @magentoDataFixture Magento/SalesRule/_files/rules.php + * @magentoDataFixture Magento/SalesRule/_files/coupons.php * @dataProvider setValidationFilterDataProvider() * @param string $couponCode * @param array $expectedItems @@ -35,6 +35,10 @@ class CollectionTest extends \PHPUnit_Framework_TestCase } } + /** + * data provider for testSetValidationFilter + * @return array + */ public function setValidationFilterDataProvider() { return [ @@ -53,6 +57,115 @@ class CollectionTest extends \PHPUnit_Framework_TestCase /** * @magentoDbIsolation enabled * @magentoAppIsolation enabled + * @magentoDataFixture Magento/Checkout/_files/quote_with_shipping_method_and_items_categories.php + * @magentoDataFixture Magento/SalesRule/_files/rules_group_any_categories.php + */ + public function testSetValidationFilterWithGroup() + { + $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + + /** @var \Magento\SalesRule\Model\Rule $rule */ + $rule = $objectManager->get('Magento\Framework\Registry') + ->registry('_fixture/Magento_SalesRule_Group_Multiple_Categories'); + + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_item_with_items', 'reserved_order_id'); + + //gather only the existing rules that obey the validation filter + /** @var \Magento\SalesRule\Model\ResourceModel\Rule\Collection $ruleCollection */ + $ruleCollection = $objectManager->create( + 'Magento\SalesRule\Model\ResourceModel\Rule\Collection' + ); + + $appliedRulesArray = array_keys( + $ruleCollection->setValidationFilter( + $quote->getStore()->getWebsiteId(), + 0, + '', + null, + $quote->getShippingAddress() + )->getItems() + ); + + $this->assertEquals([$rule->getRuleId()], $appliedRulesArray); + } + + /** + * @magentoDbIsolation enabled + * @magentoAppIsolation enabled + * @magentoDataFixture Magento/Checkout/_files/quote_with_shipping_method_and_items_categories.php + * @magentoDataFixture Magento/SalesRule/_files/rules_group_any_categories.php + */ + public function testSetValidationFilterAnyCategory() + { + $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + + /** @var \Magento\SalesRule\Model\Rule $rule */ + $rule = $objectManager->get('Magento\Framework\Registry') + ->registry('_fixture/Magento_SalesRule_Group_Multiple_Categories'); + + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_item_with_items', 'reserved_order_id'); + + //gather only the existing rules that obey the validation filter + /** @var \Magento\SalesRule\Model\ResourceModel\Rule\Collection $ruleCollection */ + $ruleCollection = $objectManager->create( + 'Magento\SalesRule\Model\ResourceModel\Rule\Collection' + ); + + $appliedRulesArray = array_keys( + $ruleCollection->setValidationFilter( + $quote->getStore()->getWebsiteId(), + 0, + '', + null, + $quote->getShippingAddress() + )->getItems() + ); + $this->assertEquals([$rule->getRuleId()], $appliedRulesArray); + } + + /** + * @magentoDbIsolation enabled + * @magentoAppIsolation enabled + * @magentoDataFixture Magento/Checkout/_files/quote_with_shipping_method_and_items_categories.php + * @magentoDataFixture Magento/SalesRule/_files/rules_group_not_categories_sku_attr.php + * @magentoDataFixture Magento/SalesRule/_files/rules_group_any_categories.php + * @magentoDataFixture Magento/SalesRule/_files/rules_group_any_categories_price_attr_set_any.php + */ + public function testSetValidationFilterOther() + { + $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + + /** @var \Magento\Quote\Model\Quote $quote */ + $quote = $objectManager->create('Magento\Quote\Model\Quote'); + $quote->load('test_order_item_with_items', 'reserved_order_id'); + + //gather only the existing rules that obey the validation filter + /** @var \Magento\SalesRule\Model\ResourceModel\Rule\Collection $ruleCollection */ + $ruleCollection = $objectManager->create( + 'Magento\SalesRule\Model\ResourceModel\Rule\Collection' + ); + + $appliedRulesArray = array_keys( + $ruleCollection->setValidationFilter( + $quote->getStore()->getWebsiteId(), + 0, + '', + null, + $quote->getShippingAddress() + )->getItems() + ); + $this->assertEquals(3, count($appliedRulesArray)); + } + + /** + * @magentoDbIsolation enabled + * @magentoAppIsolation enabled + * @magentoDataFixture Magento/SalesRule/_files/rules.php + * @magentoDataFixture Magento/SalesRule/_files/coupons.php * @magentoDataFixture Magento/SalesRule/_files/rule_specific_date.php * @magentoConfigFixture general/locale/timezone Europe/Kiev */ @@ -70,6 +183,8 @@ class CollectionTest extends \PHPUnit_Framework_TestCase /** * @magentoDbIsolation enabled * @magentoAppIsolation enabled + * @magentoDataFixture Magento/SalesRule/_files/rules.php + * @magentoDataFixture Magento/SalesRule/_files/coupons.php * @magentoDataFixture Magento/SalesRule/_files/rule_specific_date.php * @magentoConfigFixture general/locale/timezone Australia/Sydney */ diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_categories.php b/dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_categories.php new file mode 100644 index 0000000000000000000000000000000000000000..406687583765bc7cbf182d0f22c1519ff77b971b --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_categories.php @@ -0,0 +1,69 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +/** @var \Magento\SalesRule\Model\Rule $rule */ +$salesRule = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\SalesRule\Model\Rule'); +$salesRule->setData( + [ + 'name' => '50% Off on Large Orders', + 'is_active' => 1, + 'customer_group_ids' => [\Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID], + 'coupon_type' => \Magento\SalesRule\Model\Rule::COUPON_TYPE_NO_COUPON, + 'simple_action' => 'by_percent', + 'discount_amount' => 50, + 'stop_rules_processing' => 1, + 'website_ids' => [ + \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( + 'Magento\Store\Model\StoreManagerInterface' + )->getWebsite()->getId() + ] + ] +); + +$salesRule->getConditions()->loadArray([ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Combine', + 'attribute' => null, + 'operator' => null, + 'value' => '1', + 'is_value_processed' => null, + 'aggregator' => 'all', + 'conditions' => + [ + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product\\Found', + 'attribute' => null, + 'operator' => null, + 'value' => '1', + 'is_value_processed' => null, + 'aggregator' => 'all', + 'conditions' => + [ + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'category_ids', + 'operator' => '==', + 'value' => '2', + 'is_value_processed' => false, + ], + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'category_ids', + 'operator' => '==', + 'value' => '3', + 'is_value_processed' => false, + ], + ], + ], + ], +]); + +$salesRule->save(); + +/** @var Magento\Framework\Registry $registry */ +$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\Framework\Registry'); + +$registry->unregister('_fixture/Magento_SalesRule_Multiple_Categories'); +$registry->register('_fixture/Magento_SalesRule_Multiple_Categories', $salesRule); diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_category.php b/dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_category.php new file mode 100644 index 0000000000000000000000000000000000000000..4561db47c84fb91e4f4eddb4e7940d2db70f28de --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_category.php @@ -0,0 +1,62 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +/** @var \Magento\SalesRule\Model\Rule $rule */ +$salesRule = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\SalesRule\Model\Rule'); +$salesRule->setData( + [ + 'name' => '50% Off on Large Orders', + 'is_active' => 1, + 'customer_group_ids' => [\Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID], + 'coupon_type' => \Magento\SalesRule\Model\Rule::COUPON_TYPE_NO_COUPON, + 'simple_action' => 'by_percent', + 'discount_amount' => 50, + 'stop_rules_processing' => 1, + 'website_ids' => [ + \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( + 'Magento\Store\Model\StoreManagerInterface' + )->getWebsite()->getId() + ] + ] +); + +$salesRule->getConditions()->loadArray([ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Combine', + 'attribute' => null, + 'operator' => null, + 'value' => '1', + 'is_value_processed' => null, + 'aggregator' => 'all', + 'conditions' => + [ + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product\\Found', + 'attribute' => null, + 'operator' => null, + 'value' => '1', + 'is_value_processed' => null, + 'aggregator' => 'all', + 'conditions' => + [ + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'category_ids', + 'operator' => '==', + 'value' => '66', + 'is_value_processed' => false, + ], + ], + ], + ], +]); + +$salesRule->save(); + +/** @var Magento\Framework\Registry $registry */ +$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\Framework\Registry'); + +$registry->unregister('_fixture/Magento_SalesRule_Category'); +$registry->register('_fixture/Magento_SalesRule_Category', $salesRule); diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_group_all_categories.php b/dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_group_all_categories.php new file mode 100644 index 0000000000000000000000000000000000000000..220346df9fbbe7c51db9cc73631449ebdfa7c088 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_group_all_categories.php @@ -0,0 +1,95 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +/** @var \Magento\SalesRule\Model\Rule $rule */ +$salesRule = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\SalesRule\Model\Rule'); +$salesRule->setData( + [ + 'name' => '50% Off on Large Orders', + 'is_active' => 1, + 'customer_group_ids' => [\Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID], + 'coupon_type' => \Magento\SalesRule\Model\Rule::COUPON_TYPE_NO_COUPON, + 'simple_action' => 'by_percent', + 'discount_amount' => 50, + 'stop_rules_processing' => 1, + 'website_ids' => [ + \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( + 'Magento\Store\Model\StoreManagerInterface' + )->getWebsite()->getId() + ] + ] +); + +$salesRule->getConditions()->loadArray([ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Combine', + 'attribute' => null, + 'operator' => null, + 'value' => '1', + 'is_value_processed' => null, + 'aggregator' => 'all', + 'conditions' => + [ + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product\\Found', + 'attribute' => null, + 'operator' => null, + 'value' => '1', + 'is_value_processed' => null, + 'aggregator' => 'all', + 'conditions' => + [ + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'category_ids', + 'operator' => '==', + 'value' => '2', + 'is_value_processed' => false, + ], + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'category_ids', + 'operator' => '==', + 'value' => '3', + 'is_value_processed' => false, + ], + ], + ], + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product\\Found', + 'attribute' => null, + 'operator' => null, + 'value' => '1', + 'is_value_processed' => null, + 'aggregator' => 'all', + 'conditions' => + [ + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'category_ids', + 'operator' => '==', + 'value' => '3', + 'is_value_processed' => false, + ], + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'category_ids', + 'operator' => '==', + 'value' => '4', + 'is_value_processed' => false, + ], + ], + ], + + ], +]); + +$salesRule->save(); + +/** @var Magento\Framework\Registry $registry */ +$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\Framework\Registry'); + +$registry->unregister('_fixture/Magento_SalesRule_Group_Multiple_Categories'); +$registry->register('_fixture/Magento_SalesRule_Group_Multiple_Categories', $salesRule); diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_group_all_categories_price_attr_set.php b/dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_group_all_categories_price_attr_set.php new file mode 100644 index 0000000000000000000000000000000000000000..f2ee6083377ae457d2f9ae9ab72de48b19938efe --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_group_all_categories_price_attr_set.php @@ -0,0 +1,95 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +/** @var \Magento\SalesRule\Model\Rule $rule */ +$salesRule = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\SalesRule\Model\Rule'); +$salesRule->setData( + [ + 'name' => '50% Off on Large Orders', + 'is_active' => 1, + 'customer_group_ids' => [\Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID], + 'coupon_type' => \Magento\SalesRule\Model\Rule::COUPON_TYPE_NO_COUPON, + 'simple_action' => 'by_percent', + 'discount_amount' => 50, + 'stop_rules_processing' => 1, + 'website_ids' => [ + \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( + 'Magento\Store\Model\StoreManagerInterface' + )->getWebsite()->getId() + ] + ] +); + +$salesRule->getConditions()->loadArray([ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Combine', + 'attribute' => null, + 'operator' => null, + 'value' => '1', + 'is_value_processed' => null, + 'aggregator' => 'all', + 'conditions' => + [ + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product\\Found', + 'attribute' => null, + 'operator' => null, + 'value' => '1', + 'is_value_processed' => null, + 'aggregator' => 'all', + 'conditions' => + [ + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'category_ids', + 'operator' => '==', + 'value' => '2', + 'is_value_processed' => false, + ], + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'attribute_set_id', + 'operator' => '==', + 'value' => '4', + 'is_value_processed' => false, + ], + ], + ], + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product\\Found', + 'attribute' => null, + 'operator' => null, + 'value' => '1', + 'is_value_processed' => null, + 'aggregator' => 'all', + 'conditions' => + [ + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'quote_item_price', + 'operator' => '==', + 'value' => '80', + 'is_value_processed' => false, + ], + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'category_ids', + 'operator' => '==', + 'value' => '3', + 'is_value_processed' => false, + ], + ], + ], + + ], +]); + +$salesRule->save(); + +/** @var Magento\Framework\Registry $registry */ +$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\Framework\Registry'); + +$registry->unregister('_fixture/Magento_SalesRule_Group_Multiple_Categories'); +$registry->register('_fixture/Magento_SalesRule_Group_Multiple_Categories', $salesRule); diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_group_any_categories.php b/dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_group_any_categories.php new file mode 100644 index 0000000000000000000000000000000000000000..5db23449f237ae077b65d3034450fe1afbac7ec4 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_group_any_categories.php @@ -0,0 +1,95 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +/** @var \Magento\SalesRule\Model\Rule $rule */ +$salesRule = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\SalesRule\Model\Rule'); +$salesRule->setData( + [ + 'name' => '50% Off on Large Orders', + 'is_active' => 1, + 'customer_group_ids' => [\Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID], + 'coupon_type' => \Magento\SalesRule\Model\Rule::COUPON_TYPE_NO_COUPON, + 'simple_action' => 'by_percent', + 'discount_amount' => 50, + 'stop_rules_processing' => 1, + 'website_ids' => [ + \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( + 'Magento\Store\Model\StoreManagerInterface' + )->getWebsite()->getId() + ] + ] +); + +$salesRule->getConditions()->loadArray([ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Combine', + 'attribute' => null, + 'operator' => null, + 'value' => '1', + 'is_value_processed' => null, + 'aggregator' => 'all', + 'conditions' => + [ + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product\\Found', + 'attribute' => null, + 'operator' => null, + 'value' => '1', + 'is_value_processed' => null, + 'aggregator' => 'any', + 'conditions' => + [ + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'category_ids', + 'operator' => '==', + 'value' => '2', + 'is_value_processed' => false, + ], + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'category_ids', + 'operator' => '==', + 'value' => '3', + 'is_value_processed' => false, + ], + ], + ], + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product\\Found', + 'attribute' => null, + 'operator' => null, + 'value' => '1', + 'is_value_processed' => null, + 'aggregator' => 'all', + 'conditions' => + [ + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'category_ids', + 'operator' => '==', + 'value' => '3', + 'is_value_processed' => false, + ], + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'category_ids', + 'operator' => '==', + 'value' => '4', + 'is_value_processed' => false, + ], + ], + ], + + ], +]); + +$salesRule->save(); + +/** @var Magento\Framework\Registry $registry */ +$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\Framework\Registry'); + +$registry->unregister('_fixture/Magento_SalesRule_Group_Multiple_Categories'); +$registry->register('_fixture/Magento_SalesRule_Group_Multiple_Categories', $salesRule); diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_group_any_categories_price_address.php b/dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_group_any_categories_price_address.php new file mode 100644 index 0000000000000000000000000000000000000000..f284063f41d83385ae1750853be0aa0af50b455e --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_group_any_categories_price_address.php @@ -0,0 +1,98 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +/** @var \Magento\SalesRule\Model\Rule $rule */ +$salesRule = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\SalesRule\Model\Rule'); +$salesRule->setData( + [ + 'name' => '50% Off on Large Orders', + 'is_active' => 1, + 'customer_group_ids' => [\Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID], + 'coupon_type' => \Magento\SalesRule\Model\Rule::COUPON_TYPE_NO_COUPON, + 'simple_action' => 'by_percent', + 'discount_amount' => 50, + 'stop_rules_processing' => 1, + 'website_ids' => [ + \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( + 'Magento\Store\Model\StoreManagerInterface' + )->getWebsite()->getId() + ] + ] +); + +$salesRule->getConditions()->loadArray([ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Combine', + 'attribute' => null, + 'operator' => null, + 'value' => '1', + 'is_value_processed' => null, + 'aggregator' => 'any', + 'conditions' => + [ + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product\\Found', + 'attribute' => null, + 'operator' => null, + 'value' => '1', + 'is_value_processed' => null, + 'aggregator' => 'all', + 'conditions' => + [ + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'category_ids', + 'operator' => '==', + 'value' => '2', + 'is_value_processed' => false, + ], + ], + ], + [ + 'type' => 'Magento\SalesRule\Model\Rule\Condition\Address', + 'attribute' => 'payment_method', + 'operator' => '==', + 'value' => 'braintree_paypal' + ], + [ + 'type' => 'Magento\SalesRule\Model\Rule\Condition\Address', + 'attribute' => 'shipping_method', + 'operator' => '==', + 'value' => 'fedex_FEDEX_2_DAY' + ], + [ + 'type' => 'Magento\SalesRule\Model\Rule\Condition\Address', + 'attribute' => 'postcode', + 'operator' => '==', + 'value' => '78000' + ], + [ + 'type' => 'Magento\SalesRule\Model\Rule\Condition\Address', + 'attribute' => 'region', + 'operator' => '==', + 'value' => 'HD' + ], + [ + 'type' => 'Magento\SalesRule\Model\Rule\Condition\Address', + 'attribute' => 'region_id', + 'operator' => '==', + 'value' => '56' + ], + [ + 'type' => 'Magento\SalesRule\Model\Rule\Condition\Address', + 'attribute' => 'country_id', + 'operator' => '==', + 'value' => 'US' + ] + ], +]); + +$salesRule->save(); + +/** @var Magento\Framework\Registry $registry */ +$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\Framework\Registry'); + +$registry->unregister('_fixture/Magento_SalesRule_Group_Multiple_Categories'); +$registry->register('_fixture/Magento_SalesRule_Group_Multiple_Categories', $salesRule); diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_group_any_categories_price_attr_set.php b/dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_group_any_categories_price_attr_set.php new file mode 100644 index 0000000000000000000000000000000000000000..39ec18538e83a6c949b3839a4bb2fc661477e372 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_group_any_categories_price_attr_set.php @@ -0,0 +1,95 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +/** @var \Magento\SalesRule\Model\Rule $rule */ +$salesRule = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\SalesRule\Model\Rule'); +$salesRule->setData( + [ + 'name' => '50% Off on Large Orders', + 'is_active' => 1, + 'customer_group_ids' => [\Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID], + 'coupon_type' => \Magento\SalesRule\Model\Rule::COUPON_TYPE_NO_COUPON, + 'simple_action' => 'by_percent', + 'discount_amount' => 50, + 'stop_rules_processing' => 1, + 'website_ids' => [ + \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( + 'Magento\Store\Model\StoreManagerInterface' + )->getWebsite()->getId() + ] + ] +); + +$salesRule->getConditions()->loadArray([ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Combine', + 'attribute' => null, + 'operator' => null, + 'value' => '1', + 'is_value_processed' => null, + 'aggregator' => 'any', + 'conditions' => + [ + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product\\Found', + 'attribute' => null, + 'operator' => null, + 'value' => '1', + 'is_value_processed' => null, + 'aggregator' => 'all', + 'conditions' => + [ + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'category_ids', + 'operator' => '==', + 'value' => '2', + 'is_value_processed' => false, + ], + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'attribute_set_id', + 'operator' => '==', + 'value' => '4', + 'is_value_processed' => false, + ], + ], + ], + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product\\Found', + 'attribute' => null, + 'operator' => null, + 'value' => '1', + 'is_value_processed' => null, + 'aggregator' => 'all', + 'conditions' => + [ + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'quote_item_price', + 'operator' => '==', + 'value' => '80', + 'is_value_processed' => false, + ], + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'category_ids', + 'operator' => '==', + 'value' => '3', + 'is_value_processed' => false, + ], + ], + ], + + ], +]); + +$salesRule->save(); + +/** @var Magento\Framework\Registry $registry */ +$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\Framework\Registry'); + +$registry->unregister('_fixture/Magento_SalesRule_Group_Multiple_Categories'); +$registry->register('_fixture/Magento_SalesRule_Group_Multiple_Categories', $salesRule); diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_group_any_categories_price_attr_set_any.php b/dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_group_any_categories_price_attr_set_any.php new file mode 100644 index 0000000000000000000000000000000000000000..7c1fca7bf9625df4c30db325cabd04e3bb6847b4 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_group_any_categories_price_attr_set_any.php @@ -0,0 +1,102 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +/** @var \Magento\SalesRule\Model\Rule $rule */ +$salesRule = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\SalesRule\Model\Rule'); +$salesRule->setData( + [ + 'name' => '50% Off on Large Orders', + 'is_active' => 1, + 'customer_group_ids' => [\Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID], + 'coupon_type' => \Magento\SalesRule\Model\Rule::COUPON_TYPE_NO_COUPON, + 'simple_action' => 'by_percent', + 'discount_amount' => 50, + 'stop_rules_processing' => 1, + 'website_ids' => [ + \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( + 'Magento\Store\Model\StoreManagerInterface' + )->getWebsite()->getId() + ] + ] +); + +$salesRule->getConditions()->loadArray([ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Combine', + 'attribute' => null, + 'operator' => null, + 'value' => '1', + 'is_value_processed' => null, + 'aggregator' => 'any', + 'conditions' => + [ + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product\\Found', + 'attribute' => null, + 'operator' => null, + 'value' => '1', + 'is_value_processed' => null, + 'aggregator' => 'any', + 'conditions' => + [ + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'category_ids', + 'operator' => '==', + 'value' => '2', + 'is_value_processed' => false, + ], + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'sku', + 'operator' => '==', + 'value' => '80', + 'is_value_processed' => false, + ], + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'attribute_set_id', + 'operator' => '==', + 'value' => '4', + 'is_value_processed' => false, + ], + ], + ], + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product\\Found', + 'attribute' => null, + 'operator' => null, + 'value' => '1', + 'is_value_processed' => null, + 'aggregator' => 'all', + 'conditions' => + [ + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'quote_item_price', + 'operator' => '==', + 'value' => '80', + 'is_value_processed' => false, + ], + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'category_ids', + 'operator' => '==', + 'value' => '3', + 'is_value_processed' => false, + ], + ], + ], + + ], +]); + +$salesRule->save(); + +/** @var Magento\Framework\Registry $registry */ +$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\Framework\Registry'); + +$registry->unregister('_fixture/Magento_SalesRule_Group_Multiple_Categories'); +$registry->register('_fixture/Magento_SalesRule_Group_Multiple_Categories', $salesRule); diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_group_categories_price_sku_attr_set_any.php b/dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_group_categories_price_sku_attr_set_any.php new file mode 100644 index 0000000000000000000000000000000000000000..8e0bbe9923941350819a378966d7d0e31a253915 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_group_categories_price_sku_attr_set_any.php @@ -0,0 +1,95 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +/** @var \Magento\SalesRule\Model\Rule $rule */ +$salesRule = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\SalesRule\Model\Rule'); +$salesRule->setData( + [ + 'name' => '50% Off on Large Orders', + 'is_active' => 1, + 'customer_group_ids' => [\Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID], + 'coupon_type' => \Magento\SalesRule\Model\Rule::COUPON_TYPE_NO_COUPON, + 'simple_action' => 'by_percent', + 'discount_amount' => 50, + 'stop_rules_processing' => 1, + 'website_ids' => [ + \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( + 'Magento\Store\Model\StoreManagerInterface' + )->getWebsite()->getId() + ] + ] +); + +$salesRule->getConditions()->loadArray([ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Combine', + 'attribute' => null, + 'operator' => null, + 'value' => '1', + 'is_value_processed' => null, + 'aggregator' => 'any', + 'conditions' => + [ + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product\\Found', + 'attribute' => null, + 'operator' => null, + 'value' => '1', + 'is_value_processed' => null, + 'aggregator' => 'any', + 'conditions' => + [ + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'category_ids', + 'operator' => '==', + 'value' => '2', + 'is_value_processed' => false, + ], + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'attribute_set_id', + 'operator' => '==', + 'value' => '4', + 'is_value_processed' => false, + ], + ], + ], + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product\\Found', + 'attribute' => null, + 'operator' => null, + 'value' => '1', + 'is_value_processed' => null, + 'aggregator' => 'any', + 'conditions' => + [ + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'quote_item_price', + 'operator' => '==', + 'value' => '80', + 'is_value_processed' => false, + ], + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'category_ids', + 'operator' => '==', + 'value' => '3', + 'is_value_processed' => false, + ], + ], + ], + + ], +]); + +$salesRule->save(); + +/** @var Magento\Framework\Registry $registry */ +$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\Framework\Registry'); + +$registry->unregister('_fixture/Magento_SalesRule_Group_Multiple_Categories'); +$registry->register('_fixture/Magento_SalesRule_Group_Multiple_Categories', $salesRule); diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_group_not_categories_sku_attr.php b/dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_group_not_categories_sku_attr.php new file mode 100644 index 0000000000000000000000000000000000000000..04e87b44787d37db2f301f0b673adc3723925792 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_group_not_categories_sku_attr.php @@ -0,0 +1,69 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +/** @var \Magento\SalesRule\Model\Rule $rule */ +$salesRule = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\SalesRule\Model\Rule'); +$salesRule->setData( + [ + 'name' => '50% Off on Large Orders', + 'is_active' => 1, + 'customer_group_ids' => [\Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID], + 'coupon_type' => \Magento\SalesRule\Model\Rule::COUPON_TYPE_NO_COUPON, + 'simple_action' => 'by_percent', + 'discount_amount' => 50, + 'stop_rules_processing' => 1, + 'website_ids' => [ + \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( + 'Magento\Store\Model\StoreManagerInterface' + )->getWebsite()->getId() + ] + ] +); + +$salesRule->getConditions()->loadArray([ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Combine', + 'attribute' => null, + 'operator' => null, + 'value' => '1', + 'is_value_processed' => null, + 'aggregator' => 'all', + 'conditions' => + [ + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product\\Found', + 'attribute' => null, + 'operator' => null, + 'value' => '0', + 'is_value_processed' => null, + 'aggregator' => 'all', + 'conditions' => + [ + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'category_ids', + 'operator' => '==', + 'value' => '2', + 'is_value_processed' => false, + ], + [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'attribute_set_id', + 'operator' => '==', + 'value' => '4', + 'is_value_processed' => false, + ], + ], + ], + ], +]); + +$salesRule->save(); + +/** @var Magento\Framework\Registry $registry */ +$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\Framework\Registry'); + +$registry->unregister('_fixture/Magento_SalesRule_Group_Multiple_Categories'); +$registry->register('_fixture/Magento_SalesRule_Group_Multiple_Categories', $salesRule); diff --git a/lib/internal/Magento/Framework/Indexer/AbstractProcessor.php b/lib/internal/Magento/Framework/Indexer/AbstractProcessor.php index f9bfebb770026cd1ea8e6b47f2820ef2a260b763..dfeb0e4b31f8dcffb82ed76c60d61cf3b7771873 100644 --- a/lib/internal/Magento/Framework/Indexer/AbstractProcessor.php +++ b/lib/internal/Magento/Framework/Indexer/AbstractProcessor.php @@ -45,7 +45,7 @@ abstract class AbstractProcessor */ public function reindexRow($id) { - if ($this->getIndexer()->isScheduled()) { + if ($this->isIndexerScheduled()) { return; } $this->getIndexer()->reindexRow($id); @@ -59,7 +59,7 @@ abstract class AbstractProcessor */ public function reindexList($ids) { - if ($this->getIndexer()->isScheduled()) { + if ($this->isIndexerScheduled()) { return; } $this->getIndexer()->reindexList($ids); diff --git a/setup/src/Magento/Setup/Fixtures/CartPriceRulesFixture.php b/setup/src/Magento/Setup/Fixtures/CartPriceRulesFixture.php old mode 100644 new mode 100755 index a27a72e7af0ace4963d4112a59af4e579fac0d2d..bff8b2be73a800c8ad6436e9a9ccd1b250cadd6e --- a/setup/src/Magento/Setup/Fixtures/CartPriceRulesFixture.php +++ b/setup/src/Magento/Setup/Fixtures/CartPriceRulesFixture.php @@ -16,6 +16,21 @@ class CartPriceRulesFixture extends Fixture */ protected $priority = 70; + /** + * @var float + */ + protected $cartPriceRulesCount = 0; + + /** + * @var float + */ + protected $cartPriceRulesProductsFloor = 3; + + /** + * @var bool + */ + protected $cartRulesAdvancedType = false; + /** * {@inheritdoc} * @SuppressWarnings(PHPMD) @@ -23,11 +38,13 @@ class CartPriceRulesFixture extends Fixture public function execute() { $this->fixtureModel->resetObjectManager(); - $cartPriceRulesCount = $this->fixtureModel->getValue('cart_price_rules', 0); - if (!$cartPriceRulesCount) { + $this->cartPriceRulesCount = $this->fixtureModel->getValue('cart_price_rules', 0); + if (!$this->cartPriceRulesCount) { return; } - $cartPriceRulesProductsFloor = $this->fixtureModel->getValue( + + $this->cartRulesAdvancedType = $this->fixtureModel->getValue('cart_price_rules_advanced_type', false); + $this->cartPriceRulesProductsFloor = $this->fixtureModel->getValue( 'cart_price_rules_floor', 3 ); @@ -36,8 +53,8 @@ class CartPriceRulesFixture extends Fixture $storeManager = $this->fixtureModel->getObjectManager()->create('Magento\Store\Model\StoreManager'); /** @var $category \Magento\Catalog\Model\Category */ $category = $this->fixtureModel->getObjectManager()->get('Magento\Catalog\Model\Category'); - /** @var $model \Magento\SalesRule\Model\Rule*/ - $model = $this->fixtureModel->getObjectManager()->get('Magento\SalesRule\Model\Rule'); + /** @var $model \Magento\SalesRule\Model\RuleFactory */ + $modelFactory = $this->fixtureModel->getObjectManager()->get('Magento\SalesRule\Model\RuleFactory'); //Get all websites $categoriesArray = []; @@ -62,12 +79,70 @@ class CartPriceRulesFixture extends Fixture } asort($categoriesArray); $categoriesArray = array_values($categoriesArray); - $idField = $model->getIdFieldName(); - for ($i = 0; $i < $cartPriceRulesCount; $i++) { + if ($this->cartRulesAdvancedType == false) { + $this->generateRules($modelFactory, $categoriesArray); + } else { + $this->generateAdvancedRules($modelFactory, $categoriesArray); + } + } + + /** + * @param int $ruleId + * @param array $categoriesArray + * @return array + */ + public function generateCondition($ruleId, $categoriesArray) + { + return [ + 'conditions' => [ + 1 => [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Combine', + 'aggregator' => 'all', + 'value' => '1', + 'new_child' => '', + ], + '1--1' => [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Address', + 'attribute' => 'total_qty', + 'operator' => '>=', + 'value' => $this->cartPriceRulesProductsFloor + $ruleId, + ], + '1--2' => [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product\\Found', + 'value' => '1', + 'aggregator' => 'all', + 'new_child' => '', + ], + '1--2--1' => [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'category_ids', + 'operator' => '==', + 'value' => $categoriesArray[$ruleId % count($categoriesArray)][0], + ], + ], + 'actions' => [ + 1 => [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product\\Combine', + 'aggregator' => 'all', + 'value' => '1', + 'new_child' => '', + ], + ], + ]; + } + + /** + * @param \Magento\SalesRule\Model\RuleFactory $modelFactory + * @param array $categoriesArray + * @return void + */ + public function generateRules($modelFactory, $categoriesArray) + { + for ($i = 0; $i < $this->cartPriceRulesCount; $i++) { $ruleName = sprintf('Cart Price Rule %1$d', $i); $data = [ - $idField => null, + 'rule_id' => null, 'product_ids' => '', 'name' => $ruleName, 'description' => '', @@ -86,42 +161,7 @@ class CartPriceRulesFixture extends Fixture 'to_date' => '', 'sort_order' => '', 'is_rss' => '1', - 'rule' => [ - 'conditions' => [ - 1 => [ - 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Combine', - 'aggregator' => 'all', - 'value' => '1', - 'new_child' => '', - ], - '1--1' => [ - 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Address', - 'attribute' => 'total_qty', - 'operator' => '>=', - 'value' => $cartPriceRulesProductsFloor + $i, - ], - '1--2' => [ - 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product\\Found', - 'value' => '1', - 'aggregator' => 'all', - 'new_child' => '', - ], - '1--2--1' => [ - 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', - 'attribute' => 'category_ids', - 'operator' => '==', - 'value' => $categoriesArray[$i % count($categoriesArray)][0], - ], - ], - 'actions' => [ - 1 => [ - 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product\\Combine', - 'aggregator' => 'all', - 'value' => '1', - 'new_child' => '', - ], - ], - ], + 'rule' => $this->generateCondition($i, $categoriesArray), 'simple_action' => 'by_percent', 'discount_amount' => '10', 'discount_qty' => '0', @@ -169,12 +209,203 @@ class CartPriceRulesFixture extends Fixture } unset($data['rule']); + $model = $modelFactory->create(); $model->loadPost($data); $useAutoGeneration = (int)!empty($data['use_auto_generation']); $model->setUseAutoGeneration($useAutoGeneration); $model->save(); } + } + /** + * @param int $ruleId + * @param array $categoriesArray + * @return array + */ + public function generateAdvancedCondition($ruleId, $categoriesArray) + { + // Generate only 200 region rules, the rest are based on category + if ($ruleId < ($this->cartPriceRulesCount - 200)) { + // Category + $firstCondition = [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'category_ids', + 'operator' => '==', + 'value' => $categoriesArray[($ruleId / 4 ) % count($categoriesArray)][0], + ]; + + $subtotal = [0, 5, 10, 15]; + // Subtotal + $secondCondition = [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Address', + 'attribute' => 'base_subtotal', + 'operator' => '>=', + 'value' => $subtotal[$ruleId % 4], + ]; + + return [ + 'conditions' => [ + 1 => [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Combine', + 'aggregator' => 'all', + 'value' => '1', + 'new_child' => '', + ], + '1--1'=> [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product\\Found', + 'aggregator' => 'all', + 'value' => '1', + 'new_child' => '', + ], + '1--1--1' => $firstCondition, + '1--2' => $secondCondition + ], + 'actions' => [ + 1 => [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product\\Combine', + 'aggregator' => 'all', + 'value' => '1', + 'new_child' => '', + ], + ] + ]; + } else { + // Shipping Region + $regions = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', + 'Delaware', 'District of Columbia', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', + 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', + 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', + 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota', + 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', + 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', + 'Wisconsin', 'Wyoming']; + $firstCondition = [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Address', + 'attribute' => 'region', + 'operator' => '==', + 'value' => $regions[($ruleId / 4) % 50], + ]; + + $subtotals = [0, 5, 10, 15]; + // Subtotal + $secondCondition = [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Address', + 'attribute' => 'base_subtotal', + 'operator' => '>=', + 'value' => $subtotals[$ruleId % 4], + ]; + return [ + 'conditions' => [ + 1 => [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Combine', + 'aggregator' => 'all', + 'value' => '1', + 'new_child' => '', + ], + '1--1' => $firstCondition, + '1--2' => $secondCondition + ], + 'actions' => [ + 1 => [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product\\Combine', + 'aggregator' => 'all', + 'value' => '1', + 'new_child' => '', + ], + ] + ]; + } + } + + /** + * @param \Magento\SalesRule\Model\RuleFactory $modelFactory + * @param array $categoriesArray + * @return void + */ + public function generateAdvancedRules($modelFactory, $categoriesArray) + { + $j = 0; + for ($i = 0; $i < $this->cartPriceRulesCount; $i++) { + if ($i < ($this->cartPriceRulesCount - 200)) { + $ruleName = sprintf('Cart Price Advanced Catalog Rule %1$d', $j); + } else { + $ruleName = sprintf('Cart Price Advanced Region Rule %1$d', $j); + } + $j++; + $data = [ + 'rule_id' => null, + 'product_ids' => '', + 'name' => $ruleName, + 'description' => '', + 'is_active' => '1', + 'website_ids' => $categoriesArray[$i % count($categoriesArray)][1], + 'customer_group_ids' => [ + 0 => '0', + 1 => '1', + 2 => '2', + 3 => '3', + ], + 'coupon_type' => '1', + 'coupon_code' => '', + 'uses_per_customer' => '', + 'from_date' => '', + 'to_date' => '', + 'sort_order' => '', + 'is_rss' => '1', + 'rule' => $this->generateAdvancedCondition($i, $categoriesArray), + 'simple_action' => 'cart_fixed', + 'discount_amount' => '1', + 'discount_qty' => '0', + 'discount_step' => '', + 'apply_to_shipping' => '0', + 'simple_free_shipping' => '0', + 'stop_rules_processing' => '0', + 'reward_points_delta' => '', + 'store_labels' => [ + 0 => '', + 1 => '', + 2 => '', + 3 => '', + 4 => '', + 5 => '', + 6 => '', + 7 => '', + 8 => '', + 9 => '', + 10 => '', + 11 => '', + ], + 'page' => '1', + 'limit' => '20', + 'in_banners' => '', + 'banner_id' => [ + 'from' => '', + 'to' => '', + ], + 'banner_name' => '', + 'visible_in' => '', + 'banner_is_enabled' => '', + 'related_banners' => [], + ]; + if (isset($data['simple_action']) && $data['simple_action'] == 'cart_fixed' + && isset($data['discount_amount']) + ) { + $data['discount_amount'] = min(1, $data['discount_amount']); + } + if (isset($data['rule']['conditions'])) { + $data['conditions'] = $data['rule']['conditions']; + } + if (isset($data['rule']['actions'])) { + $data['actions'] = $data['rule']['actions']; + } + unset($data['rule']); + + $model = $modelFactory->create(); + $model->loadPost($data); + $useAutoGeneration = (int)!empty($data['use_auto_generation']); + $model->setUseAutoGeneration($useAutoGeneration); + $model->save(); + } } /** @@ -182,7 +413,7 @@ class CartPriceRulesFixture extends Fixture */ public function getActionTitle() { - return 'Generating Cart Price Rules'; + return 'Generating cart price rules'; } /** diff --git a/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php b/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php old mode 100644 new mode 100755 index 2c277f66eeac30e877c24c362dd58b81f8c5ac78..da9a4f092b52f80e163caaa70f0faa9e77651c7b --- a/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php @@ -73,12 +73,13 @@ class CartPriceRulesFixtureTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue('category_id')); $modelMock = $this->getMock('\Magento\SalesRule\Model\Rule', [], [], '', false); - $modelMock->expects($this->once()) - ->method('getIdFieldName') - ->will($this->returnValue('Field Id Name')); + $modelFactoryMock = $this->getMock('\Magento\SalesRule\Model\RuleFactory', ['create'], [], '', false); + $modelFactoryMock->expects($this->once()) + ->method('create') + ->willReturn($modelMock); $objectValueMap = [ - ['Magento\SalesRule\Model\Rule', $modelMock], + ['Magento\SalesRule\Model\RuleFactory', $modelFactoryMock], ['Magento\Catalog\Model\Category', $categoryMock] ]; @@ -92,11 +93,12 @@ class CartPriceRulesFixtureTest extends \PHPUnit_Framework_TestCase $valueMap = [ ['cart_price_rules', 0, 1], - ['cart_price_rules_floor', 3, 3] + ['cart_price_rules_floor', 3, 3], + ['cart_price_rules_advanced_type', false, false] ]; $this->fixtureModelMock - ->expects($this->exactly(2)) + ->expects($this->exactly(3)) ->method('getValue') ->will($this->returnValueMap($valueMap)); $this->fixtureModelMock @@ -130,9 +132,121 @@ class CartPriceRulesFixtureTest extends \PHPUnit_Framework_TestCase $this->model->execute(); } + /** + * @param int $ruleId + * @param array $categoriesArray + * @param int $ruleCount + * @dataProvider dataProviderGenerateAdvancedCondition + */ + public function testGenerateAdvancedCondition($ruleId, $categoriesArray, $ruleCount) + { + $reflection = new \ReflectionClass($this->model); + $reflectionProperty = $reflection->getProperty('cartPriceRulesCount'); + $reflectionProperty->setAccessible(true); + $reflectionProperty->setValue($this->model, $ruleCount); + + $result = $this->model->generateAdvancedCondition($ruleId, $categoriesArray); + if ($ruleId < ($ruleCount - 200)) { + $firstCondition = [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product', + 'attribute' => 'category_ids', + 'operator' => '==', + 'value' => null, + ]; + + $secondCondition = [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Address', + 'attribute' => 'base_subtotal', + 'operator' => '>=', + 'value' => 5, + ]; + $expected = [ + 'conditions' => [ + 1 => [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Combine', + 'aggregator' => 'all', + 'value' => '1', + 'new_child' => '', + ], + '1--1'=> [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product\\Found', + 'aggregator' => 'all', + 'value' => '1', + 'new_child' => '', + ], + '1--1--1' => $firstCondition, + '1--2' => $secondCondition + ], + 'actions' => [ + 1 => [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product\\Combine', + 'aggregator' => 'all', + 'value' => '1', + 'new_child' => '', + ], + ] + ]; + } else { + // Shipping Region + $regions = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', + 'Delaware', 'District of Columbia', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', + 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', + 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', + 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota', + 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', + 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', + 'Wisconsin', 'Wyoming']; + $firstCondition = [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Address', + 'attribute' => 'region', + 'operator' => '==', + 'value' => $regions[($ruleId / 4) % 50], + ]; + + $secondCondition = [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Address', + 'attribute' => 'base_subtotal', + 'operator' => '>=', + 'value' => 5, + ]; + $expected = [ + 'conditions' => [ + 1 => [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Combine', + 'aggregator' => 'all', + 'value' => '1', + 'new_child' => '', + ], + '1--1' => $firstCondition, + '1--2' => $secondCondition + ], + 'actions' => [ + 1 => [ + 'type' => 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product\\Combine', + 'aggregator' => 'all', + 'value' => '1', + 'new_child' => '', + ], + ] + ]; + } + $this->assertSame($expected, $result); + } + + /** + * @return array + */ + public function dataProviderGenerateAdvancedCondition() + { + return [ + [1, [0], 1], + [1, [0], 300] + ]; + } + public function testGetActionTitle() { - $this->assertSame('Generating Cart Price Rules', $this->model->getActionTitle()); + $this->assertSame('Generating cart price rules', $this->model->getActionTitle()); } public function testIntroduceParamLabels()