Skip to content

Commit

Permalink
MDVA-27939: Backport inventor patches down to 2.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
robertorubino committed May 21, 2020
1 parent 6c9c7b8 commit 7e9915c
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public function aroundModifyPrice(
$select->from(['price_index' => $priceTable->getTableName()], []);
$priceEntityField = $priceTable->getEntityField();

if (!$this->isDefaultStock($stock) && $this->resourceConnection->getConnection()->isTableExists($stockTable)) {
if (!$this->isDefaultStock($stock)
&& $this->resourceConnection->getConnection()->isTableExists($stockTable)) {
$select->joinInner(
['product_entity' => $this->resourceConnection->getTableName('catalog_product_entity')],
"product_entity.entity_id = price_index.{$priceEntityField}",
Expand All @@ -105,6 +106,17 @@ public function aroundModifyPrice(
[]
);
$select->where('inventory_stock.is_salable = 0 OR inventory_stock.is_salable IS NULL');
} else {
$legacyStockTableName = $this->resourceConnection->getTableName('cataloginventory_stock_status');
$select->joinLeft(
['stock_status' => $legacyStockTableName],
sprintf(
'stock_status.product_id = price_index.%s',
$priceEntityField
),
[]
);
$select->where('stock_status.stock_status = 0 OR stock_status.stock_status IS NULL');
}

$select->where('price_index.website_id = ?', $websiteId);
Expand Down Expand Up @@ -136,4 +148,15 @@ private function getWebsiteIdsFromProducts(array $entityIds): array

return $result;
}

/**
* Checks if inventory stock is DB view
*
* @param StockInterface $stock
* @return bool
*/
private function isDefaultStock(StockInterface $stock): bool
{
return (int)$stock->getStockId() === $this->defaultStockProvider->getId();
}
}

0 comments on commit 7e9915c

Please sign in to comment.