-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MSI-1890: Elasticsearch don't work with Custom stock #1943
Conversation
$select->where('product.entity_id IN (?)', $productIds); | ||
$productsSalable = $connection->fetchAssoc($select); | ||
$productsSalable = array_filter($productsSalable, function ($productSalable) { | ||
return StockStatusInterface::STATUS_IN_STOCK == $productSalable['is_salable']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here we are working with Inventory indexes table structure, no need to use deprecated constant from CatalogInventory module
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maghamed I've deleted array filtration.
|
||
foreach ($this->getProductIdsByWebsiteIds($productIds) as $websiteId => $productIds) { | ||
$stock = $this->stockByWebsiteIdResolver->execute($websiteId); | ||
$stockTable = $this->stockIndexTableNameResolver->execute((int)$stock->getStockId()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like we have to provide conditional logic for Default Stock similar to this PR
#1937
to prevent performance degradation on Default Stock
['website_id', 'product_id'] | ||
)->where('product_in_websites.product_id IN (?)', $entityIds)->distinct(); | ||
foreach ($connection->fetchAll($select) as $websiteData) { | ||
$result[(int)$websiteData['website_id']][] = (int)$websiteData['product_id']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably it's more performance efficient to use GROUP BY + GROUP CONCAT on DB level
$select->where('product.entity_id IN (?)', $productIds); | ||
$productsSalable = $connection->fetchAssoc($select); | ||
$productsSalable = array_filter($productsSalable, function ($productSalable) { | ||
return StockStatusInterface::STATUS_IN_STOCK == $productSalable['is_salable']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
always use === for comparison
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use filtering as a part of MySQL query?
why do you filter by in stock
in application?
); | ||
$select->joinInner( | ||
['stock' => $stockTable], | ||
"product.sku = stock.sku", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use single quotes
$stock = $this->stockByWebsiteIdResolver->execute($websiteId); | ||
$stockTable = $this->stockIndexTableNameResolver->execute((int)$stock->getStockId()); | ||
|
||
if ($this->resourceConnection->getConnection()->isTableExists($stockTable)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to use this IF clause
if ($this->resourceConnection->getConnection()->isTableExists($stockTable)) {
$select->where('product.entity_id IN (?)', $productIds); | ||
$productsSalable = $connection->fetchAssoc($select); | ||
$productsSalable = array_filter($productsSalable, function ($productSalable) { | ||
return StockStatusInterface::STATUS_IN_STOCK == $productSalable['is_salable']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use filtering as a part of MySQL query?
why do you filter by in stock
in application?
* @param array $entityIds | ||
* @return array | ||
*/ | ||
private function getProductIdsByWebsiteIds(array $entityIds): array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need this logic at all? as customer always run a query in the scope of one website
one and only
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maghamed Save product in admin panel or run reindex will be on admin scope
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but you are still supposed to execute business logic in a single scope
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so that this method looks excessive
DataProvider $dataProvider, | ||
array $indexData, | ||
array $productData, | ||
int $storeId |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are backward incompatible changes, as you are introducing strict typing for NON-strict typed contract
/**
* Prepare Fulltext index value for product
*
* @param array $indexData
* @param array $productData
* @param int $storeId
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @since 100.0.3
*/
public function prepareProductIndex($indexData, $productData, $storeId)
} | ||
|
||
/** | ||
* Filter out of stock options for configurable product. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove "of"
and just leave
Filter out stock options for configurable product.
$productIds = array_keys($indexData); | ||
$stockStatuses = []; | ||
|
||
foreach ($this->getProductIdsByWebsiteIds($productIds) as $websiteId => $productIdsStr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have to resolve Website by $storeId and then by Website (which in MSI plays a role of Sales Channel) we could resolve corresponding Stock
Thus, for $stockId you would have ONE and ONLY Stock
|
||
foreach ($this->getProductIdsByWebsiteIds($productIds) as $websiteId => $productIdsStr) { | ||
$stock = $this->stockByWebsiteIdResolver->execute($websiteId); | ||
$stockId = (int)$stock->getStockId(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you use type casting if we already use strict typing in out interfaces?
/**
* Get stock id
*
* @return int|null
*/
public function getStockId(): ?int;
* @param array $entityIds | ||
* @return array | ||
*/ | ||
private function getProductIdsByWebsiteIds(array $entityIds): array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but you are still supposed to execute business logic in a single scope
* @param array $entityIds | ||
* @return array | ||
*/ | ||
private function getProductIdsByWebsiteIds(array $entityIds): array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so that this method looks excessive
… test \Magento\Elasticsearch\Model\Indexer\IndexHandlerTest)
Fixed Issues (if relevant)
Contribution checklist