Mass Actions Add Product Variants

  • Posts: 8
  • Thank you received: 0
2 years 2 months ago #338523

-- HikaShop version -- : 4.2.3
-- Joomla version -- : 3.9.24
-- PHP version -- : 7.4.27

I have a website with so many Tech Gadgets and I am looking for a quicker way to create filters for some pages with many items like laptops. I didnt plan for filters in the early stages so I did not configure characteristics, specifications and product variants in the early stages.

Now I need some filters to work but without proper product variants -- hikashop filter modules dont return any result.
I am thinking I can create a mysql script with cursors in mysql and run it via mass actions/ or PhpMyadmin using simple sql tricks like a product_name with '%core i5%' can be set for the Core i5 filter under CPU types. And so forth for other CPU options. This can help me narrow down the work and remain with a few variants to activate manually those dont any good details in their product names. I am sure this a situation u can meet any time when a hikashop website grows. What is the easiest way about it. I have so far moved a small step to make the script but I am missing something; I cant set a default variant selected. When I try to make my variants default, hikashop undoes the changes I added as the data because my data integrity is missing somethings I guess. Any guidance please
-

Attachments:

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

  • Posts: 81379
  • Thank you received: 13037
  • MODERATOR
2 years 2 months ago #338525

Hi,

You need three things to add variants to a product:
- add the variants entries in the hikashop_table. I can see this is done with your second INSERT query
- add entries in the hikashop_variant table linking the default values in hikahop_characteristic and the main product entry in hikashop_product. I can see this is done with your first INSERT query.
- add entries in the hikashop_variant table linking each variant in hikashop_product to their corresponding values in hikashop_characteristic. I don't see this query in your txt file.
So I suppose you're missing the third query and that's why it behaves incorrectly.

Note that the goal of variants is to allow the customer to select several values on the product page so that they can choose among several variants of the same product, and based on what is selected the price/stock/image/etc can be different.
That's what is shown here: demo.hikashop.com/index.php/en/hikashop/...with-characteristics
I can see that you only have one variant for each product which means the selection on the product page is meaningless.
In that case, I would recommend to use custom fields of the table "product" instead of characteristics, like we did with the "specifications" page here: demo.hikashop.com/index.php/en/hikashop/.../with-specifications
A custom field of the table "product" will add a corresponding column in the hikashop_product table.
You can use the type "single dropdown" so that in the custom field "values" section, you can enter the different values allowed.
And then in each product you can select the value you want in the custom field.
And you can link a filter to that custom field so that it will use the values of the custom field to filter the product.
Another nice thing if doing it like that is that you can easily set the value of the custom field for a bunch of products with a simple query:

UPDATE #__hikashop_product SET xxx = 'yyy' WHERE product_name LIKE "%i5%";
where xxx is the column name of the custom field and yyy the value you want to set.

In fact, these can easily be done via the interface in the backend for people who don't know MySQL :
- create a new mass action in the System>Mass actions menu
- add a filter on the product_name with the mode "like" selected and the value %i5%
- add an action "update the values" on the product_name column with the mode "string" and yyy in the input field.
- when you press "process", it will run the mass action and basically run the UPDATE query for you.

Having custom product fields instead of characteristics will also be less resource-hungry when using filters, and will allow things like add to cart from the products listings (which is not possible for products with variants).

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

  • Posts: 8
  • Thank you received: 0
2 years 2 months ago #338569

Hello Nicholas; Thank You for this great reply, it makes much sense and will surely achieve what I want more easily than my earlier approach.
#1. Meanwhile can we make Hikashop be able to filter these results like in my case after I have set the specifications and default values on a product without need for activation of variants? I realized Hikashop filters only on variants if u base the filter on characteristics.
#2. When you activate variants, the 'add to cart' button turns to 'choose options'. In a situation where variants have many options set; it takes longer selecting through options before a user sees the 'add to cart' button and this confuses majority mobile phone users. Can we make the 'add to cart' button independent of the option selections ie it can be seen always as one selects through options.

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

  • Posts: 81379
  • Thank you received: 13037
  • MODERATOR
2 years 2 months ago #338570

Hi,

1. I'm not sure what you're asking. If you have set the characteristics/variants with the same data as custom product fields, then switching the filters to use the custom fields instead of the characteristics is really easy. You just have to edit each filter and change the "apply on" to use custom fields instead of characteristics and select the corresponding custom field.

2. With a bit of customization you can allow the display of the add to cart button on the listing, even if the product has variants/options. However, this means that you'll add the main product to the cart when you click on the button.
You need to edit the add_to_cart_ajax.php view file via the menu Display>Views.
There, you have this line:

$has_options = !empty($this->row->has_options) || (!$display_fields && $has_required_fields);
near the beginning, which defines if the current product on the listing has options/characteristics
So you can just change the line to:
$has_options = false;
However, note that this might have some unforseen consequences down the line as you're not supposed to be able to add to the cart the main product normally but only the variants when a product has variants.

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

Time to create page: 0.039 seconds
Powered by Kunena Forum