I am trying to get round a bug in Magento In-Store pickup, https://github.com/magento/inventory/issues/3367
I have multiple pickup locations, stock is assigned to the relevant location but Magento always shows all locations even if its out of stock.
I have been looking at GetPickupLocationIntersectionForSkus.php but I cant see how to filter the results to only show souces that have stock
public function execute(array $skus): array
{
$select = $this->sourceItemResource->getConnection()->select();
$expression = $this->expressionFactory->create(['expression' => 'COUNT(' . SourceItemInterface::SKU . ')']);
$select->from($this->sourceItemResource->getMainTable())
->joinInner(
$this->sourceResource->getMainTable(),
$this->sourceItemResource->getMainTable() . '.' . SourceItemInterface::SOURCE_CODE . '=' .
$this->sourceResource->getMainTable() . '.' . SourceInterface::SOURCE_CODE
)
->where(SourceItemInterface::SKU . ' in (?) ', $skus)
->where(SourceInterface::ENABLED . ' = 1')
->where(PickupLocationInterface::IS_PICKUP_LOCATION_ACTIVE . ' = 1')
->reset(Select::COLUMNS)
->columns([SourceItemInterface::SOURCE_CODE])
->group($this->sourceItemResource->getMainTable() . '.' . SourceItemInterface::SOURCE_CODE)
->having($expression . ' = ' . count($skus));
$result = $this->sourceItemResource->getConnection()->fetchAssoc($select);
$sourceCodes = [];
foreach ($result as $row) {
$sourceCodes[] = $row[SourceItemInterface::SOURCE_CODE];
}
return $sourceCodes;
}
I thought adding ->where(SourceItemInterface::STATUS . ' = 1')
would do the trick but this still shows the sources where the item is out of stock