Skip to content

Commit

Permalink
MDEE-599: [Product feed] Errors in child data provider do not allow t…
Browse files Browse the repository at this point in the history
…o assemble entire batch of products (#353)

* MDEE-599: [Product feed] Errors in child data provider do not allow to assemble entire batch of products
  • Loading branch information
duhon authored Nov 30, 2023
1 parent 6a254ba commit bc5211e
Showing 1 changed file with 47 additions and 21 deletions.
68 changes: 47 additions & 21 deletions ConfigurableProductDataExporter/Model/Provider/Product/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace Magento\ConfigurableProductDataExporter\Model\Provider\Product;

use Exception;
use Magento\CatalogDataExporter\Model\Provider\Product\OptionProviderInterface;
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
use Magento\ConfigurableProductDataExporter\Model\Query\ProductOptionQuery;
Expand Down Expand Up @@ -91,7 +90,7 @@ private function getTable(string $reference)
}

/**
* Returns possible attribute valies for a product
* Returns possible attribute values for a product
*
* @param int $entityId
* @param int $attributeId
Expand Down Expand Up @@ -225,6 +224,8 @@ private function getOptionKey($row): string

/**
* @inheritDoc
*
* @throws UnableRetrieveData
*/
public function get(array $values): array
{
Expand All @@ -246,29 +247,12 @@ public function get(array $values): array
try {
$options = [];
$optionValuesData = $this->getOptionValuesData($queryArguments);

$select = $this->productOptionQuery->getQuery($queryArguments);

$cursor = $this->resourceConnection->getConnection()->query($select);

while ($row = $cursor->fetch()) {
if (!isset($temp[$row['productId'] . '-' . $row['attribute_id']])) {
$temp[$row['productId'] . '-' . $row['attribute_id']] =
$this->getPossibleAttributeValues($row['productId'], $row['attribute_id']);
}
$filter = $temp[$row['productId'] . '-' . $row['attribute_id']];

$key = $this->getOptionKey($row);
$options[$key] = $options[$key] ?? $this->formatOptionsRow($row);

if (isset($optionValuesData[$row['attribute_id']][$row['storeViewCode']])) {
$options[$key]['optionsV2']['values'] = $this->getAssignedAttributeValues(
$optionValuesData[$row['attribute_id']][$row['storeViewCode']],
$filter
);
}
$options = $this->getOptions($row, $temp, $options, $optionValuesData);
}
} catch (Exception $exception) {
} catch (\Throwable $exception) {
$this->logger->error($exception->getMessage(), ['exception' => $exception]);
throw new UnableRetrieveData('Unable to retrieve configurable product options data');
}
Expand All @@ -288,4 +272,46 @@ private function getAssignedAttributeValues(array $attributeValuesList, array $a

return !empty($assignedAttributeValues) ? \array_values($assignedAttributeValues) : [];
}

/**
* Get Options
*
* @param mixed $row
* @param array $temp
* @param array $options
* @param array $optionValuesData
* @return array
*/
private function getOptions(mixed $row, array $temp, array $options, array $optionValuesData): array
{
try {
$key = $row['productId'] . '-' . $row['attribute_id'];
if (!isset($temp[$key])) {
$temp[$key] = $this->getPossibleAttributeValues($row['productId'], $row['attribute_id']);
}
$filter = $temp[$key];

$key = $this->getOptionKey($row);
$options[$key] = $options[$key] ?? $this->formatOptionsRow($row);

if (isset($optionValuesData[$row['attribute_id']][$row['storeViewCode']])) {
$options[$key]['optionsV2']['values'] = $this->getAssignedAttributeValues(
$optionValuesData[$row['attribute_id']][$row['storeViewCode']],
$filter
);
}
} catch (\Throwable $exception) {
$this->logger->error(
sprintf(
'Unable to retrieve configurable product options data
(productId:%s, attributeId:%s, storeViewCode:%s)',
$row['productId'],
$row['attribute_id'],
$row['storeViewCode']
),
['exception' => $exception]
);
}
return $options;
}
}

0 comments on commit bc5211e

Please sign in to comment.