Skip to content

Commit 194ac13

Browse files
committed
ACP2E-1388, skipping price removal if product is out of stock, but part of a dynamic price bundle
1 parent a52bf90 commit 194ac13

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

app/code/Magento/Bundle/Pricing/Adjustment/DefaultSelectionPriceListProvider.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ public function getPriceList(Product $bundleProduct, $searchMin, $useRegularPric
8686
);
8787
$selectionsCollection->setFlag('has_stock_status_filter', true);
8888
$selectionsCollection->removeAttributeToSelect();
89-
//$selectionsCollection->addQuantityFilter();
9089

9190
if (!$useRegularPrice) {
9291
$selectionsCollection->addAttributeToSelect('special_price');

app/code/Magento/Catalog/Model/Indexer/Product/Price/AbstractAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ function ($type) use ($productsTypes) {
411411
$indexer->executeByDimensions($dimensions, \SplFixedArray::fromArray($entityIds, false));
412412
$mainTable = $this->tableMaintainer->getMainTableByDimensions($dimensions);
413413
$this->_insertFromTable($temporaryTable, $mainTable);
414-
//$this->deleteOutdatedData($entityIds, $temporaryTable, $mainTable); //here be the problem
414+
$this->deleteOutdatedData($entityIds, $temporaryTable, $mainTable);
415415
}
416416
} else {
417417
// handle 3d-party indexers for backward compatibility

app/code/Magento/CatalogInventory/Model/Indexer/ProductPriceIndexFilter.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,35 @@ public function modifyPrice(IndexTableStructure $priceTable, array $entityIds =
121121
foreach ($batchSelectIterator as $select) {
122122
$productIds = null;
123123
foreach ($connection->query($select)->fetchAll() as $row) {
124-
$productIds[] = (int) $row['product_id'];
124+
if ($row['product_id'] && $this->isWithinDynamicPriceBundle($priceTable->getTableName(), (int) $row['product_id'])) {
125+
$productIds[] = (int) $row['product_id'];
126+
}
125127
}
126128
if ($productIds !== null) {
127129
$where = [$priceTable->getEntityField() .' IN (?)' => $productIds];
128130
$connection->delete($priceTable->getTableName(), $where);
129131
}
130132
}
131133
}
134+
135+
/**
136+
* Check if the product is used within a dynamic price bundle configuration
137+
*
138+
* @param string $priceTableName
139+
* @param int $productId
140+
* @return bool
141+
*/
142+
private function isWithinDynamicPriceBundle(string $priceTableName, int $productId): bool
143+
{
144+
$connection = $this->resourceConnection->getConnection($this->connectionName);
145+
$select = $connection->select();
146+
$select->from(['selection' => 'catalog_product_bundle_selection'], 'selection_id');
147+
$select->joinInner(['entity' => 'catalog_product_entity'], implode(' AND ', ['selection.parent_product_id = entity.entity_id']), null);
148+
$select->joinInner(['price' => $priceTableName], implode(' AND ', ['price.entity_id = selection.product_id']), null);
149+
$select->where('selection.product_id = ?', $productId);
150+
$select->where('entity.type_id = ?', \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE);
151+
$select->where('price.tax_class_id = ?', \Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC);
152+
153+
return intval($connection->fetchOne($select)) != 0;
154+
}
132155
}

0 commit comments

Comments
 (0)