Skip to content

Commit 131ada4

Browse files
Merge pull request #860 from magento-south/BUGS
Fixed issues: - MAGETWO-62616: Products are missed and total count is wrong on category page - MAGETWO-63403: Auto Generated coupon codes not applying - MAGETWO-63561: category_ids attribute scope dropdown - MAGETWO-61830; Related Products Rules can't be defined based on product attribute
2 parents 8b16cd5 + 895cf3b commit 131ada4

File tree

19 files changed

+782
-32
lines changed

19 files changed

+782
-32
lines changed

app/code/Magento/Catalog/Model/Indexer/Category/Product/AbstractAction.php

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
namespace Magento\Catalog\Model\Indexer\Category\Product;
1010

11+
use Magento\Framework\DB\Query\BatchIteratorInterface as BatchIteratorInterface;
12+
use Magento\Framework\DB\Query\Generator as QueryGenerator;
1113
use Magento\Framework\App\ResourceConnection;
1214
use Magento\Framework\EntityManager\MetadataPool;
1315

@@ -102,20 +104,29 @@ abstract class AbstractAction
102104
*/
103105
protected $tempTreeIndexTableName;
104106

107+
/**
108+
* @var QueryGenerator
109+
*/
110+
private $queryGenerator;
111+
105112
/**
106113
* @param ResourceConnection $resource
107114
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
108115
* @param \Magento\Catalog\Model\Config $config
116+
* @param QueryGenerator $queryGenerator
109117
*/
110118
public function __construct(
111119
\Magento\Framework\App\ResourceConnection $resource,
112120
\Magento\Store\Model\StoreManagerInterface $storeManager,
113-
\Magento\Catalog\Model\Config $config
121+
\Magento\Catalog\Model\Config $config,
122+
QueryGenerator $queryGenerator = null
114123
) {
115124
$this->resource = $resource;
116125
$this->connection = $resource->getConnection();
117126
$this->storeManager = $storeManager;
118127
$this->config = $config;
128+
$this->queryGenerator = $queryGenerator ?: \Magento\Framework\App\ObjectManager::getInstance()
129+
->get(QueryGenerator::class);
119130
}
120131

121132
/**
@@ -309,15 +320,26 @@ protected function isRangingNeeded()
309320
* @param int $range
310321
* @return \Magento\Framework\DB\Select[]
311322
*/
312-
protected function prepareSelectsByRange(\Magento\Framework\DB\Select $select, $field, $range = self::RANGE_CATEGORY_STEP)
313-
{
314-
return $this->isRangingNeeded() ? $this->connection->selectsByRange(
315-
$field,
316-
$select,
317-
$range
318-
) : [
319-
$select
320-
];
323+
protected function prepareSelectsByRange(
324+
\Magento\Framework\DB\Select $select,
325+
$field,
326+
$range = self::RANGE_CATEGORY_STEP
327+
) {
328+
if($this->isRangingNeeded()) {
329+
$iterator = $this->queryGenerator->generate(
330+
$field,
331+
$select,
332+
$range,
333+
\Magento\Framework\DB\Query\BatchIteratorInterface::NON_UNIQUE_FIELD_ITERATOR
334+
);
335+
336+
$queries = [];
337+
foreach ($iterator as $query) {
338+
$queries[] = $query;
339+
}
340+
return $queries;
341+
}
342+
return [$select];
321343
}
322344

323345
/**

app/code/Magento/Catalog/etc/eav_attributes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<field code="is_searchable" locked="true" />
3131
</attribute>
3232
<attribute code="category_ids">
33+
<field code="is_global" locked="true" />
3334
<field code="is_searchable" locked="true" />
3435
<field code="used_for_sort_by" locked="true" />
3536
<field code="is_used_in_grid" locked="true" />

app/code/Magento/SalesRule/Model/ResourceModel/Rule/Collection.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,19 @@ public function setValidationFilter(
165165
\Magento\SalesRule\Model\Rule::COUPON_TYPE_NO_COUPON
166166
);
167167

168-
$orWhereConditions = [
168+
$autoGeneratedCouponCondition = [
169169
$connection->quoteInto(
170-
'(main_table.coupon_type = ? AND rule_coupons.type = 0)',
170+
"main_table.coupon_type = ?",
171171
\Magento\SalesRule\Model\Rule::COUPON_TYPE_AUTO
172172
),
173+
$connection->quoteInto(
174+
"rule_coupons.type = ?",
175+
\Magento\SalesRule\Api\Data\CouponInterface::TYPE_GENERATED
176+
),
177+
];
178+
179+
$orWhereConditions = [
180+
"(" . implode($autoGeneratedCouponCondition, " AND ") . ")",
173181
$connection->quoteInto(
174182
'(main_table.coupon_type = ? AND main_table.use_auto_generation = 1 AND rule_coupons.type = 1)',
175183
\Magento\SalesRule\Model\Rule::COUPON_TYPE_SPECIFIC

dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Repository/ConfigurableProduct.xml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,40 @@
241241
</field>
242242
</dataset>
243243

244+
<dataset name="product_with_color_for_promo_rules">
245+
<field name="name" xsi:type="string">Test configurable product with color and size %isolation%</field>
246+
<field name="sku" xsi:type="string">sku_test_configurable_product_%isolation%</field>
247+
<field name="product_has_weight" xsi:type="string">This item has weight</field>
248+
<field name="weight" xsi:type="string">30</field>
249+
<field name="status" xsi:type="string">Yes</field>
250+
<field name="visibility" xsi:type="string">Catalog, Search</field>
251+
<field name="tax_class_id" xsi:type="array">
252+
<item name="dataset" xsi:type="string">taxable_goods</item>
253+
</field>
254+
<field name="url_key" xsi:type="string">configurable-product-%isolation%</field>
255+
<field name="configurable_attributes_data" xsi:type="array">
256+
<item name="dataset" xsi:type="string">color_for_promo_rules</item>
257+
</field>
258+
<field name="quantity_and_stock_status" xsi:type="array">
259+
<item name="is_in_stock" xsi:type="string">In Stock</item>
260+
</field>
261+
<field name="website_ids" xsi:type="array">
262+
<item name="0" xsi:type="array">
263+
<item name="dataset" xsi:type="string">default</item>
264+
</item>
265+
</field>
266+
<field name="attribute_set_id" xsi:type="array">
267+
<item name="dataset" xsi:type="string">default</item>
268+
</field>
269+
<field name="checkout_data" xsi:type="array">
270+
<item name="dataset" xsi:type="string">configurable_default</item>
271+
</field>
272+
<field name="price" xsi:type="array">
273+
<item name="value" xsi:type="string">40</item>
274+
<item name="dataset" xsi:type="string">price_40</item>
275+
</field>
276+
</dataset>
277+
244278
<dataset name="one_variation">
245279
<field name="name" xsi:type="string">Test configurable product %isolation%</field>
246280
<field name="sku" xsi:type="string">sku_test_configurable_product_%isolation%</field>

dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Repository/ConfigurableProduct/ConfigurableAttributesData.xml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,44 @@
563563
</field>
564564
</dataset>
565565

566+
<dataset name="color_for_promo_rules">
567+
<field name="attributes_data" xsi:type="array">
568+
<item name="attribute_key_0" xsi:type="array">
569+
<item name="options" xsi:type="array">
570+
<item name="option_key_0" xsi:type="array">
571+
<item name="pricing_value" xsi:type="string">5.00</item>
572+
<item name="include" xsi:type="string">Yes</item>
573+
</item>
574+
<item name="option_key_1" xsi:type="array">
575+
<item name="pricing_value" xsi:type="string">10.00</item>
576+
<item name="include" xsi:type="string">Yes</item>
577+
</item>
578+
<item name="option_key_2" xsi:type="array">
579+
<item name="pricing_value" xsi:type="string">15.00</item>
580+
<item name="include" xsi:type="string">Yes</item>
581+
</item>
582+
</item>
583+
</item>
584+
</field>
585+
<field name="attributes" xsi:type="array">
586+
<item name="attribute_key_0" xsi:type="string">catalogProductAttribute::color_for_promo_rules</item>
587+
</field>
588+
<field name="matrix" xsi:type="array">
589+
<item name="attribute_key_0:option_key_0" xsi:type="array">
590+
<item name="qty" xsi:type="string">1</item>
591+
<item name="weight" xsi:type="string">1</item>
592+
</item>
593+
<item name="attribute_key_0:option_key_1" xsi:type="array">
594+
<item name="qty" xsi:type="string">1</item>
595+
<item name="weight" xsi:type="string">1</item>
596+
</item>
597+
<item name="attribute_key_0:option_key_2" xsi:type="array">
598+
<item name="qty" xsi:type="string">1</item>
599+
<item name="weight" xsi:type="string">1</item>
600+
</item>
601+
</field>
602+
</dataset>
603+
566604
<dataset name="size">
567605
<field name="attributes_data" xsi:type="array">
568606
<item name="attribute_key_0" xsi:type="array">

dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/PromoQuoteForm.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,9 @@
8080
<selector>[data-index="labels"]</selector>
8181
<strategy>css selector</strategy>
8282
</labels>
83+
<manage_coupon_code>
84+
<class>\Magento\SalesRule\Test\Block\Adminhtml\Promo\Quote\Edit\Section\ManageCouponCode</class>
85+
<selector>[data-index="block_promo_sales_rule_edit_tab_coupons"]</selector>
86+
<strategy>css selector</strategy>
87+
</manage_coupon_code>
8388
</sections>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\SalesRule\Test\Block\Adminhtml\Promo\Quote\Edit\Section;
7+
8+
use Magento\Mtf\Client\Locator;
9+
use Magento\Ui\Test\Block\Adminhtml\Section;
10+
11+
/**
12+
* Backend sales rule label section.
13+
*/
14+
class ManageCouponCode extends Section
15+
{
16+
const GENERATE_CODES_BUTTON_CSS_SELECTOR = ".action-default.scalable.generate";
17+
18+
const LAST_GENERATED_COUPON_CODE_SELECTOR = "//*[@id=\"couponCodesGrid_table\"]/tbody/tr/td[2]";
19+
20+
const SPINNER = ".loading-mask";
21+
22+
/**
23+
* Click on generate button in order to generate coupon codes
24+
*
25+
* @return void
26+
*/
27+
public function generateCouponCodes()
28+
{
29+
$button = $this->_rootElement->find(self::GENERATE_CODES_BUTTON_CSS_SELECTOR);
30+
$button->click();
31+
}
32+
33+
/**
34+
* Retrieve last generated coupon code
35+
*
36+
* @return string
37+
*/
38+
public function getGeneratedCouponCode()
39+
{
40+
$this->waitForSpinner();
41+
$column = $this->_rootElement->find(self::LAST_GENERATED_COUPON_CODE_SELECTOR, Locator::SELECTOR_XPATH);
42+
return $column->getText();
43+
}
44+
45+
private function waitForSpinner()
46+
{
47+
$this->waitForElementNotVisible(self::SPINNER);
48+
sleep(1);
49+
}
50+
}

dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCartPriceRuleApplying.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ public function processAssert(
156156
Customer $customer = null,
157157
Address $address = null,
158158
$isLoggedIn = null,
159+
$couponCode = null,
159160
array $shipping = [],
160161
array $cartPrice = []
161162
) {
@@ -179,10 +180,15 @@ public function processAssert(
179180
$this->checkoutCart->getShippingBlock()->fillEstimateShippingAndTax($address);
180181
$this->checkoutCart->getShippingBlock()->selectShippingMethod($shipping);
181182
}
182-
if ($salesRule->getCouponCode() || $salesRuleOrigin->getCouponCode()) {
183-
$this->checkoutCart->getDiscountCodesBlock()->applyCouponCode(
184-
$salesRule->getCouponCode() ? $salesRule->getCouponCode() : $salesRuleOrigin->getCouponCode()
185-
);
183+
184+
if ($salesRule->getCouponCode()) {
185+
$couponCode = $salesRule->getCouponCode();
186+
} elseif ($salesRuleOrigin->getCouponCode()) {
187+
$couponCode = $salesRuleOrigin->getCouponCode();
188+
}
189+
190+
if ($salesRule->getCouponCode() || $salesRuleOrigin->getCouponCode() || $couponCode) {
191+
$this->checkoutCart->getDiscountCodesBlock()->applyCouponCode($couponCode);
186192
}
187193
$this->assert();
188194
}

dev/tests/functional/tests/app/Magento/SalesRule/Test/Repository/SalesRule.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@
9595
<field name="discount_amount" xsi:type="string">50</field>
9696
<field name="stop_rules_processing" xsi:type="string">Yes</field>
9797
</dataset>
98-
9998
<dataset name="active_sales_rule_with_complex_conditions">
10099
<field name="name" xsi:type="string">Cart Price Rule with with complex conditions %isolation%</field>
101100
<field name="description" xsi:type="string">Cart Price Rule with with complex conditions</field>

dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\SalesRule\Test\TestCase;
88

9+
use Magento\SalesRule\Test\Block\Adminhtml\Promo\Quote\Edit\Section\ManageCouponCode;
910
use Magento\SalesRule\Test\Fixture\SalesRule;
1011
use Magento\SalesRule\Test\Page\Adminhtml\PromoQuoteEdit;
1112
use Magento\SalesRule\Test\Page\Adminhtml\PromoQuoteIndex;
@@ -107,7 +108,8 @@ public function testCreateSalesRule(
107108
CatalogProductSimple $productForSalesRule1,
108109
CatalogProductSimple $productForSalesRule2 = null,
109110
Customer $customer = null,
110-
$conditionEntity = null
111+
$conditionEntity = null,
112+
SalesRule $salesRuleEdit = null
111113
) {
112114
$replace = null;
113115
$this->salesRuleName = $salesRule->getName();
@@ -127,7 +129,22 @@ public function testCreateSalesRule(
127129
// Steps
128130
$this->promoQuoteNew->open();
129131
$this->promoQuoteNew->getSalesRuleForm()->fill($salesRule, null, $replace);
130-
$this->promoQuoteNew->getFormPageActions()->save();
132+
133+
if ($salesRule->getCouponType() == "Auto") {
134+
$this->promoQuoteNew->getFormPageActions()->saveAndContinue();
135+
$form = $this->promoQuoteEdit->getSalesRuleForm();
136+
$form->openSection('manage_coupon_code');
137+
/** @var ManageCouponCode $section */
138+
$section = $form->getSection('manage_coupon_code');
139+
$section->fill($salesRuleEdit);
140+
$section->generateCouponCodes();
141+
$couponCode = $section->getGeneratedCouponCode();
142+
$this->promoQuoteEdit->getFormPageActions()->save();
143+
144+
return ["couponCode" => $couponCode];
145+
} else {
146+
$this->promoQuoteNew->getFormPageActions()->save();
147+
}
131148
}
132149

133150
/**

0 commit comments

Comments
 (0)