Force Variants when adding to cart

  • Posts: 8
  • Thank you received: 3
11 years 6 months ago #147552

-- 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

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

  • Posts: 84424
  • Thank you received: 13720
  • MODERATOR
11 years 6 months ago #147564

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:

echo $this->cart->displayButton(JText::_('ADD_TO_CART'),'add',$this->params,$url,$this->ajax,'',$max,$min);
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 following user(s) said Thank You: Billymb3

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

  • Posts: 8
  • Thank you received: 3
11 years 6 months ago #148036

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.

$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.

  • Posts: 1
  • Thank you received: 0
10 years 4 months ago #201283

-

Last edit: 7 years 5 months ago by Jerome. Reason: remove spam

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

  • Posts: 84424
  • Thank you received: 13720
  • MODERATOR
10 years 4 months ago #201299

Did you have any question kasimody ?

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

  • Posts: 1
  • Thank you received: 0
9 years 1 week ago #250422

Nice collection! Thanks for the post.

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

Time to create page: 0.069 seconds
Powered by Kunena Forum