- Posts: 8
- Thank you received: 3
Force Variants when adding to cart
12 years 8 months ago #147552
by Billymb3
Force Variants when adding to cart was created by Billymb3
-- url of the page with the problem -- :
girlygeekclothing.com/women/womens-shirt...trash-womens-t-shirt
-- HikaShop version -- : 2.2.1
-- Joomla version -- : 3.2
-- PHP version -- : 5.3.8
-- Browser(s) name and version -- : FIREFOX 27.0.1
-- Error-message(debug-mod must be tuned on) -- : Error_message
Hello-
I currently have our "Add to Cart" button hidden until the user chooses one of each of the products available characteristics.
We would like to change it so that the button is there on page load but if pressed and no variants chosen then fire two events -
1. Add a class to the variants/characteristics that need to be selected.
2. set "display block" to a hidden div next to the variants with an error message.
End result would look like the error when adding a product here -
www.victoriassecret.com/clothing/all-top...54&CatalogueType=OLS
I have been trying to stop the buttons add to cart functionality using a template override with a custom hikashop_button_render function, and also tried modifying cart.php, but not able to figure it out. I know I should be able to do it with a combination of php and Jquery but no luck.
Any direction or suggestions would be great, thank you!
-Billy
-- HikaShop version -- : 2.2.1
-- Joomla version -- : 3.2
-- PHP version -- : 5.3.8
-- Browser(s) name and version -- : FIREFOX 27.0.1
-- Error-message(debug-mod must be tuned on) -- : Error_message
Hello-
I currently have our "Add to Cart" button hidden until the user chooses one of each of the products available characteristics.
We would like to change it so that the button is there on page load but if pressed and no variants chosen then fire two events -
1. Add a class to the variants/characteristics that need to be selected.
2. set "display block" to a hidden div next to the variants with an error message.
End result would look like the error when adding a product here -
www.victoriassecret.com/clothing/all-top...54&CatalogueType=OLS
I have been trying to stop the buttons add to cart functionality using a template override with a custom hikashop_button_render function, and also tried modifying cart.php, but not able to figure it out. I know I should be able to do it with a combination of php and Jquery but no luck.
Any direction or suggestions would be great, thank you!
-Billy
Please Log in or Create an account to join the conversation.
12 years 8 months ago #147564
by nicolas
Replied by nicolas on topic Force Variants when adding to cart
Hi,
The add to cart button is displayed by the file "quantity" of the view "product" that you can edit via the menu Display>Views.
There you'll have several that line of code which calls the button display function:
The $this->ajax variable contains the javascript code of the onclick trigger. If in that javascript you have a return false, it won't do the add to cart. And you can add any javascript in it. I recommend to first dump the content of the variable to see what's in it (it changes based on the options, etc) so that you can add your own javascript without breaking the add to cart function call.
The add to cart button is displayed by the file "quantity" of the view "product" that you can edit via the menu Display>Views.
There you'll have several that line of code which calls the button display function:
Code:
echo $this->cart->displayButton(JText::_('ADD_TO_CART'),'add',$this->params,$url,$this->ajax,'',$max,$min);
The following user(s) said Thank You: Billymb3
Please Log in or Create an account to join the conversation.
12 years 8 months ago #148036
by Billymb3
Replied by Billymb3 on topic Force Variants when adding to cart
Thank you so much for the direction Nicolas. I put the following code in the quantity view at line 20 and its working great. I am now just adding the error message warning the user to "choose a variant", and highlight the radio's and I am good to go.
Code:
$this->ajax = '
var chosenVariant = document.getElementById(hikashop_product_quantity_field_1);
if (chosenVariant = \'hikashop_product_quantity_field_1\') {
return false;
}
else {
return hikashopModifyQuantity(\''.$this->row->product_id.'\',field,1,0,\'cart\','.$module_id.')
}';
Please Log in or Create an account to join the conversation.
11 years 6 months ago - 8 years 6 months ago #201283
by kasimody
Replied by kasimody on topic Force Variants when adding to cart
-
Last edit: 8 years 6 months ago by Jerome. Reason: remove spam
Please Log in or Create an account to join the conversation.
11 years 6 months ago #201299
by nicolas
Replied by nicolas on topic Force Variants when adding to cart
Did you have any question kasimody ?
Please Log in or Create an account to join the conversation.
Less
More
- Posts: 1
- Thank you received: 0
10 years 1 month ago #250422
by DavidBoling
Replied by DavidBoling on topic Force Variants when adding to cart
Nice collection! Thanks for the post.
Please Log in or Create an account to join the conversation.
Time to create page: 0.089 seconds