jahyax Posted November 28, 2013 Share Posted November 28, 2013 (edited) in my product.tpl I have <script> var custom_val; custom_val = $("#cstm_txt").val(); </script> <input type="text" id="cstm_txt" value="some text"> my question is how do i pass the value 'custom_val' from product.tpl into the ProductController.php thanks, Jah Yax Edited December 10, 2013 by jahyax (see edit history) Link to comment Share on other sites More sharing options...
jahyax Posted December 6, 2013 Author Share Posted December 6, 2013 (edited) any idea on this one? this my jquery that i added on product.tpl $(document).ready(function(){ $("#retail_details").hide(); if ($("#retail").prop("checked") == true){ console.log('retail'); xxx = '{$productPrice}'; console.log(xxx); //yyy = {Product::testingProductFunctionTwo("xxx")}; }else if($("#wholesale").prop("checked") == true){ console.log('wholesale'); {math equation="pprice / punit_price" pprice=$productPrice punit_price=$product->unit_price_ratio assign=unit_price} xxx = '{$unit_price|number_format:2}'; console.log(xxx); //yyy = {Product::testingProductFunctionTwo(xxx)}; console.log('hey'); } $("#retail").click(function(){ if($(this).prop("checked") == true){ $("#wholesale").attr("checked", false); $("#retail_details").show(); $("#retail_tot_price").val('{$productPrice}'); $("#our_price_display").text('{$currencySign|html_entity_decode:2:"UTF-8"}{$productPrice}'); xxx = '{$productPrice}'; console.log(xxx); }else if ($(this).prop("checked") == false){ $("#wholesale").attr("checked", false); $(this).checked = true; $("#retail_details").show(); $("#retail_tot_price").val('{$productPrice}'); $("#our_price_display").text('{$currencySign|html_entity_decode:2:"UTF-8"}{$productPrice}'); xxx = '{$productPrice}'; console.log(xxx); } }); $("#wholesale").click(function(){ if($(this).prop("checked") == true){ $("#retail").attr("checked", false); $("#retail_tot_price").val(0); $("#retail_details").hide(); {math equation="pprice / punit_price" pprice=$productPrice punit_price=$product->unit_price_ratio assign=unit_price} $("#our_price_display").text('{$currencySign|html_entity_decode:2:"UTF-8"}{$unit_price|number_format:2} / {$product->unity}'); xxx = '{$unit_price|number_format:2}'; console.log(xxx); }else if ($(this).prop("checked") == false){ $("#retail").attr("checked", false); $(this).checked = true; $("#retail_tot_price").val(0); $("#retail_details").hide(); {math equation="pprice / punit_price" pprice=$productPrice punit_price=$product->unit_price_ratio assign=unit_price} $("#our_price_display").text('{$currencySign|html_entity_decode:2:"UTF-8"}{$unit_price|number_format:2} / {$product->unity}'); xxx = '{$unit_price|number_format:2}'; console.log(xxx); } }); $("#quantity_wanted").change(function(){ var rprice = '{$productPrice}'; var rtlqty = $("#quantity_wanted").val(); var rtlweight = '{$product->unity_weight}'; $("#retail_prop").val(rtlqty * (rtlweight)); $("#retail_tot_price").val(rtlqty * rprice); }); }); and this is on the rest of the code <!-- Moding for retail price--> {if !empty($product->unity) && $product->unit_price_ratio > 0.000000} <!-- wholesale / retail selection --> <p> <label>{''}</label> <input type="radio" id="retail" value="0" />{'pc(s). '} <input type="radio" id="wholesale" value="1" checked="checked" />{l s=''} {$product->unity|escape:'htmlall':'UTF-8'}{'(s)'} </p> <!-- retail selection active --> <p id="retail_details"> <label>{''}</label> <input type="text" size="3" id="retail_prop" value="{$product->unity_weight}" />{$product->unity|escape:'htmlall':'UTF-8'}{' $'} <input type="text" size="3" id="retail_tot_price"/> </p> {/if} <!-- end for moding retaqil price --> <p class="our_price_display"> {if $priceDisplay >= 0 && $priceDisplay <= 2} {if !isset($unity_choice) && empty($unity_choice)} <span id="our_price_display">{convertPrice price=$productPrice}</span> {else isset($unity_choice) && !empty($unity_choice)} {math equation="pprice / punit_price" pprice=$productPrice punit_price=$product->unit_price_ratio assign=unit_price} <span id="our_price_display" >{convertPrice price=$unit_price}{' / '}{$product->unity|escape:'htmlall':'UTF-8'}</span> {/if} {/if} </p> I want to pass the value of "xxx" to the cart How can I pass the value xxx to Cart Controller you can also visit this link to see what is the function : http://localhost/koshersupercenter/dreidels/10255-100-medium-dreidels-bulk-pack.html Edited December 6, 2013 by jahyax (see edit history) Link to comment Share on other sites More sharing options...
jahyax Posted December 10, 2013 Author Share Posted December 10, 2013 anyone please? How do I pass a value from text field from products.tpl to Controller.php or cart.php any idea is appreciated Link to comment Share on other sites More sharing options...
vekia Posted December 10, 2013 Share Posted December 10, 2013 you have to post this form first, then you can use $_POST['cstm_txt'] (don't forget about name="cstm_txt") Link to comment Share on other sites More sharing options...
jahyax Posted December 10, 2013 Author Share Posted December 10, 2013 you have to post this form first, then you can use $_POST['cstm_txt'] (don't forget about name="cstm_txt") Hi Vekia actually this input is already under the form <form id="buy_block" {if $PS_CATALOG_MODE AND !isset($groups) AND $product->quantity > 0}class="hidden"{/if} action="{$link->getPageLink('cart')}" method="post"> .....some code <input type="hidden" name="cstm_txt" id="cstm_txt" value="{convertPrice price=$unit_price}" /> <p id="add_to_cart" class="buttons_bottom_block"> <span></span> <input type="submit" name="Submit" value="{l s='Add to cart'}" class="exclusive" /> </p> </form> where do i include the variable that this input gets posted, what I am trying to do is Post this value in the Cart Controller and acces the value both in the CartController.php and in the Cart.php Link to comment Share on other sites More sharing options...
vekia Posted December 11, 2013 Share Posted December 11, 2013 you can use in product controller Tools::getValue('cstm_txt') Link to comment Share on other sites More sharing options...
jahyax Posted December 11, 2013 Author Share Posted December 11, 2013 you can use in product controller Tools::getValue('cstm_txt') Thanks Vekia I have tried in Product Controller $this->context->smarty->assign('custom_unity_price', Tools::getValue('cstm_txt')); and in product.tpl i use {$custom_unity_price} but the value is empty.. also I want this value to be accessible in the Cart.. Link to comment Share on other sites More sharing options...
vekia Posted December 11, 2013 Share Posted December 11, 2013 you have to post this field first, after that you will be able to use Tools feature. you said that you've got it in the form so i suppose that you want to post it somewhere. Link to comment Share on other sites More sharing options...
jahyax Posted December 11, 2013 Author Share Posted December 11, 2013 you have to post this field first, after that you will be able to use Tools feature. you said that you've got it in the form so i suppose that you want to post it somewhere. Vekia, thanks for looking out.. yes I include it in the form and the for is <form id="buy_block" {if $PS_CATALOG_MODE AND !isset($groups) AND $product->quantity > 0}class="hidden"{/if} action="{$link->getPageLink('cart')}" method="post"> according to my understanding, if I am not wrong, this form is the one that execute or adds products to cart, I also assume that the posted data goes into CartController if not in ProductController, but I am lost on where to access the posted data so that I could view in on cart display for front end Link to comment Share on other sites More sharing options...
jahyax Posted December 12, 2013 Author Share Posted December 12, 2013 I want I really want to happen on this one is that the value of my custom field on product.tpl is to posted or passed on to Cart: my workaround was: include the the custom text field inside a form for the add to cart ie <form id="buy_block" {if $PS_CATALOG_MODE AND !isset($groups) AND $product->quantity > 0}class="hidden"{/if} action="{$link->getPageLink('cart')}" method="post"> .....some code <input type="hidden" name="cstm_txt" id="cstm_txt" value="{convertPrice price=$unit_price}" /> <p id="add_to_cart" class="buttons_bottom_block"> <span></span> <input type="submit" name="Submit" value="{l s='Add to cart'}" class="exclusive" /> </p> </form> and then on the ajax-cart.js i added on the data of the function add on this line of code $('#add_to_cart input').unbind('click').click(function(){ ajaxCart.add( $('#product_page_product_id').val(), $('#idCombination').val(), true, null, $('#quantity_wanted').val(), null, $('#ctm_uty_prc').val()); // add a product in the cart via ajax "add : function(...........)" ...some code 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): '' + '&ctm_uty_prc=' + $("#cstm_txt").val()) and on the Cart.php I was able to retrieve the value via "Tools::getValue('ctm_uty_prc')" this was most on what I have i done, thanks to all that have help me on this.. >>>> to the next phase of the project.. Link to comment Share on other sites More sharing options...
3cubes Posted April 7, 2014 Share Posted April 7, 2014 Where exactly in the Cart.php did you retrieve the value of your field??? An Answer would really be appreciated. Thanks Link to comment Share on other sites More sharing options...
3cubes Posted April 8, 2014 Share Posted April 8, 2014 (edited) Nobody here who could give me an advice?? I have already changed ajax-cart.js file so when you click on buy button on product page the value of my custom input field ist also beeing sent, if I am not wrong, to the cart controller. Now how can I fetch this value in controller file to use it further and save this value to databse (custom row in database is already created and ready) ???? I just want to save this value in cart_product table and show it along with the product in blockcart and cartsummary. Just like customization fields but I dont want to use them for certain reasons. Thank you very much Edited April 8, 2014 by 3cubes (see edit history) Link to comment Share on other sites More sharing options...
jahyax Posted April 11, 2014 Author Share Posted April 11, 2014 in the Cart.php you could just use $variable = Tools:getValue('name_of_the_input'); Link to comment Share on other sites More sharing options...
3cubes Posted April 12, 2014 Share Posted April 12, 2014 But when I change ajax-cart.js like you described I don't get my data send. Without ajax cart enabled data is send. But when I use ajax cart and change the file like above no other data is send to cart.php than the original data!??? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now