Skip to content

Commit

Permalink
Merge remote-tracking branch 'mainline/develop' into prepared-pull-re…
Browse files Browse the repository at this point in the history
…quest
  • Loading branch information
Michail Slabko committed Nov 2, 2015
2 parents a1c4dc5 + abb8d3b commit 92513dc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 41 deletions.
11 changes: 8 additions & 3 deletions app/code/Magento/CatalogImportExport/Model/Import/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -2223,9 +2223,14 @@ private function _parseAdditionalAttributes($rowData)

$attributeNameValuePairs = explode($this->getMultipleValueSeparator(), $rowData['additional_attributes']);
foreach ($attributeNameValuePairs as $attributeNameValuePair) {
$nameAndValue = explode(self::PAIR_NAME_VALUE_SEPARATOR, $attributeNameValuePair);
if (!empty($nameAndValue)) {
$rowData[$nameAndValue[0]] = isset($nameAndValue[1]) ? $nameAndValue[1] : '';
$separatorPosition = strpos($attributeNameValuePair, self::PAIR_NAME_VALUE_SEPARATOR);
if ($separatorPosition !== false) {
$key = substr($attributeNameValuePair, 0, $separatorPosition);
$value = substr(
$attributeNameValuePair,
$separatorPosition + strlen(self::PAIR_NAME_VALUE_SEPARATOR)
);
$rowData[$key] = $value === false ? '' : $value;
}
}
return $rowData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ class ConfigurableProductHandler
/** @var ConfigurableProductsProvider */
private $configurableProductsProvider;

/** @var array */
private $subProductsValidationResults = [];

/**
* @param \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable $configurable
* @param ConfigurableProductsProvider $configurableProductsProvider
Expand All @@ -39,45 +36,24 @@ public function __construct(
* @param \Magento\CatalogRule\Model\Rule $rule
* @param array $productIds
* @return array
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterGetMatchingProductIds(\Magento\CatalogRule\Model\Rule $rule, array $productIds)
{
$configurableProductIds = $this->configurableProductsProvider->getIds(array_keys($productIds));
foreach ($configurableProductIds as $productId) {
$subProductsIds = $this->configurable->getChildrenIds($productId)[0];
$parentValidationResult = $productIds[$productId];
foreach ($subProductsIds as $subProductsId) {
$productIds[$subProductsId] = $this->getSubProductValidationResult(
$rule->getId(),
$subProductsId,
$parentValidationResult
);
$subProductIds = $this->configurable->getChildrenIds($productId)[0];
$parentValidationResult = isset($productIds[$productId])
? array_filter($productIds[$productId])
: [];
foreach ($subProductIds as $subProductId) {
$childValidationResult = isset($productIds[$subProductId])
? array_filter($productIds[$subProductId])
: [];
$productIds[$subProductId] = $parentValidationResult + $childValidationResult;
}
unset($productIds[$productId]);
}
return $productIds;
}

/**
* Return validation result for sub-product.
* If any of configurable product is valid for current rule, then their sub-product must be valid too
*
* @param int $urlId
* @param int $subProductsId
* @param array $parentValidationResult
* @return array
*/
private function getSubProductValidationResult($urlId, $subProductsId, $parentValidationResult)
{
if (!isset($this->subProductsValidationResults[$urlId][$subProductsId])) {
$this->subProductsValidationResults[$urlId][$subProductsId] = array_filter($parentValidationResult);
} else {
$parentValidationResult = array_intersect_key(
$this->subProductsValidationResults[$urlId][$subProductsId] + $parentValidationResult,
$parentValidationResult
);
$this->subProductsValidationResults[$urlId][$subProductsId] = $parentValidationResult;
}
return $parentValidationResult;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,9 @@ public function testAfterGetMatchingProductIdsWithConfigurableProduct()
0 => true,
1 => true,
3 => true,
4 => false,
],
'simple2' => [
0 => false,
1 => false,
3 => true,
4 => false,
]
],
$this->configurableProductHandler->afterGetMatchingProductIds(
Expand Down

0 comments on commit 92513dc

Please sign in to comment.