Display out of stock products with variants

  • Posts: 1057
  • Thank you received: 11
  • Hikashop Business
6 years 1 week ago #300466

-- HikaShop version -- : 3.2.2
-- Joomla version -- : 3.8.6
-- PHP version -- : 7.0

Hello,

I enabled the option "Display out of stock products" and it works fine, when the product's variants are 0 they are hidden.
Problem is that if all the variants have 0 quantity but the main product's quantity is unlimited, the product is still published but it has no variants to select.
When all variants are 0 i want the whole product to be unpublish.

Thank you

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
6 years 1 week ago #300467

Hi,

Then I would recommend to set the stock of the main product as the sum of the quantity of all the variants. That way, when the stock of the last variant with stock hits 0 the main product will also hit 0 and it won't appear on the products listings.

Please Log in or Create an account to join the conversation.

  • Posts: 1057
  • Thank you received: 11
  • Hikashop Business
6 years 1 week ago #300497

Hi nicolas,

the thing is that there are thousands of products and they are imported in hikashop, with your solution i need to do this for each product seperately? That really does not work for me, is there any other way to do this for all products automatically?

Thank you

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
6 years 1 week ago #300501

Hi,

If you don't want to do that manually, then you can develop a custom plugin and implement the onBeforeProductListingLoad trigger:
www.hikashop.com/support/documentation/6...reProductListingLoad
With it, you can modify dynamically the MySQL query loading the products on the listings.
So you could for example add an extra left join on the hikashop_product table grouping by the product_parent_id with a sum of the product_quantity of the variants with an extra condition on that sum to be either NULL or bigger than 0.
However, we can't do that by default in HikaShop. That means that the MySQL query loading the products on the listings will be slowed down a lot. With a lot of products/variants it could even make the MySQL query crash.
Alternatively, you could also have a custom plugin to update the main product stock when the stock of the variants is changed. But if you use the import system to import the stock, then that won't work as the triggers are not called during imports for efficiency.
Aternatively again, you could modify your CSV you're importing to add the main product stock. You could have an Excel macro automatically filling that data for you in your CSV.

The following user(s) said Thank You: verzevoul

Please Log in or Create an account to join the conversation.

Time to create page: 0.058 seconds
Powered by Kunena Forum