Have Specific Custom Fields based on Variant

  • Posts: 31
  • Thank you received: 3
8 years 3 months ago #225841

-- url of the page with the problem -- : www.solarmade.com/store/product/executive-windmill
-- HikaShop version -- : 2.6.0
-- Joomla version -- : 3.4.8
-- PHP version -- : 5.4.45

Hello,

I am trying to achieve something for our customized products. The products can have custom engravings with 0,1,2 or 3 lines of engraving. Based on the number of lines the customer wants, the price will change. Therefore I have made variants in order to achieve this.

Now for the tricky part. I have made custom fields(text) where people can put in the desired text they would like us to engrave. I am trying to tie the specific custom field(s) to the specific variant but I am finding this hard to achieve. For example: If the customer does not want any engraving I don't want the custom fields to be displayed. If the customer wants one line of text (variant) I only want one custom field to be displayed. If the customer wants two lines of text I want two custom fields to be displayed and so on.

I have attached screen shots so you understand what I mean.

What is the best way to achieve this if I can? Thank you for your assistance.

Attachments:

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

  • Posts: 81598
  • Thank you received: 13081
  • MODERATOR
8 years 3 months ago #225919

Hi,

There is no mechanism in HikaShop to have custom item fields display based on the selected variant.
So it will require some modification.
The easiest is to edit the file "show" of the view "product" via the menu Display>Views and add some custom javascript code to the page to hide/display the custom fields using the hkAfterUpdateVariant javascript trigger.
You can register it like this:
window.Oby.registerAjax("hkAfterUpdateVariant", "my_custom_function");
where my_custom_function is the name of your custom function where you will check the value selected in the characteristic dropdown and then display/hide the fields based on that.

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

  • Posts: 31
  • Thank you received: 3
8 years 3 months ago #225937

Thank you Nicolas,

Is there somewhere in the 419 Lines of code I should consider putting the code? :)

Also I should probably be using the my_custom_function for each of the four different custom fields. Correct!

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

  • Posts: 26017
  • Thank you received: 4004
  • MODERATOR
8 years 3 months ago #227664

Hi,

If you need to insert some javascript ; there is not really a very specific place to add it.
But the bottom of the view is generally more appropriate so you're sure that your code won't break the HTML or be included into a loop.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

Time to create page: 0.058 seconds
Powered by Kunena Forum