Skip to main content

Show price of variant

More
9 years 3 months ago - 9 years 3 months ago #272000 by bolando
Replied by bolando on topic Show price of variant
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
Code:
$values[$k] = $value->characteristic_value;
put:
Code:
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: 9 years 3 months ago by nicolas.

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

More
9 years 3 months ago #272054 by nicolas
Replied by nicolas on topic Show price of variant
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.

More
9 years 3 months ago #272686 by bolando
Replied by bolando on topic Show price of variant
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.

More
9 years 2 months ago #272694 by nicolas
Replied by nicolas on topic Show price of variant
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.

More
9 years 2 months ago #273835 by thschuler
Replied by thschuler on topic Show price of variant
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.

More
9 years 2 months ago #273890 by bolando
Replied by bolando on topic Show price of variant
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.

More
8 years 3 months ago - 8 years 3 months ago #293628 by savvygents
Replied by savvygents on topic Show price of variant
I just found this post. I have followed all of your suggestion but it did not work. Am I missing some thing?
Code:
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: 8 years 3 months ago by nicolas.

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

More
8 years 3 months ago #293632 by nicolas
Replied by nicolas on topic Show price of variant
Hi,

If you want to have the price added to the variants, you can just change the code:
Code:
$values[$k] = $value->characteristic_value;
to:
Code:
$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.

More
4 years 8 months ago #338717 by BluepointWebdesign
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.

More
4 years 8 months ago #338719 by nicolas
Replied by nicolas on topic Show price of variant
Hi,

This won't work anymore as we moved things around.
You now have to change the line:
Code:
$values[$k] = $value->characteristic_value;
in the file show_block_characteristic via the menu Display>Views and replace it by:
Code:
$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.

More
4 years 8 months ago #338803 by BluepointWebdesign
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.

More
4 years 8 months ago #338808 by Mohamed Thelji
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.

More
4 years 8 months ago #338841 by BluepointWebdesign
Hi,
I editted the right view..
Just checked it.

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

More
4 years 8 months ago #338865 by nicolas
Replied by nicolas on topic Show price of variant
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:
Code:
$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.324 seconds
Powered by Kunena Forum