- Posts: 149
- Thank you received: 6
Can Characteristic Selection trigger a javascript?
10 years 2 weeks ago #249640
by icomex
Can Characteristic Selection trigger a javascript? was created by icomex
-- 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?
-- 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.
10 years 2 weeks ago #249679
by nicolas
Replied by nicolas on topic Can Characteristic Selection trigger a javascript?
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:
to:
For the add to cart, you can edit the file "quantity" of the view "product" and change the line:
to:
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:
Code:
echo $this->characteristic->displayFE($this->element, $this->params) . '</div>';
Code:
echo str_replace('onchange="','onchange="callToMyCustomJavascriptFunction();',$this->characteristic->displayFE($this->element, $this->params)) . '</div>';
Code:
$this->ajax = 'return hikashopModifyQuantity(\''.$this->row->product_id.'\',field,1,0,\'cart\','.$module_id.')';
Code:
$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.
10 years 2 weeks ago #249735
by icomex
Replied by icomex on topic Can Characteristic Selection trigger a javascript?
Your suggestions work beautifully. Thanks!
Please Log in or Create an account to join the conversation.
Time to create page: 0.172 seconds