Adding a text custom field using the item table to a product with variants

  • Posts: 39
  • Thank you received: 2
  • Hikaserial Standard Hikashop Business
2 weeks 1 day ago #363933

-- HikaShop version -- : 5.1.1
-- Joomla version -- : 4.4.8
-- PHP version -- : 8.3.12
-- Browser(s) name and version -- : Brave Version 1.67.123 Chromium: 126.0.6478.126 (Official Build) (arm64)
-- Error-message(debug-mod must be tuned on) -- : no error messages

I have a product with variants. I want to add a custom field to the item table that will allow customers to provide a text message on the product.

PRODUCT A

We have pretty much the same thing setup on a different product...

PRODUCT B

The only major difference between these two products is that PRODUCT B has two characteristics (Division and Choose Size) that create a total of 11 variants. The PRODUCT A only has one characteristic (size) for a total of three variants.

I carefully matched all the settings for my new custom text field (in the items table) with the existing text field that serves PRODUCT B. I am even able to successfully add the new field to PRODUCT B without any issue.

When I add the new field to PRODUCT A it will not appear. I restricted it as an individual product and then tried restricting it to the category. I have checked all the of the display options for the two different fields and the two different products over and over. They appear to match in terms of display options, etc.

The only two other observations that I have is that if I make the field required on the PRODUCT A page, I will get the error message when trying to add it to the cart even though the field is not showing. I also notice that the default variant does not immediately show for PRODUCT B when the page first loads. I am given the chance to choose characteristics first. Whereas with PRODUCT A the default variant shows right away. I am not sure if that is relevant or why one product behaves differently in this regard.

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

  • Posts: 82683
  • Thank you received: 13337
  • MODERATOR
2 weeks 19 hours ago #363934

Hi,

I think there is a problem with the settings of the custom field.
Please provide a screenshot of the custom field and a screenshot of the settings of PRODUCT A.
That should allow us to check what's going on and hopefully tell you what you're missing.

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

  • Posts: 39
  • Thank you received: 2
  • Hikaserial Standard Hikashop Business
2 weeks 10 hours ago #363946

Hi Nicholas,

I am attaching screenshots with sensitive info blocked out. Again if I "require" the field, I get the appropriate error message that prevents me from adding the product to the cart. So I know it is not an issue of correctly assigning the field to the correct product or category.

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

  • Posts: 82683
  • Thank you received: 13337
  • MODERATOR
2 weeks 6 hours ago #363947

Hi,

Thanks for the screenshots. Everything looks fine.
If it's not an issue of correctly assigning the field (and it isn't as far as I can see), then I can only think of a customization issue.
Could you try switching temporarily to the default template of Joomla and see if the field appears on the product page with the default template ? If so, it would indicate that the problem is in one of the view override files in templates/YOUR_TEMPLATE/html/com_hikashop/product/
If that doesn't change anything, then I'm out of ideas and we'll need a backend access and a FTP access in order to look deeper into it. You can provide these via our contact form:
www.hikashop.com/support/contact-us.html

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

  • Posts: 39
  • Thank you received: 2
  • Hikaserial Standard Hikashop Business
1 week 6 days ago #363976

HI Nicholas,

I am not sure if this is a change in how we started setting up our products or if the code that I am about to share was part of a recent update.


In /templates/g5_helium/html/com_hikashop/product/show_default.php, we have...

Value of '$this->itemFields' is NULL

We found the issue in components / com_hikashop / views / product : view.html.php at line: 1722

There is a check for whether or not a variant has a price. If it does not the custom fields will not display. Here is the code
$display_item_fields = true;
				if(!$this->config->get('display_add_to_cart_for_free_products') || ($this->config->get('display_add_to_wishlist_for_free_products', 1) && $this->params->get('add_to_wishlist') && $this->config->get('enable_wishlist', 1))) {
					if(empty($element->variants)) {
						if(empty($element->prices))
							$display_item_fields = false;
					} else {
						$variants_are_all_free = true;
						foreach($element->variants as $variant) {
							if(!empty($variant->prices)) {
								$variants_are_all_free = false;
							}
						}

						if($variants_are_all_free)
							$display_item_fields = false;
					}

				}

I thought the original behavior was that if a variant does not have a price it would inherit the price of the parent product.

In any event our problem of custom fields not showing is solved by making sure that all variants have a price.

Thanks,
Brian

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

  • Posts: 39
  • Thank you received: 2
  • Hikaserial Standard Hikashop Business
1 week 6 days ago #363978

Actually after further testing we still have some products that have no variants that are not displaying the custom fields.

We have temporarily added

$display_item_fields = true;

at line 1740 in components / com_hikashop / views / product : view.html.php

So that our custom fields can show. I know this will be overwritten on the next update, but I need something in place in the short term.

Please let me know what I am missing.

Thanks,
Brian

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

  • Posts: 82683
  • Thank you received: 13337
  • MODERATOR
1 week 3 days ago #363992

Hi,

Ok, I see what's going on.
You're on the right track. The variant indeed inherits the prices of the main product when the variant doesn't have a price.
The issue is that this is done with the line of code:
$productClass->checkVariants($element);
And this line of code is actually after the check on the price of the variants for the display of the custom item fields when the "display add to cart button for free products" setting is turned off.
So, fixing this issue will require moving the piece of code you identified, after this call to the checkVariants function in the view.html.php
We'll add this change on our end for the next version of HikaShop.

The following user(s) said Thank You: manu.beladevan@gmail.com

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

  • Posts: 1
  • Thank you received: 0
1 week 3 days ago #364011

Great .. Thank you very much, when we can expect the next version ?

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

  • Posts: 82683
  • Thank you received: 13337
  • MODERATOR
1 week 3 days ago #364013

We're planning to release it next month. You can apply the modification manually via FTP if you need it before this.

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

Time to create page: 0.081 seconds
Powered by Kunena Forum