|
10 | 10 | use Magento\Catalog\Api\Data\ProductInterface;
|
11 | 11 | use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
|
12 | 12 | use Magento\Catalog\Model\Product\Attribute\Source\Status as ProductStatus;
|
| 13 | +use Magento\Framework\Exception\NoSuchEntityException; |
13 | 14 | use Magento\Quote\Model\Quote;
|
14 | 15 | use Magento\Quote\Model\Quote\Item as QuoteItem;
|
15 | 16 | use Magento\Quote\Model\ResourceModel\Quote\Item as ResourceQuoteItem;
|
@@ -256,8 +257,17 @@ protected function _assignProducts(): self
|
256 | 257 | foreach ($this as $item) {
|
257 | 258 | /** @var ProductInterface $product */
|
258 | 259 | $product = $productCollection->getItemById($item->getProductId());
|
| 260 | + try { |
| 261 | + /** @var QuoteItem $item */ |
| 262 | + $parentItem = $item->getParentItem(); |
| 263 | + $parentProduct = $parentItem ? $parentItem->getProduct() : null; |
| 264 | + } catch (NoSuchEntityException $exception) { |
| 265 | + $parentItem = null; |
| 266 | + $parentProduct = null; |
| 267 | + $this->_logger->error($exception); |
| 268 | + } |
259 | 269 | $qtyOptions = [];
|
260 |
| - if ($product && $this->isValidProduct($product)) { |
| 270 | + if ($this->isValidProduct($product) && (!$parentItem || $this->isValidProduct($parentProduct))) { |
261 | 271 | $product->setCustomOptions([]);
|
262 | 272 | $optionProductIds = $this->getOptionProductIds($item, $product, $productCollection);
|
263 | 273 | foreach ($optionProductIds as $optionProductId) {
|
@@ -327,7 +337,7 @@ private function getOptionProductIds(
|
327 | 337 | * @param ProductInterface $product
|
328 | 338 | * @return bool
|
329 | 339 | */
|
330 |
| - private function isValidProduct(ProductInterface $product): bool |
| 340 | + private function isValidProduct(?ProductInterface $product): bool |
331 | 341 | {
|
332 | 342 | $result = ($product && (int)$product->getStatus() !== ProductStatus::STATUS_DISABLED);
|
333 | 343 |
|
|
0 commit comments