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

Reworking stock post processor and stock_item resolver as batch contracts #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

aleksandrsm
Copy link
Contributor

To go together with scandipwa/catalog-graphql#141

Requires FE change, to not query in_stock field on stock_item.

Implemented new StockStatus batch service contract resolver.

The logic of AreProductsSalableConditionChain is following the core M2 logic of IsProductSalableConditionChain for frontend area, but is refactored to support grouped requests at (almost) every step.
Alternatives for MSI/M2 plugins on the corresponding core classes implemented as part of code directly.

Note: by default, M2 was creating a new instance of a batch service contract wrapper for each product type(so it'd group stock request for simple products separately from configurable, bundle, etc..). Implemented a workaround with an internal request queue on the services.

Moved stock_item resolver from CatalogGraphQl module / replaced with a batch service contract that re-uses stock item data cache from the new stock_status resolver.

@carinadues
Copy link
Contributor

Taking note not to merge them now. We will test everything in a separate instance first.

Comment on lines 235 to 236
|| $this->isSingleSourceMode->execute()
|| !$this->isSourceItemManagementAllowedForSku->execute($sku)
Copy link
Member

@AzizKHAN030 AzizKHAN030 Jul 18, 2022

Choose a reason for hiding this comment

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

Sometimes while fetching products in PLP we get Error and can't get the products, these 2 methods are null in these cases and can't execute.
In some categories everything is okay, example
For other the error occurs, example

Endpoint: https://scandipwapmrevprtest-dev.indvp.com/graphql (Access with VPN)

Full GraphQL Query:
query ( $sort_1: ProductAttributeSortInput! $filter_1: ProductAttributeFilterInput! $pageSize_1: Int! $currentPage_1: Int! ) { products( sort: $sort_1 filter: $filter_1 pageSize: $pageSize_1 currentPage: $currentPage_1 ) { total_count items { uid id sku name type_id stock_status salable_qty stock_item { min_sale_qty max_sale_qty qty_increments } price_range { minimum_price { discount { amount_off percent_off } final_price { currency value } final_price_excl_tax { currency value } regular_price { currency value } regular_price_excl_tax { currency value } default_price { currency value } default_final_price { currency value } default_final_price_excl_tax { currency value } } maximum_price { discount { amount_off percent_off } final_price { currency value } final_price_excl_tax { currency value } regular_price { currency value } regular_price_excl_tax { currency value } default_price { currency value } default_final_price { currency value } default_final_price_excl_tax { currency value } } } image { path url } thumbnail { path url } small_image { path url } short_description { html } special_from_date special_to_date price_tiers { discount { amount_off percent_off } final_price { currency value } quantity } attributes: s_attributes { attribute_id attribute_value attribute_code attribute_label attribute_type attribute_group_id attribute_group_name attribute_options { label value swatch_data { type value } } } url url_rewrites { url } review_count rating_summary ... on CustomizableProductInterface { options { ... on CustomizableDropDownOption { dropdownValues: value { uid option_type_id price priceInclTax priceExclTax price_type currency sku title sort_order } } ... on CustomizableRadioOption { dropdownValues: value { uid option_type_id price priceInclTax priceExclTax price_type currency sku title sort_order } } ... on CustomizableCheckboxOption { checkboxValues: value { uid option_type_id price priceInclTax priceExclTax price_type currency sku title sort_order } } ... on CustomizableMultipleOption { checkboxValues: value { uid option_type_id price priceInclTax priceExclTax price_type currency sku title sort_order } } ... on CustomizableFieldOption { fieldValues: value { price priceInclTax priceExclTax price_type currency sku max_characters } product_sku } ... on CustomizableAreaOption { areaValues: value { price priceInclTax priceExclTax price_type currency sku max_characters } product_sku } ... on CustomizableFileOption { fileValues: value { price priceInclTax priceExclTax price_type currency sku file_extension } } ... on CustomizableDateOption { value { price priceInclTax priceExclTax price_type currency sku } product_sku } title required sort_order type uid } } ... on ConfigurableProduct { configurable_options { attribute_code values { value_index } } variants: variants_plp { product { uid id sku name type_id stock_status salable_qty stock_item { min_sale_qty max_sale_qty qty_increments } price_range { minimum_price { discount { amount_off percent_off } final_price { currency value } final_price_excl_tax { currency value } regular_price { currency value } regular_price_excl_tax { currency value } default_price { currency value } default_final_price { currency value } default_final_price_excl_tax { currency value } } maximum_price { discount { amount_off percent_off } final_price { currency value } final_price_excl_tax { currency value } regular_price { currency value } regular_price_excl_tax { currency value } default_price { currency value } default_final_price { currency value } default_final_price_excl_tax { currency value } } } attributes: s_attributes { attribute_id attribute_value attribute_code attribute_label attribute_type attribute_group_id attribute_group_name } } } } ... on BundleProduct { dynamic_price dynamic_sku ship_bundle_items dynamic_weight items { uid option_id title required type position sku options { uid label quantity position is_default price price_type can_change_quantity product { name stock_status price_range { minimum_price { discount { amount_off percent_off } final_price { currency value } final_price_excl_tax { currency value } regular_price { currency value } regular_price_excl_tax { currency value } default_price { currency value } default_final_price { currency value } default_final_price_excl_tax { currency value } } maximum_price { discount { amount_off percent_off } final_price { currency value } final_price_excl_tax { currency value } regular_price { currency value } regular_price_excl_tax { currency value } default_price { currency value } default_final_price { currency value } default_final_price_excl_tax { currency value } } } } } } bundle_options { option_id selection_details { selection_id final_option_price final_option_price_excl_tax regular_option_price regular_option_price_excl_tax } } } ... on GroupedProduct { items { product { uid id sku name type_id stock_status salable_qty stock_item { min_sale_qty max_sale_qty qty_increments } price_range { minimum_price { discount { amount_off percent_off } final_price { currency value } final_price_excl_tax { currency value } regular_price { currency value } regular_price_excl_tax { currency value } default_price { currency value } default_final_price { currency value } default_final_price_excl_tax { currency value } } maximum_price { discount { amount_off percent_off } final_price { currency value } final_price_excl_tax { currency value } regular_price { currency value } regular_price_excl_tax { currency value } default_price { currency value } default_final_price { currency value } default_final_price_excl_tax { currency value } } } attributes: s_attributes { attribute_id attribute_value attribute_code attribute_label attribute_type attribute_group_id attribute_group_name } } position qty } } ... on DownloadableProduct { links_purchased_separately } } page_info { current_page total_pages } } }

Variables:
{ "sort_1": { "name": "ASC" }, "filter_1": { "price": {}, "category_id": { "eq": 40 }, "customer_group_id": { "eq": "0" } }, "pageSize_1": 24, "currentPage_1": 1, "_currency": "" }

$skusToCheck = array_flip($skuArray);

foreach ($skuArray as $sku) {
if ($this->isSourceItemManagementAllowedForSku->execute($sku)) {
Copy link
Member

Choose a reason for hiding this comment

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

Argument #1 ($sku) must be of type string, int given, I think here typecasting is needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The sku's come from AreProductsSalable service, its unprocessedSkuQueue
public function addSkuToQueue(string $sku): void

^it already is type casted, did you get an actual int here, somehow, or is this an IDE warning?

Copy link
Member

@AzizKHAN030 AzizKHAN030 Jul 20, 2022

Choose a reason for hiding this comment

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

I got this error from system.log in the instance

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Clear, wonder how the hell it got here. Will add type casting just in case, thanks

@aleksandrsm
Copy link
Contributor Author

@AzizKHAN030
Updated PR, can no longer reproduce the issue on my local copy of pmrev-dev.
Could you test it again, just in case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants