Show price of variant

  • Posts: 81
  • Thank you received: 5
4 years 11 months ago #272000

Hey,

I was also looking for an option to show price of a variant and after some trying I found out that this code works:
In file
/administrator/components/com_hikashop/types/characteristic.php
line about 227
instead of

$values[$k] = $value->characteristic_value;
put:
foreach($element->variants as $variant){
									foreach($variant->characteristics as $variantCharacteristic){
										
										if($variantCharacteristic->characteristic_id==$value->characteristic_id){
											$cenaWariantu = $variant->prices[0]->price_value_with_tax;
											$cena[] =sprintf("%01.2f", $cenaWariantu);
											
											}
									}

								}

							
							$values[$k]=$value->characteristic_value." - PLN ".$cena[$k-1];
Works at least for me.

But I also know that after HikaShop upgrade I will lose it. Is there a chance to implement this option by HikaShop Team?

Last edit: 4 years 11 months ago by nicolas.

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

  • Posts: 75517
  • Thank you received: 11750
  • MODERATOR
4 years 11 months ago #272054

Hi,

We're thinking about doing something but it's a complex issue. Most of the time, you don't want the price there. Especially, since it can only work with one characteristic on the products. But even with only one characteristic, there are many cases when you don't want to display the price there.
We'll have to figure out something but we try to avoid adding too many options.
In fact, we're thinking of redoing the whole characteristic system in order to be ajax like we did with HikaShop 3 and the cart/checkout system. So when we do, we'll make sure that you can override the display properly.
But that won't happen in the short term.
For now, you'll have to keep your hack of the core or develop a small class override plugin to override the whole class of the file to have your change taken into account.
Here is a thread where we talk about class overrides:
www.hikashop.com/forum/2-general-talk-ab...custom-features.html

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

  • Posts: 81
  • Thank you received: 5
4 years 10 months ago #272686

Hey,

I am trying to create a plugin as you said.
Can you take a look at the code?
github.com/bolando/plg_hika_char_prices/
Is the logic OK?
It doesn't seem to work now.

The following user(s) said Thank You: trevsmiff

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

  • Posts: 75517
  • Thank you received: 11750
  • MODERATOR
4 years 10 months ago #272694

Hi,

Change the class name to hikashopCharacteristicTypeOverride and it should be taken into account by HikaShop automatically.
You can add temporarily an exit; at the beginning of the load function just to make sure that your override class is used by HikaShop.

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

  • Posts: 4
  • Thank you received: 0
4 years 10 months ago #273835

Hi bolando,
your code nearly worked for me.
I had to change $cena[ ] to $cena in both lines, and then it worked.
Why did you make $cena[ ] and array?

Thanks
Thomas

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

  • Posts: 81
  • Thank you received: 5
4 years 10 months ago #273890

I am not a good coder, so maybe your code is better. I am glad that it works.

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

  • Posts: 5
  • Thank you received: 0
3 years 11 months ago #293628

I just found this post. I have followed all of your suggestion but it did not work. Am I missing some thing?

foreach($element->variants as $variant){
									foreach($variant->characteristics as $variantCharacteristic){
										
										if($variantCharacteristic->characteristic_id==$value->characteristic_id){
											$cenaWariantu = $variant->prices[0]->price_value_with_tax;
											$cena=sprintf("%01.2f", $cenaWariantu);
											
											}
									}

								}

							
							$values[$k]=$value->characteristic_value." - PLN ".$cena;

Last edit: 3 years 11 months ago by nicolas.

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

  • Posts: 75517
  • Thank you received: 11750
  • MODERATOR
3 years 11 months ago #293632

Hi,

If you want to have the price added to the variants, you can just change the code:

$values[$k] = $value->characteristic_value;
to:
$currencyHelper = hikashop_get('class.currency');
$values[$k]=$value->characteristic_value.' ('.$currencyHelper->format($element->variants[$value->variant_product_id]->prices[0]->price_value,$element->variants[$value->variant_product_id]->prices[0]->price_currency_id).')';
in that file administrator/components/com_hikashop/types/characteristic.php and that should do it.

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

  • Posts: 355
  • Thank you received: 6
  • Hikamarket Multivendor Hikashop Business
4 months 1 day ago #338717

hi,

This gives the variants value and only price (€ 0,00) behind all the variants..
or am i missing something?

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

  • Posts: 75517
  • Thank you received: 11750
  • MODERATOR
4 months 1 day ago #338719

Hi,

This won't work anymore as we moved things around.
You now have to change the line:

$values[$k] = $value->characteristic_value;
in the file show_block_characteristic via the menu Display>Views and replace it by:
$values[$k]=$value->characteristic_value.' ('.$this->currencyHelper->format($this->element->variants[$value->variant_product_id]->prices[0]->price_value,$this->element->variants[$value->variant_product_id]->prices[0]->price_currency_id).')';

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

  • Posts: 355
  • Thank you received: 6
  • Hikamarket Multivendor Hikashop Business
4 months 1 hour ago #338803

Did what you said but still get the (€0,00) after each variant.. or do i miss something.?

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

  • Posts: 12953
  • Thank you received: 1774
3 months 4 weeks ago #338808

Hello,

Can you check via "Hikashop->Display->Views" that you have edited the "show_block_characteristic" file of the "product" view of your front-end template that you are currently using on your website :
www.hikashop.com/support/documentation/1...-display.html#layout

Kind regards,
Mohamed.

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

  • Posts: 355
  • Thank you received: 6
  • Hikamarket Multivendor Hikashop Business
3 months 4 weeks ago #338841

Hi,
I editted the right view..
Just checked it.

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

  • Posts: 75517
  • Thank you received: 11750
  • MODERATOR
3 months 4 weeks ago #338865

Hi,

I checked the code and did some debugging and the issue is that the variants array keys are modified before reaching the view file to sort them based on the order configured in the shop while it's not yet the case in the location where the code was to be modified in old versions of HikaShop.
This means that the code needs to be a bit more complex, like this:

$current =  null;
foreach($this->element->variants as $variant){
if($variant->product_id == $value->variant_product_id) $current = $variant;
}
$values[$k]=$value->characteristic_value.' ('.$this->currencyHelper->format($current->prices[0]->price_value,$current->prices[0]->price_currency_id).')';
I successfully tested this code on my end.

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

Time to create page: 0.122 seconds
Powered by Kunena Forum