"Unit price only" doesn't show default variant

  • Posts: 52
  • Thank you received: 0
9 years 10 months ago #219310

-- url of the page with the problem -- : www.filkab.solar
-- HikaShop version -- : 2.6.0

Hi,
I have set Price display method to "Unit price only". It works fine when I have different price for quantities without variants.
When I have variants it doesn't show the default variant price but the cheapest one (or the price of the first variant, I'm not quite sure which). Is it supposed to be like this and how can I change it to show the price of the default variant.

P.S. It get's a little confusing for a customer seeing one price on the products listing and after that different price on the product page. It should be the same price before choosing another variant. At the same time the default variant is chosen based on different and sometimes complicated criteria so we cannot keep it the cheapest one or the first one in the list.

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

  • Posts: 5
  • Thank you received: 0
9 years 10 months ago #219388

I am having the same problem exactly too and would like to know the solution as well :)

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

  • Posts: 84306
  • Thank you received: 13701
  • MODERATOR
9 years 10 months ago #219412

Hi,

When you select "unit price only", it will first look at the prices of the main product and will use the unit price there if any.
If none, then it will load the prices of the variants and will take the first one which is a unit price. It's not really random, it's in the order of creation of the prices in the database. But it sure can seem random.
The solution is to simply set the price that you want to display on the listing in the main product.

The following user(s) said Thank You: goldian

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

  • Posts: 52
  • Thank you received: 0
9 years 10 months ago #219602

Hi nicolas,
The problem in my case is that I have custom fields related with the SKU number of our products. Since we have ERP system in our company I'm trying to integrate Hikashop with it as much as possible. For that reason I don't want to mess up with the main product, because it would be very difficult for me to update automatically stock availabilities and prices later. Having redundant data in the database would only introduce more troubles for me.
Please advise me how to change the php code in order to display the default variant price if that is possible.
Thank you in advance.

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

  • Posts: 84306
  • Thank you received: 13701
  • MODERATOR
9 years 10 months ago #219638

Hi,

The thing is that the variants data of each product is not loaded on the products listings.
We avoid doing that as it would make the page processing crash on a lot of websites.
Suppose that you have 100 variants for each product. That's already a lot but it's manageable on the product page.
But if you display a products listing and need to load the data of all the variants of all the products, even with only 20 products on your listing, that's already 2020 product entities loaded and processed.
That's just too much data for the resources restrictions in place on normal hostings.
So that will make your job more difficult as you first need to load the variants data to know which variant is the default one and then load its price.
You want to edit the getListingPrices function of the file administrator/components/com_hikashop/classes/currency.php
There, you'll find two main blocks of code. The first one load the prices of the main product and get the cheapest/unit/range one(s). The second load load the prices of the variants of the product and get the cheapest/unit/range one(s).
So in between these two blocks, right after the line

if(!empty($variantSearch)){
you want to:
- first to do a MySQL query in the hikashop_variant table in order to get the characteristic_ids linked to the main products product_id.
- second, to do a MySQL query in the hikashop_product table in order to load the product_ids of all the variants of the main products based on the product_parent_id being equal to the product_id of the main products
- third, to do a MySQL query in the hiakshop_variant table in order to get the entries matching the characteristic_ids of your first query with the product_ids of your second query. That will give you the product_ids of the default variants of the main products
- fourth, to do a MySQL query in the hikashop_price table in order to load the prices of these default variants based on their product_ids
- fifth, to do the same PHP processing on them and get the cheapest/unit/range one(s).

So it's not just a few lines of code to add and will make the loading of the page a bit slower. That's why we decided not to do it by default and use the trick of providing the price for the listing in the main product instead.

The following user(s) said Thank You: ydingilski

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

  • Posts: 52
  • Thank you received: 0
9 years 10 months ago #219801

Hi nicolas,
Thank you for explaining the issue so thoroughly. Seeing the problem from that point of view it's clear why my request cannot be fulfilled.
At least everybody with the same issue would know why they have to use the workaround and how to organize their listings.
Once again thank you :)

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

Time to create page: 0.076 seconds
Powered by Kunena Forum