Product > Quantity: 0 - category / by default

  • Posts: 461
  • Thank you received: 36
2 years 4 months ago #345522

-- HikaShop version -- : 4.6.1
-- Joomla version -- : 3.10.11
-- PHP version -- : 7.4.32
-- Browser(s) name and version -- : Chrome

Hi guys,
we can enable the Catalogue by setting "Configuration > Features > Catalogue mode: Yes" for the entire site.
But, also we can leave it as "No" and choose to enable the Catalogue mode by setting "Product > Quantity: 0" for each products we want. Now:

1 - Is there a way to enable the Catalogue mode by Category (for all the Products included into a specific Category) ?

2 - From a HikaMarket Multi Vendor point of view, as Super User we can always display:none; / pointer-events: none; fields to limit HikaShop features(depending on Vendors User Groups levels), but not the reverse. So, by default it would be better to have "Product > Quantity: 0" and not unlimited.
Do you agree ?
…/administrator/components/com_hikashop/views/product/view.html.php
line 1772 - $product->product_quantity = $config->get('default_stock_for_new_products', -1); >>> 0

Last edit: 2 years 4 months ago by joomleb.

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

  • Posts: 83338
  • Thank you received: 13476
  • MODERATOR
2 years 4 months ago #345530

Hi,

1. You could do it with a few custom fields and mass actions:
- a custom "category" field with two values "yes" and "no" and the name "catalogue_mode".
- a custom "product" field with the name "saved_quantity".
- a mass action with a trigger "after a category is updated", a filter on the column "catalogue_mode" equal to "yes", and an action "run MySQL query" with the MySQL query:

UPDATE #__hikashop_product SET saved_quantity = product_quantity, product_quantity=0 WHERE product_id IN (SELECT product_id FROM #__hikashop_product_category WHERE category_id={category_id})
- a mass action with a trigger "after a category is updated", a filter on the column "catalogue_mode" equal to "no", and an action "run MySQL query" with the MySQL query:
UPDATE #__hikashop_product SET product_quantity = saved_quantity WHERE product_id IN (SELECT product_id FROM #__hikashop_product_category WHERE category_id={category_id})

2. This is a hidden option. You don't need to change the code for that. Go in your PHPMyAdmin, add a new entry to the hikashop_config table with the namekey default_stock_for_new_products and the value 0 and it will do it. And no worries with updates. The hidden option was made specifically for such cases.

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

  • Posts: 461
  • Thank you received: 36
2 years 4 months ago #345720

Hi Nicolas,

2 - hidden option
PHPMyAdmin > hikashop_config table > namekey: default_stock_for_new_products - value 0
It works perfectly, many thanks !
Please, Is there any documentation where can I read more about HikaShop hidden options and HikaShop namekeys ?
(I'm not able to find nothing)

1 - You could do it with a few custom fields and mass actions:
- a custom "category" field with two values "yes" and "no" and the name "catalogue_mode".
- a custom "product" field with the name "saved_quantity".
- a mass action with a trigger "after a category is updated", a filter on the column "catalogue_mode" equal to "yes", and an action "run MySQL query" with the MySQL query: ...
- a mass action with a trigger "after a category is updated", a filter on the column "catalogue_mode" equal to "no", and an action "run MySQL query" with the MySQL query: ...

1A - a custom "product" field with the name "saved_quantity":
Due to "point 2" above, we are working with "product_quantity = 0" by default.
Please, Why it is necessary the creation of the "saved_quantity" custom field and it is not possible to write "0" directly into the "product_quantity" field ?

1B - "Updated" includes also "Created" (the first time a new Category is created) ?

1C - And, as far as I understand, the same also for Products:
- a mass action with a trigger after a product is updated" (and created), when the product is added to a categorie with "catalogue_mode" = "Yes", then the "product_quantity = 0"
- a mass action with a trigger after a product is updated" (and created), when the product is added to a categorie with "catalogue_mode" = "No", if the "product_quantity = 0" (inherit from coming from a Category catalogue mode=Yes), then the "product_quantity = -1" (I suppose "unlimited" is better then "1")
Do you agree ?

Last edit: 2 years 4 months ago by joomleb.

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

  • Posts: 83338
  • Thank you received: 13476
  • MODERATOR
2 years 4 months ago #345729

Hi,

2. No. We've been working on an interface to be able to edit the hidden options from an advanced area in the HikaShop configuration. But for now there is no documentation on them.

1A. The goal of the saved_quantity field allows you to restore the original quantity when you disable the catalogue mode of the category. That way, if the product was already out of stock, it will keep the product out of stock. And if the product had a stock of 50 it will restore that stock of 50, and if the stock was -1 (unlimited) it will restore it to unlimited.
So this avoids the problem of out of stock products you don't want to enable back when you deactivate the catalogue mode, and it also helps if you have a store with non unlimited stock products.

1B. The mass actions I proposed have an action to run a MySQL query on the products of a category. When you create a new category, the category doesn't have any products yet, so there is no point in adding a trigger "after a category is created" for them.

1C. I don't. But I don't know the specifics of your situation, so that might be what you want to do.
However, the way I see it: when you add a product to a category, you know if you want to sell that product or not and thus you can directly enter the stock you want on the product edit screen at the same time you're selecting the category. This also allows you to purposefully create products you want to not sell to categories in catalogue mode so that even when you enable it, the product still won't be available.
Also, there is no way to add a condition when the product is added to a categorie with "catalogue_mode" = "No"/"Yes" to a product mass action. So you won't be able to write such a mass action.

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

  • Posts: 461
  • Thank you received: 36
2 years 4 months ago #345975

Hi Nicolas,
thanks!

1A - Very Good

1B - You are right

1C - Got it, it makes sense

2 - Okay

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

  • Posts: 12
  • Thank you received: 3
  • Hikashop Business Hikashop Essential
2 years 2 months ago #346967

Question to Nicolas,

nicolas wrote: Hi,

1. You could do it with a few custom fields and mass actions:
- a custom "category" field with two values "yes" and "no" and the name "catalogue_mode".
- a custom "product" field with the name "saved_quantity".
- a mass action with a trigger "after a category is updated", a filter on the column "catalogue_mode" equal to "yes", and an action "run MySQL query" with the MySQL query:

UPDATE #__hikashop_product SET saved_quantity = product_quantity, product_quantity=0 WHERE product_id IN (SELECT product_id FROM #__hikashop_product_category WHERE category_id={category_id})
- a mass action with a trigger "after a category is updated", a filter on the column "catalogue_mode" equal to "no", and an action "run MySQL query" with the MySQL query:
UPDATE #__hikashop_product SET product_quantity = saved_quantity WHERE product_id IN (SELECT product_id FROM #__hikashop_product_category WHERE category_id={category_id})

2. This is a hidden option. You don't need to change the code for that. Go in your PHPMyAdmin, add a new entry to the hikashop_config table with the namekey default_stock_for_new_products and the value 0 and it will do it. And no worries with updates. The hidden option was made specifically for such cases.


Some questions about this:
1. Is this still applicable for Joomla 4 and HikaShop 4.6.2?

2. Do I have to change the SQL statements according to my exact table name (#__ to jml_)?

3. Does it also work with different variants of a product?

It's just because I cannot see any changes in the product table after making a change to the category and I am wondering if the sql even runs properly. I haven't find the log on that, yet.

Thanks.

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

  • Posts: 83338
  • Thank you received: 13476
  • MODERATOR
2 years 2 months ago #346972

Hi,

1. Yes. Even with the 4.7.0.

2. If you run the MySQL queries via PHPMyAdmin, you indeed do need to change the table prefix so that PHPMyAdmin can run the MySQL queries. However, if you use a "run MySQL query" action in a mass action, HikaShop will change the table prefix automatically so you don't have to do it.

3. It depends. If the stock is only in the main product, it will work. If the stock is in each variant, then you would need extra mass actions configured the same, but with product_parent_id instead of product_id in the MySQL queries.

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

  • Posts: 12
  • Thank you received: 3
  • Hikashop Business Hikashop Essential
2 years 2 months ago #346987

Thanks, Nicolas.

Ik had to go over every category to set whether or not is was a catalog view. But then it worked like a charm.

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

Time to create page: 0.083 seconds
Powered by Kunena Forum