Sale method doesn't change with variants

  • Posts: 40
  • Thank you received: 2
2 years 9 months ago #334523

-- HikaShop version -- : 4.4.3

We sell products per weight. So I have chicken fillet here which we sell per 500 grams or per 1 kilo.

The standard sale method is per kilo. But when someone chooses 500 grams, it will still say "per kilo" and then the price isn't correct anymore. The price changes to the 500 gram price, but behind the right price it stil says "per kilo" when it should change to "per 500 gram"

I've tried to change the sale method per variant, which I thought should help, but it doesn't.

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

  • Posts: 81515
  • Thank you received: 13068
  • MODERATOR
2 years 9 months ago #334526

Hi,

I would rather recommend you leave the "per unit" text empty for all the products, so that the main price displayed in the price of the variant, and then that you activate the "Display the cost per unit weight" setting of the HikaShop configuration. That setting was made specifically for your use case.
If you set a weight unit of "kg" and the weight in each variant, the system will then automatically display the price per kilo below the price of the variant, calculated automatically for you.
I believe it's easier to manage for you, doesn't require any code modification, and is also nicer for the customer since he can really compare the prices of products for the same weight.

Now to answer your question:
There is no mechanism to display a different "per unit" text for different products in HikaShop. So I suppose that you followed the instructions in the section "I sell packed products, how can I change "each" text in the product page ?" of our FAQ www.hikashop.com/support/documentation/106-faq.html
And indeed, with the code proposed there, the unit will be the same for all the variants of a product.
Supposing that you're talking about these instructions, the code there should be changed to :

if(isset($this->row->salemethod)) echo JText::_($this->row->salemethod);
and in that case, it will use the "per unit" defined in the "salemethod" custom field of each variant.

The following user(s) said Thank You: Dijkshoorn

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

  • Posts: 40
  • Thank you received: 2
2 years 9 months ago #334542

Thank you for the quick response. Really great service as always!

The "Display the cost per unit weight" is a new option?

Most of my products are sold by unit (about 2/3). Would this option still be good, or should I take the second option and change the code?

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

  • Posts: 81515
  • Thank you received: 13068
  • MODERATOR
2 years 9 months ago #334546

Hi,

No, this option has been there for almost 10 years.

Regarding your second question, I can't answer it as it depends on what you want.
For example, for the product "Pondan Cake Mix" you're selling it per unit. That's normal. However, in a normal supermarket (where I live at least), for such a product, the price per kilo is still displayed on the price tag on the shelf as that's required by the law.
So to me, having the price per kilo displayed for that kind of product (any kind of food / beverage item) makes sense.
And for the other products, if you don't enter a weight, then the price per kilo won't be displayed on the product page.
Now, I can see that for the category "verhuur" you have non food / beverage items. So it doesn't make much sense to display the price per kilo there. So you could just not specify the weight in these products. However, if your shipping methods base themselves on the weight of the items in the cart, then you can't use this mechanism as is, since you need to the weight for the shipping methods, but you don't want it to not have the price per kilo displayed for them. In that case, it woul still be possible, to use that mechanism, but you would have to modify a bit the code in product / listing_price.php so that the price per kilo would only appear based on the value selected in another custom product field.

The following user(s) said Thank You: Dijkshoorn

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

  • Posts: 40
  • Thank you received: 2
2 years 9 months ago #334555

Thank you very much for your extensive answer!

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

  • Posts: 40
  • Thank you received: 2
7 months 3 weeks ago #354815

nicolas wrote: Hi,

I would rather recommend you leave the "per unit" text empty for all the products, so that the main price displayed in the price of the variant, and then that you activate the "Display the cost per unit weight" setting of the HikaShop configuration. That setting was made specifically for your use case.
If you set a weight unit of "kg" and the weight in each variant, the system will then automatically display the price per kilo below the price of the variant, calculated automatically for you.
I believe it's easier to manage for you, doesn't require any code modification, and is also nicer for the customer since he can really compare the prices of products for the same weight.

Now to answer your question:
There is no mechanism to display a different "per unit" text for different products in HikaShop. So I suppose that you followed the instructions in the section "I sell packed products, how can I change "each" text in the product page ?" of our FAQ www.hikashop.com/support/documentation/106-faq.html
And indeed, with the code proposed there, the unit will be the same for all the variants of a product.
Supposing that you're talking about these instructions, the code there should be changed to
if(isset($this->row->salemethod)) echo JText::_($this->row->salemethod);[/code] and in that case, it will use the "per unit" defined in the "salemethod" custom field of each variant.


I've come back to this answer to try again. I've never really gotten it to work.

I'm very close now. I've changed the code and when I'm in the product view in the webshop it works. When I select a different weight the sale method changes. The only problem I've got is that I like to display all prices in the product overview. But there it still displays the "per kilo" sale method for every weight characteristic. Is it possible to change that as well? I've turned the option to display all prices in the product overview off, so for now it's not a big problem, but I'd like to turn it on again so people can see the options.

Last edit: 7 months 3 weeks ago by Dijkshoorn.

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

  • Posts: 81515
  • Thank you received: 13068
  • MODERATOR
7 months 3 weeks ago #354826

Hi,

Indeed, the FAQ doesn't cover the case when the product has several prices for different minimum quantities. That's because it would make it too complex.

For that case, you'll have to change the line:

echo '<span class="hikashop_product_price_per_unit_x">'.JText::sprintf('PER_UNIT_AT_LEAST_X_BOUGHT',$price->price_min_quantity).'</span>';
in the same view file product / listing_price
I would recommend changing it to:
if(!empty($this->element->main->salemethod)) echo '<span class="hikashop_product_price_per_unit_x">'.JText::sprintf($this->element->main->salemethod. '_AT_LEAST_X_BOUGHT', $price->price_min_quantity);
elseif(!empty($this->row->salemethod)) echo '<span class="hikashop_product_price_per_unit_x">'.JText::sprintf($this->row->salemethod. '_AT_LEAST_X_BOUGHT', $price->price_min_quantity);
elseif(!empty($this->element->salemethod)) echo '<span class="hikashop_product_price_per_unit_x">'.JText::sprintf($this->element->salemethod. '_AT_LEAST_X_BOUGHT', $price->price_min_quantity);
else echo '<span class="hikashop_product_price_per_unit_x">'.JText::sprintf('PER_UNIT_AT_LEAST_X_BOUGHT',$price->price_min_quantity).'</span>';
Then, you'll have to add translation overrides for the different translation keys. For example, if you have a "PER_PACK" value in your custom product field, you want to add the translation override:
PER_PACK_AT_LEAST_X_BOUGHT=" per pack for buying at least %s"
(you can adapt the text to display what you want, it's just an example.

Last edit: 7 months 3 weeks ago by nicolas.
The following user(s) said Thank You: Dijkshoorn

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

  • Posts: 40
  • Thank you received: 2
7 months 2 weeks ago #354872

Thanks Nicolas. This is useful for the quantity discounts, but different sale methods for different variants are still not displayed properly with this code. I feel like I should be able to figure out how to do it looking at your code for the quantity discounts, but I sadly don't have enough (no) coding skills.

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

  • Posts: 81515
  • Thank you received: 13068
  • MODERATOR
7 months 2 weeks ago #354878

Hi,

Indeed, with the code I provided, the priority is given to the main product sale method.
If you want to change that, you would need to adapt the code to something like this:

if(!empty($this->row->salemethod)) echo '<span class="hikashop_product_price_per_unit_x">'.JText::sprintf($this->row->salemethod. '_AT_LEAST_X_BOUGHT', $price->price_min_quantity);
elseif(!empty($this->element->salemethod)) echo '<span class="hikashop_product_price_per_unit_x">'.JText::sprintf($this->element->salemethod. '_AT_LEAST_X_BOUGHT', $price->price_min_quantity);
elseif(!empty($this->element->main->salemethod)) echo '<span class="hikashop_product_price_per_unit_x">'.JText::sprintf($this->element->main->salemethod. '_AT_LEAST_X_BOUGHT', $price->price_min_quantity);
else echo '<span class="hikashop_product_price_per_unit_x">'.JText::sprintf('PER_UNIT_AT_LEAST_X_BOUGHT',$price->price_min_quantity).'</span>';

The following user(s) said Thank You: Dijkshoorn

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

Time to create page: 0.069 seconds
Powered by Kunena Forum