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
"Catalog Products List" includes "Out of Stock" products when "Quantity is In Stock" is a required condition of the widget and the products are given the quantity "Out of Stock" from within admin #4108
Comments
For example if I create a widget with the condition stated and accept all other default settings I get the following mustache code: |
The widget type calls the following method: By placing a breakpoint in this method on the last line before the method returns the collection of products you can run the following line:
The SQL produced follows |
The comment above shows that only catalog_product_entity_int is queried to find wether a product is out of stock or in stock. However, that table is not updated by changing inventory in admin. I haven't tried running a product out of stock through the front end but I am concerned that the same issue probably exists under that circumstance as well. I will return here and update this issue at a later date after testing this scenario. |
It appears that when saving a product in the admin, the Magento\Catalog\Model\Product\Attribute\Backend\Stock::beforeSave() method takes the data property 'quantity_and_stock_status' which contains 'qty' and 'is_in_stock' data for the product and then sets that data to the product's 'stock_data' property, overwriting any existing values there. It then unsets 'quantity_and_stock_status' entirely. When it passes back to the parent::beforeSave() method, that method finds that 'quantity_and_stock_status' is now empty and sets its value to a default value which is '1'. This value gets set to the attribute database table (catalog_product_entity_int) and is always set to '1', regardless of whether or not the item is in stock. The real values are written elsewhere. When setting up a Product List widget, there is a conditions field that uses a Condition block (located in the Catalog Widget module). When setting up rules, the "quantity" rule (which allows you to specify 'in stock' or 'out of stock') is configured to use the 'quantity_and_stock_status' product attribute, but as we saw before, this is always being set to 1 regardless. The way the quantity and stock values are currently configured to be written to the database, this condition rule will never work properly. All products will be seen as "in stock". As it stands, if you manually set a product's 'quantity_and_stock_status' attribute in the database table to '0', the widget will not display that product, as that is evidently how this was originally written to work. However, once you save that product again in the admin, that attribute will be overwritten and set to '1'. So was this change intentional? If not, these beforeSave() methods will need to be rewritten to not incorrectly set the 'quantity_and_stock_status' attribute. But if so, then the Condition block will need to take this change in the location of "in stock" values into account when it sets up the rules that will ultimately go into the widget's instance, because currently the rule uses the 'quantity_and_stock_status' attribute. |
Internal issue MAGETWO-53445 |
…k" products when "Quantity is In Stock" is a required condition of the widget and the products are given the quantity "Out of Stock" from within admin #4108
…k" products when "Quantity is In Stock" is a required condition of the widget and the products are given the quantity "Out of Stock" from within admin #4108 - Extracted variable to di.xml
This issue was fixed in develop branch. |
@tomispepe thank you for your report. |
@magento-engcom-team |
@magento-engcom-team any news? |
This worked for me: As I have a specific function to update inventory that extends \Magento\CatalogInventory\Model\StockRegistry, I called inside it, but if you use Magento itself you should create a plugin to be called after you have run the function Magento\CatalogInventory\Model\StockRegistry::updateStockItemBySku(). At each inventory update, this function updates the is_in_stock status of the parent product by adding the items of the child products: `
Hope this helps! Thank you! |
Steps to reproduce
Expected result
Actual result
The text was updated successfully, but these errors were encountered: