Serial Posted September 14, 2015 Share Posted September 14, 2015 Hi, I want to propose has my customers to be able to ask to cut out his product free. I created a new <th> line in shopping-cart.tpl for each products in the cart. <th class="cart_coupe item text-center">{l s='Coupe'}</th> After in shopping-cart-product-line.tpl, after the column "Availability" : <td class="coupe_tissus" data-title="{l s='Coupe'}"> <input class="coupe_select" type="checkbox" value="no" name="checkbox_coupe_{$product.id_product}_{$product.id_product_attribute}_{if $quantityDisplayed > 0}nocustom{else}0{/if}_{$product.id_address_delivery|intval}">Coupe</input> <div class="param_coupe {$icpClass}" name="param_coupe_{$product.id_product}_{$product.id_product_attribute}_{if $quantityDisplayed > 0}nocustom{else}0{/if}_{$product.id_address_delivery|intval}"> <div class="coupe-content"><input id="nb_pieces" type="text" value="{$product.cart_quantity}" name="pieces_{$product.id_product}_{$product.id_product_attribute}_{if $quantityDisplayed > 0}nocustom{else}0{/if}_{$product.id_address_delivery|intval}" style="width:40px;"/> pièce(s) x <input id="nb_metres" type="text" name="metres_{$product.id_product}_{$product.id_product_attribute}_{if $quantityDisplayed > 0}nocustom{else}0{/if}_{$product.id_address_delivery|intval}" style="width:40px;" disabled /> m</div> <input class="bouton_calculer" type="button" value="Calculer" /> </div> </td> And in cart-summary.js, I created the a select checkbox, and if it's checked by customer, I display a <div> to define his cutting : // Au changement d'une checkbox "Coupe" $('.coupe_select').change('click', function(e){ e.preventDefault(); var icp = ppCart.getIcp($(this)); if ($('.coupe_select' + ppCart.getIcpSelector(icp)).attr('checked')) { $('div.param_coupe' + ppCart.getIcpSelector(icp)).show('slow'); } else { $('div.param_coupe' + ppCart.getIcpSelector(icp)).hide('slow'); } } ); // Lors du clic sur le bouton Calculer $('.bouton_calculer').on('click', function(e){ e.preventDefault(); var icp = ppCart.getIcp($(this)); // On relève le numéro de la ligne var pieces = $("input#nb_pieces" + ppCart.getIcpSelector(icp)).val(); // On récupère le nombre de pièces de la ligne (par défaut : 1) var quantite = $('input.cart_quantity_input' + ppCart.getIcpSelector(icp)).val().replace(",","."); // On récupère la quantité // On appelle la fonction CalculCoupe avec les valeurs de la ligne du produit. CalculCoupe(pieces,quantite,icp); } ); And my function CalculCoupe() : function CalculCoupe(pieces, quantite, icp) { // Conversion des chaînes en tant que nombre pour pouvoir faire la division pieces = parseInt(pieces); quantite = parseFloat(quantite); // Déclaration d'une variable metres résultant de la division // On vérifie sir le chiffre contient plus de 3 chiffres après la virgule // Si c'est le cas, on fixe à 3 chiffres après la virgule // Puis on affiche le nombre de mètres dans la case var metres = quantite / pieces; if (metres.toString().split(".")[1].length > 3) { metres = metres.toFixed(3); } $('input#nb_metres' + ppCart.getIcpSelector(icp)).val(metres); } So all is OK for this. Now, my problem is that I want to save customer's choice. To do simple, I want to concatenate my JS variables ( metres and pieces) in a string variable and save this string variable in my database in ps_order_detail in a new VARCHAR field that I created before (name : coupe_tissu). Any have solution please ? Link to comment Share on other sites More sharing options...
Paul C Posted September 14, 2015 Share Posted September 14, 2015 (edited) If It was me I'd add 2 customisation fields to the product (meters and pieces) and then do any necessary validation on them on the product page itself. That way they get added to the cart as Prestashop expects and the rest is standard. You would need to make sure that the fields were mandatory to prevent getting an order with those fields blank (if the customer doesn't notice they need to specify them). Even though they are text fields you can hard-code the customisation fields in your theme as dropdown boxes based on a particular criteria so they only show up for products in a certain category (or better - that have those specific customisation fields present, just in case you forget to add them to the product). I've used this method successfully in a jewellery site where we wanted the customer to choose the size. Unfortunately if you use combinations then Prestashop expects you to have stock of one of each size, whereas in fact the exact same single ring gets resized - so this was the only way of getting the UI to work as expected but maintain the proper stock handling. Some people have also added modifications to the cart controller so you don;t have to "save" the customisation before adding to the cart which makes it an even more seamless process. Edited September 14, 2015 by Paul C (see edit history) Link to comment Share on other sites More sharing options...
Serial Posted September 14, 2015 Author Share Posted September 14, 2015 (edited) Ok. But It's too hard if I finish my approach ? The problem of combination is that I must to do this for each products. Edited September 14, 2015 by Serial (see edit history) 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