Skip to content

Commit fd40a7b

Browse files
committed
Avoid duplicate keys when updating from select
1 parent f75a78b commit fd40a7b

File tree

1 file changed

+37
-1
lines changed
  • app/code/Magento/Bundle/Model/ResourceModel/Indexer

1 file changed

+37
-1
lines changed

app/code/Magento/Bundle/Model/ResourceModel/Indexer/Price.php

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,42 @@ private function getBaseBundleSelectionPriceSelect(): Select
455455
return $select;
456456
}
457457

458+
/**
459+
* Get base select for bundle selection price update
460+
*
461+
* @return Select
462+
* @throws \Exception
463+
*/
464+
private function getBaseBundleSelectionPriceUpdateSelect(): Select
465+
{
466+
$metadata = $this->metadataPool->getMetadata(ProductInterface::class);
467+
$linkField = $metadata->getLinkField();
468+
$bundleSelectionTable = $this->getBundleSelectionTable();
469+
470+
$select = $this->getConnection()->select()
471+
->join(
472+
['i' => $this->getBundlePriceTable()],
473+
"i.entity_id = $bundleSelectionTable.entity_id
474+
AND i.customer_group_id = $bundleSelectionTable.customer_group_id
475+
AND i.website_id = $bundleSelectionTable.website_id",
476+
[]
477+
)->join(
478+
['parent_product' => $this->getTable('catalog_product_entity')],
479+
'parent_product.entity_id = i.entity_id',
480+
[]
481+
)->join(
482+
['bo' => $this->getTable('catalog_product_bundle_option')],
483+
"bo.parent_id = parent_product.$linkField AND bo.option_id = $bundleSelectionTable.option_id",
484+
['option_id']
485+
)->join(
486+
['bs' => $this->getTable('catalog_product_bundle_selection')],
487+
"bs.option_id = bo.option_id AND bs.selection_id = $bundleSelectionTable.selection_id",
488+
['selection_id']
489+
);
490+
491+
return $select;
492+
}
493+
458494
/**
459495
* Apply selections price for fixed bundles
460496
*
@@ -498,7 +534,7 @@ private function applyFixedBundleSelectionPrice()
498534
]
499535
);
500536

501-
$select = $this->getBaseBundleSelectionPriceSelect();
537+
$select = $this->getBaseBundleSelectionPriceUpdateSelect();
502538
$select->joinInner(
503539
['bsp' => $this->getTable('catalog_product_bundle_selection_price')],
504540
'bs.selection_id = bsp.selection_id AND bsp.website_id = i.website_id',

0 commit comments

Comments
 (0)