Can Characteristic Selection trigger a javascript?

  • Posts: 144
  • Thank you received: 4
  • Hikashop Business
8 years 2 months ago #249640

-- HikaShop version -- : 2.6.4
-- Joomla version -- : 3.6.2
-- PHP version -- : 5.6.16

I have Product which is made of three selected Option items within a packaging container (a Characteristic item which does not modify the price). The Customer normally selects which "Color" of container the product will use and then chooses the three component Options (each of which modifies the Product's price). After this, the Customer can select optional "Artwork" (a Custom Field also attached to this Product, which does not modify the price). My customer does maintain a stock of each container "Color", and would like to use HikaShop to keep track of them.

The difficulty is that not all "Artwork" is available for use on both "Colors" of container. I currently have a javascript snippet included in the custom "Artwork" field's definition which builds the option list based upon which "Color" Characteristic is currently selected. This works for a normal purchase until a customer decides to modify their "Color" Characteristic after they have selected "Artwork". I need to unselect the "Artwork" selection every time the "Color" Characteristic is modified.

I have examined HikaShop's editable Views and have not found a way to add an "onChange" attribute to the Characteristic drop-down input item, or to the "Add To Cart" button. It also appears that Custom Fields can only be attached to Product items, not Characteristic Items so I cannot provide different lists of "Artwork" to each Characteristic.

The javascript would be relatively simple if I could find the right place to add a trigger.

Do you have any suggestions?

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

  • Posts: 82867
  • Thank you received: 13373
  • MODERATOR
8 years 2 months ago #249679

Hi,

You should be able to easily add an onchange to a characteristic or a onclick on the add to cart button.
For the characteristic dropdown, edit the file "show_block_characteristic" via the menu Display>Views and change the line:

echo $this->characteristic->displayFE($this->element, $this->params) . '</div>';
to:
echo str_replace('onchange="','onchange="callToMyCustomJavascriptFunction();',$this->characteristic->displayFE($this->element, $this->params)) . '</div>';
For the add to cart, you can edit the file "quantity" of the view "product" and change the line:
$this->ajax = 'return hikashopModifyQuantity(\''.$this->row->product_id.'\',field,1,0,\'cart\','.$module_id.')';
to:
$this->ajax = 'callToMySecondCustomJavascriptFunction();return hikashopModifyQuantity(\''.$this->row->product_id.'\',field,1,0,\'cart\','.$module_id.')';

The following user(s) said Thank You: icomex

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

  • Posts: 144
  • Thank you received: 4
  • Hikashop Business
8 years 2 months ago #249735

Your suggestions work beautifully. Thanks!

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

Time to create page: 0.061 seconds
Powered by Kunena Forum