From 92b2366ed1c8d660f633351a54b505f73200c6f0 Mon Sep 17 00:00:00 2001 From: Marion Muszynski Date: Thu, 6 Jul 2017 17:30:16 +0200 Subject: [PATCH] fix --- override/controllers/CartController.php | 4 +++- themes/site/js/cart-summary.js | 32 ++++++++++++++++++------- themes/site/shopping-cart.tpl | 2 +- themes/site_mobile/js/cart-summary.js | 21 ++++++++++++---- 4 files changed, 45 insertions(+), 14 deletions(-) diff --git a/override/controllers/CartController.php b/override/controllers/CartController.php index 559db8da..a7616f4e 100644 --- a/override/controllers/CartController.php +++ b/override/controllers/CartController.php @@ -303,9 +303,11 @@ class CartController extends CartControllerCore } if($giftMessage){ - if(Tools::getValue('action') == 'remove_message'){ + if(Tools::getValue('action') == 'remove_all'){ self::$cart->gift = 0; self::$cart->gift_message = ''; + } elseif(Tools::getValue('action') == 'remove_message'){ + self::$cart->gift_message = ''; } elseif(Tools::getValue('action') == 'add_message'){ self::$cart->gift = 1; self::$cart->gift_message = strip_tags(Tools::getValue('message')); diff --git a/themes/site/js/cart-summary.js b/themes/site/js/cart-summary.js index fc8254fe..220c0771 100755 --- a/themes/site/js/cart-summary.js +++ b/themes/site/js/cart-summary.js @@ -33,11 +33,9 @@ $(document).ready(function() $('.cart_quantity_down').unbind('click').click(function(){ downQuantity($(this).attr('id').replace('cart_quantity_down_', '')); return false; }); $('.cart_quantity_delete' ).unbind('click').click(function(){ deletProductFromSummary($(this).attr('id')); return false; }); $('.cart_quantity_input').typeWatch({ highlight: true, wait: 600, captureLength: 0, callback: updateQty }); - $('#go_to_next_step').unbind('click').click(function(){giftMessage(true,true); }); - // $('#cart_add_gift_message').unbind('click').click(function(){giftMessage(true); return false; }); - // $('#cart_remove_gift_message').unbind('click').click(function(){giftMessage(false); return false; }); - $('.remove_message_gift').unbind('click').click(function(){giftMessage(false,false); return false; }); + $('#go_to_next_step').unbind('click').click(function(){giftMessage(true,true,false);}); + $('.remove_message_gift').unbind('click').click(function(){giftMessage(false,false,true); return false; }); } }); @@ -478,10 +476,21 @@ function updateCartSummary(json) ajaxCart.refresh(); } -function giftMessage(add, next){ +function giftMessage(add, next, all){ var action = "add_message"; - if(add == false || $('#gift_message').val()=='' || !$('input#gift').is(':checked')){ - var action = "remove_message"; + if(add == false ){ + if(all == true || !$('input#gift').is(':checked')) { + action = "remove_all"; + } else { + action = "remove_message"; + } + } + if(add == true){ + if(!$('input#gift').is(':checked')){ + action = "remove_all"; + } else { + action = "add_message"; + } } $.ajax({ type: 'POST', @@ -513,12 +522,19 @@ function giftMessage(add, next){ message = escape($('#gift_message').val()) $('#my_gift_message').html($('#gift_message').val().replace(/\n/g, "
")); $('#my_gift').show(); - } else { + if($('#gift_message').val()==''){ + $('#my_gift').hide(); + } + } else if (jsonData.action == "remove_all") { $('#my_gift_message').html(''); $('#my_gift').hide(); $('#gift_message').val(''); $('#gift_div').hide(); $('#gift').removeAttr('checked'); + } else if (jsonData.action == "remove_message") { + $('#my_gift_message').html(''); + $('#my_gift').hide(); + $('#gift_message').val(''); } if(next==true){ return true; diff --git a/themes/site/shopping-cart.tpl b/themes/site/shopping-cart.tpl index 8753ace1..6436bb7c 100755 --- a/themes/site/shopping-cart.tpl +++ b/themes/site/shopping-cart.tpl @@ -317,7 +317,7 @@ {if $giftAllowed} -

gift == 0} style="display:none;" {/if}> +

gift == 0 || $cart->gift_message == ''} style="display:none;" {/if}> X {l s='My message : '}
{nl2br($cart->gift_message)|escape:'UTF-8'} diff --git a/themes/site_mobile/js/cart-summary.js b/themes/site_mobile/js/cart-summary.js index 3d92eaf5..9521f2be 100755 --- a/themes/site_mobile/js/cart-summary.js +++ b/themes/site_mobile/js/cart-summary.js @@ -34,7 +34,7 @@ $(document).ready(function() $('.cart_quantity_delete' ).unbind('click').click(function(){ deletProductFromSummary($(this).attr('id')); return false; }); $('.cart_quantity_input').typeWatch({ highlight: true, wait: 600, captureLength: 0, callback: updateQty }); - $('#go_to_next_step').unbind('click').click(function(){giftMessage(true,true); }); + $('#go_to_next_step').unbind('click').click(function(){giftMessage(true,true,false); }); } }); @@ -464,10 +464,21 @@ function updateCartSummary(json) ajaxCart.refresh(); } -function giftMessage(add, next){ +function giftMessage(add, next, all){ var action = "add_message"; - if(add == false || $('#gift_message').val()=='' || !$('input#gift').is(':checked')){ - var action = "remove_message"; + if(add == false ){ + if(all == true || !$('input#gift').is(':checked')) { + action = "remove_all"; + } else { + action = "remove_message"; + } + } + if(add == true){ + if(!$('input#gift').is(':checked')){ + action = "remove_all"; + } else { + action = "add_message"; + } } $.ajax({ type: 'POST', @@ -497,6 +508,8 @@ function giftMessage(add, next){ { if(jsonData.action == "remove_message") { $('#gift_message').val(''); + }else if(jsonData.action == "remove_all"){ + $('#gift_message').val(''); $('#gift_div').hide(); $('#gift').removeAttr('checked'); }