Skip to content
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

Merged
merged 10 commits into from
Dec 21, 2018
Merged

Conversation

IvanPletnyov
Copy link
Contributor

Fixed Issues (if relevant)

  1. Elasticsearch don't work with Custom stock #1890: Elasticsearch don't work with Custom stock

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

$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'];
Copy link
Contributor

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

Copy link
Contributor Author

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());
Copy link
Contributor

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'];
Copy link
Contributor

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'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

always use === for comparison

Copy link
Contributor

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",
Copy link
Contributor

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)) {
Copy link
Contributor

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'];
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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

Copy link
Contributor

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
Copy link
Contributor

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.
Copy link
Contributor

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) {
Copy link
Contributor

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();
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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)
@maghamed maghamed merged commit 673e85c into 2.3-develop Dec 21, 2018
@ishakhsuvarov ishakhsuvarov deleted the MSI-1890 branch June 19, 2019 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants