Custom fields not changing depending on variant

  • Posts: 345
  • Thank you received: 23
  • Hikaserial Standard Hikashop Business
5 months 1 week ago #337693

-- HikaShop version -- : 4.4.4
-- Joomla version -- : 3.10.3
-- PHP version -- : 7.4

Hi

I have added a custom field to a product and then added a charateristic.
The on the product added 2 variants with different entries in the custom field.

But on the page: passtheport.thr.nu/shop/ruby-port/lbv-la...inta-das-lamelas-lbv the field isn't changing when I chose a different variant?

"FLASKEÅR" should change ...
What to do here?

Regards
Thomas

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

  • Posts: 75517
  • Thank you received: 11750
  • MODERATOR
5 months 1 week ago #337707

Hi,

The "FLASKEÅR" there is in the description of the product.
So you would have to edit the variant and change the text of the description to have that change taken into effect when you use the characteristic dropdown.

I suppose you didn't configure the custom product field to appear on the product page and thus it's just not being displayed.

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

  • Posts: 345
  • Thank you received: 23
  • Hikaserial Standard Hikashop Business
5 months 1 week ago #337751

Hi

"FLASKEÅR" is not in the description, but has been coded in product/show_default.php like this:

<?php
if(isset($this->row->bottleyear) && !empty($this->row->bottleyear)){ ?>
<div class="hikashop_product_bottleyear">
<div><h4>Flaskeår</h4></div><div><?php echo $this->row->bottleyear; ?></div>
</div>
<?php }
?>

And each variant has different value in FLASKEÅR.

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

  • Posts: 3617
  • Thank you received: 488
  • MODERATOR
5 months 1 week ago #337766

Hello,

Select Characteristics will update parts of the page but not all, from this all we can tell you is that your custom code isn't in the good place.
BUT if each product variant can have different "Flaskear" why don't you use as suggested by Nicolas to use Description as if each variant description is different this part will be update by selecting characteristics.
Create dynamic data from variant to another is of course possible but not that easy, especially compare to Nicolas idea.

but, if for a reason or another you need to use this custom code, then you have to "associated" your code WITH a part that will be updated for each variant as description (or another part).

For description example, you will find this code part in the view product/show, look for this code "hikashop_product_description_<?php echo $variant_name; ?>" to find dynamic description code.

Hope this will help you to get what you need.
Regards

Last edit: 5 months 1 week ago by Philip.

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

  • Posts: 345
  • Thank you received: 23
  • Hikaserial Standard Hikashop Business
5 months 1 week ago #337844

Thanks Philip!

These custom fields are made to make it easier for my customer who owns the shop.
I'm pretty sure he will f**k things up, if he had to make this in the description :-)

I will look into your suggestion, thank you!!

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

  • Posts: 345
  • Thank you received: 23
  • Hikaserial Standard Hikashop Business
5 months 1 week ago #337851

So I have managed to get some of it to work, but I can't quite figure out how to change between the data.
I have set display to block, just to check if I got the data, but when I set it to display:none; I don't see anything, not even when changing variant.

Any advice?

This is the code I use:

- TEST START -  
   <?php

	foreach($this->element->variants as $variant) {
		$this->row =& $variant;
		$variant_name = array ();
		if(!empty($variant->characteristics)) {
			foreach($variant->characteristics as $k => $ch) {
				$variant_name[] = $ch->characteristic_id;
			}
		}

		$variant_name = implode('_', $variant_name);
		$this->variant_name = '_' . $variant_name;

		if(!empty($variant->bottleyear)) {
?>
		<div id="hikashop_product_description_<?php echo $variant_name; ?>" style="display:block;"><?php
			echo JHTML::_('content.prepare',preg_replace('#<hr *id="system-readmore" */>#i','',$variant->product_description));
		?>Bottle year: <?php echo $variant->bottleyear; ?></div>
<?php
		}
	}
   ?>  
  - TEST END -

And the page can be seen here:
passtheport.thr.nu/shop/ruby-port/lbv-la...inta-das-lamelas-lbv

Regards
Thomas

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

  • Posts: 75517
  • Thank you received: 11750
  • MODERATOR
5 months 1 week ago #337859

Hi,

You're almost there.
You have 3 things left though:
- You need to change hikashop_product_description to something else as that is already used by the description of the product.
You could use for example hikashop_product_bottleyear instead.
- As you can see all the divs where the data displayed refreshes based on the selected variants ahve an id like this: hikashop_product_description_main in show_default.
So you need to change hikashop_product_bottleyear to hikashop_product_bottleyear_main in the id of your main div so that the characteristic system will be able to find it and match it with the variants ones.
- In the show_block_characteristics view file, you can find this line:

var names = ['id','name','code','image','price','quantity','description','weight','url','width','length','height','contact','custom_info','files'];
It tells the system what names to search in the HTML. So in there, you should also add bottleyear

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

  • Posts: 345
  • Thank you received: 23
  • Hikaserial Standard Hikashop Business
5 months 1 week ago #337865

Hi nicolas
Great! Almost there, but I must miss something.
The BOTTLEYEAR is not there from the beginning, but shows when I change variant to 2016.
But changing back to 2015, it stays the bottleyear from 2016 - 2015 has to be 2019.

Can you spot my mistake somewhere?

var names = ['id','name','code','image','price','quantity','description','weight','url','width','length','height','contact','custom_info','files','bottleyear'];
- TEST START -  
  <div id="hikashop_product_bottleyear_main" class="hikashop_product_bottleyear_main" itemprop="bottleyear">
   <?php

	foreach($this->element->variants as $variant) {
		$this->row =& $variant;
		$variant_name = array ();
		if(!empty($variant->characteristics)) {
			foreach($variant->characteristics as $k => $ch) {
				$variant_name[] = $ch->characteristic_id;
			}
		}

		$variant_name = implode('_', $variant_name);
		$this->variant_name = '_' . $variant_name;

		if(!empty($variant->bottleyear)) {
?>
  
		<div id="hikashop_product_bottleyear_<?php echo $variant_name; ?>" style="display:none;">Bottle year: <?php echo $variant->bottleyear; ?></div>  
<?php
		}
	}
   ?>  
   </div>
  - TEST END -

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

  • Posts: 75517
  • Thank you received: 11750
  • MODERATOR
5 months 1 week ago #337867

Hi,

The issue is that the variant divs shouldn't be inside the hikashop_product_bottleyear_main div.
The main div needs to be elsewhere and in it, you want to display the default value to display before the user selects something.

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

  • Posts: 345
  • Thank you received: 23
  • Hikaserial Standard Hikashop Business
5 months 1 week ago #337878

Hi

Oh I get it now, perfect!

And thank you so much - I'm always amazed by the knowledge you guys have and your dedication on helping out - even when I "demand" weird stuff!

The following user(s) said Thank You: nicolas

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

Time to create page: 0.056 seconds
Powered by Kunena Forum