Skip to content

Commit abb8d3b

Browse files
author
Korshenko, Olexii(okorshenko)
committed
Merge pull request #86 from magento-troll/MAGETWO-43336
[Troll]: Catalog Price Rules fix
2 parents 20245f4 + d1b250c commit abb8d3b

File tree

3 files changed

+18
-41
lines changed

3 files changed

+18
-41
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2223,9 +2223,14 @@ private function _parseAdditionalAttributes($rowData)
22232223

22242224
$attributeNameValuePairs = explode($this->getMultipleValueSeparator(), $rowData['additional_attributes']);
22252225
foreach ($attributeNameValuePairs as $attributeNameValuePair) {
2226-
$nameAndValue = explode(self::PAIR_NAME_VALUE_SEPARATOR, $attributeNameValuePair);
2227-
if (!empty($nameAndValue)) {
2228-
$rowData[$nameAndValue[0]] = isset($nameAndValue[1]) ? $nameAndValue[1] : '';
2226+
$separatorPosition = strpos($attributeNameValuePair, self::PAIR_NAME_VALUE_SEPARATOR);
2227+
if ($separatorPosition !== false) {
2228+
$key = substr($attributeNameValuePair, 0, $separatorPosition);
2229+
$value = substr(
2230+
$attributeNameValuePair,
2231+
$separatorPosition + strlen(self::PAIR_NAME_VALUE_SEPARATOR)
2232+
);
2233+
$rowData[$key] = $value === false ? '' : $value;
22292234
}
22302235
}
22312236
return $rowData;

app/code/Magento/CatalogRuleConfigurable/Plugin/CatalogRule/Model/Rule/ConfigurableProductHandler.php

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ class ConfigurableProductHandler
2020
/** @var ConfigurableProductsProvider */
2121
private $configurableProductsProvider;
2222

23-
/** @var array */
24-
private $subProductsValidationResults = [];
25-
2623
/**
2724
* @param \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable $configurable
2825
* @param ConfigurableProductsProvider $configurableProductsProvider
@@ -39,45 +36,24 @@ public function __construct(
3936
* @param \Magento\CatalogRule\Model\Rule $rule
4037
* @param array $productIds
4138
* @return array
39+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4240
*/
4341
public function afterGetMatchingProductIds(\Magento\CatalogRule\Model\Rule $rule, array $productIds)
4442
{
4543
$configurableProductIds = $this->configurableProductsProvider->getIds(array_keys($productIds));
4644
foreach ($configurableProductIds as $productId) {
47-
$subProductsIds = $this->configurable->getChildrenIds($productId)[0];
48-
$parentValidationResult = $productIds[$productId];
49-
foreach ($subProductsIds as $subProductsId) {
50-
$productIds[$subProductsId] = $this->getSubProductValidationResult(
51-
$rule->getId(),
52-
$subProductsId,
53-
$parentValidationResult
54-
);
45+
$subProductIds = $this->configurable->getChildrenIds($productId)[0];
46+
$parentValidationResult = isset($productIds[$productId])
47+
? array_filter($productIds[$productId])
48+
: [];
49+
foreach ($subProductIds as $subProductId) {
50+
$childValidationResult = isset($productIds[$subProductId])
51+
? array_filter($productIds[$subProductId])
52+
: [];
53+
$productIds[$subProductId] = $parentValidationResult + $childValidationResult;
5554
}
5655
unset($productIds[$productId]);
5756
}
5857
return $productIds;
5958
}
60-
61-
/**
62-
* Return validation result for sub-product.
63-
* If any of configurable product is valid for current rule, then their sub-product must be valid too
64-
*
65-
* @param int $urlId
66-
* @param int $subProductsId
67-
* @param array $parentValidationResult
68-
* @return array
69-
*/
70-
private function getSubProductValidationResult($urlId, $subProductsId, $parentValidationResult)
71-
{
72-
if (!isset($this->subProductsValidationResults[$urlId][$subProductsId])) {
73-
$this->subProductsValidationResults[$urlId][$subProductsId] = array_filter($parentValidationResult);
74-
} else {
75-
$parentValidationResult = array_intersect_key(
76-
$this->subProductsValidationResults[$urlId][$subProductsId] + $parentValidationResult,
77-
$parentValidationResult
78-
);
79-
$this->subProductsValidationResults[$urlId][$subProductsId] = $parentValidationResult;
80-
}
81-
return $parentValidationResult;
82-
}
8359
}

app/code/Magento/CatalogRuleConfigurable/Test/Unit/Plugin/CatalogRule/Model/Rule/ConfigurableProductHandlerTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,9 @@ public function testAfterGetMatchingProductIdsWithConfigurableProduct()
9393
0 => true,
9494
1 => true,
9595
3 => true,
96-
4 => false,
9796
],
9897
'simple2' => [
99-
0 => false,
100-
1 => false,
10198
3 => true,
102-
4 => false,
10399
]
104100
],
105101
$this->configurableProductHandler->afterGetMatchingProductIds(

0 commit comments

Comments
 (0)