Jump to content

[SOLVED] FO Radiobuttons in product detail


Guest

Recommended Posts

I added a radibuttons to the product page.
When I click the Add to cart button, I need to write the status of the radiobutton to a new table in the database.
How do I pass a value to the cart and save it to the database?


Thank you

Edited by Guest (see edit history)
Link to comment
Share on other sites

./themes/default-bootstrap/product.tpl

<p>Please select your gender:</p>
  <input type="radio" id="1" name="MyExtraGender" value="male">
  <label for="male">Male</label><br>
  <input type="radio" id="2" name="MyExtraGender" value="female">
  <label for="female">Female</label><br>
  <input type="radio" id="3" name="MyExtraGender" value="other">
  <label for="other">Other</label>

<p id="add_to_cart" class="buttons_bottom_block no-print">
								<button type="submit" name="Submit" class="exclusive">
									<span>{if $content_only && (isset($product->customization_required) && $product->customization_required)}{l s='Customize'}{else}{l s='Add to cart'}{/if}</span>
								</button>
							</p>

 

./themes/default-bootstrap/js/modules/blockcart/ajax-cart.js

add MyExtraGender

// add a product in the cart via ajax
	add : function(idProduct, idCombination, addedFromProductPage, callerElement, quantity, whishlist, MyExtraGender){

		...
        ...
        ...

		$.ajax({
			type: 'POST',
			headers: { "cache-control": "no-cache" },
			url: baseUri + '?rand=' + new Date().getTime(),
			async: true,
			cache: false,
			dataType : "json",
			data: 'controller=cart&add=1&ajax=true&qty=' + ((quantity && quantity != null) ? quantity : '1') + '&id_product=' + idProduct + '&token=' + static_token + ( (parseInt(idCombination) && idCombination != null) ? '&ipa=' + parseInt(idCombination): '' + '&id_customization=' + ((typeof customizationId !== 'undefined') ? customizationId : 0))+'&MyExtraGender='+MyExtraGender,
		...
        ...
        ...
		});
	},

 

./modules/my_module/my_module.php

NOT WORK

public function hookActionCartSave()
    {
      $cart_id = $this->context->cart->id;
      $gender_id = $this->context->cart->MyExtraGender;
    }

 

Edited by Guest (see edit history)
Link to comment
Share on other sites

Nobody assigned $this->context->cart->MyExtraGender variable

try to read directly

       

$gender_id  = Tools::getValue('MyExtraGender', '');
// or
// $gender_id  = Tools::getValue('MyExtraGender', 'other');

 

 

Link to comment
Share on other sites

ok, good message - in this case ajax POSTs  NAN value of MyExtraGender.
it means that  parameter MyExtraGender is undefined.

for the start I would recommend you to use directly MyExtraGender value + javascript DEBUG - of course

(srry for another form of data, but it is more readable for me than querystring)

// add a product in the cart via ajax
	add : function(idProduct, idCombination, addedFromProductPage, callerElement, quantity, whishlist, MyExtraGender){

		...
        ...
        ...
        data={};
        data['controller']='cart';
        data['add']=1;
        data['ajax']=true;
        data['qty']= ((quantity && quantity != null) ? quantity : '1');
        data['id_product']= idProduct;
        data['token']= static_token;
        if  (parseInt(idCombination) && idCombination != null) {
          data['ipa']= parseInt(idCombination): '';
        }
        data['id_customization']=customizationId : 0;
        data['MyExtraGender']=$('input[name="MyExtraGender"]').val();
		...
		$.ajax({
			type: 'POST',
			headers: { "cache-control": "no-cache" },
			url: baseUri + '?rand=' + new Date().getTime(),
			async: true,
			cache: false,
			dataType : "json",
			data: data,
		...
        ...
        ...
		});
	},


 

Edited by EvaF (see edit history)
Link to comment
Share on other sites

Thank you,
when I used your solution, the ajax cart redirected me to the order.
When I used the solution below, everything went fine and I got the parameter in the hook that I need.

Thanks again for the help.

data: 'controller=cart&add=1&ajax=true&qty=' + ((quantity && quantity != null) ? quantity : '1') + '&id_product=' + idProduct + '&token=' + static_token + ( (parseInt(idCombination) && idCombination != null) ? '&ipa=' + parseInt(idCombination): '' + '&id_customization=' + ((typeof customizationId !== 'undefined') ? customizationId : 0))+'&MyExtraGender='+$('input[name="MyExtraGender"]').val(),

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...