From 13b68d20aead6fd7da60851df0919061036dca34 Mon Sep 17 00:00:00 2001
From: Marion Muszynski
Date: Fri, 30 Jun 2017 12:57:06 +0200
Subject: [PATCH] moving gift message to shopping cart step
---
controllers/ParentOrderController.php | 20 +++++-----
override/classes/Cart.php | 1 +
override/controllers/CartController.php | 15 +++++++
themes/site/css/style.css | 11 +++++
themes/site/js/cart-summary.js | 53 ++++++++++++++++++++++++-
themes/site/order-carrier.tpl | 4 +-
themes/site/shopping-cart.tpl | 30 ++++++++++++++
7 files changed, 122 insertions(+), 12 deletions(-)
diff --git a/controllers/ParentOrderController.php b/controllers/ParentOrderController.php
index 1047787d..4aa282aa 100755
--- a/controllers/ParentOrderController.php
+++ b/controllers/ParentOrderController.php
@@ -32,7 +32,7 @@ class ParentOrderControllerCore extends FrontController
{
public $ssl = true;
public $php_self = 'order.php';
-
+
public $nbProducts;
public function __construct()
@@ -200,14 +200,15 @@ class ParentOrderControllerCore extends FrontController
protected function _processCarrier()
{
self::$cart->recyclable = (int)(Tools::getValue('recyclable'));
- self::$cart->gift = (int)(Tools::getValue('gift'));
- if ((int)(Tools::getValue('gift')))
- {
- if (!Validate::isMessage($_POST['gift_message']))
- $this->errors[] = Tools::displayError('Invalid gift message');
- else
- self::$cart->gift_message = strip_tags($_POST['gift_message']);
- }
+ // @Override Antadis - Gift cart updated on step 1
+ // self::$cart->gift = (int)(Tools::getValue('gift'));
+ // if ((int)(Tools::getValue('gift')))
+ // {
+ // if (!Validate::isMessage($_POST['gift_message']))
+ // $this->errors[] = Tools::displayError('Invalid gift message');
+ // else
+ // self::$cart->gift_message = strip_tags($_POST['gift_message']);
+ // }
if (isset(self::$cookie->id_customer) AND self::$cookie->id_customer)
{
@@ -290,6 +291,7 @@ class ParentOrderControllerCore extends FrontController
protected function _assignAddress()
{
+
//if guest checkout disabled and flag is_guest in cookies is actived
if (Configuration::get('PS_GUEST_CHECKOUT_ENABLED') == 0 AND ((int) self::$cookie->is_guest != Configuration::get('PS_GUEST_CHECKOUT_ENABLED')))
{
diff --git a/override/classes/Cart.php b/override/classes/Cart.php
index a699907c..c49312b0 100755
--- a/override/classes/Cart.php
+++ b/override/classes/Cart.php
@@ -1046,6 +1046,7 @@ class Cart extends CartCore {
'products' => $products,
'discounts' => $this->getDiscounts(false, true),
'is_virtual_cart' => (int)$this->isVirtualCart(),
+ 'giftAllowed' => (int)(Configuration::get('PS_GIFT_WRAPPING')),
'total_discounts' => $this->getOrderTotal(true, Cart::ONLY_DISCOUNTS),
'total_discounts_tax_exc' => $this->getOrderTotal(false, Cart::ONLY_DISCOUNTS),
'total_wrapping' => $this->getOrderTotal(true, Cart::ONLY_WRAPPING),
diff --git a/override/controllers/CartController.php b/override/controllers/CartController.php
index abe42da0..559db8da 100644
--- a/override/controllers/CartController.php
+++ b/override/controllers/CartController.php
@@ -42,6 +42,7 @@ class CartController extends CartControllerCore
$add = Tools::getIsset('add') ? 1 : 0;
$delete = Tools::getIsset('delete') ? 1 : 0;
$removeAll = Tools::getIsset('removeall') ? 1 : 0;
+ $giftMessage = Tools::getValue('giftmessage');
if (Configuration::get('PS_TOKEN_ENABLE') == 1
&& strcasecmp(Tools::getToken(false), strval(Tools::getValue('token')))
@@ -300,6 +301,20 @@ class CartController extends CartControllerCore
}
}
}
+
+ if($giftMessage){
+ if(Tools::getValue('action') == 'remove_message'){
+ self::$cart->gift = 0;
+ self::$cart->gift_message = '';
+ } elseif(Tools::getValue('action') == 'add_message'){
+ self::$cart->gift = 1;
+ self::$cart->gift_message = strip_tags(Tools::getValue('message'));
+ }
+
+ if(self::$cart->update()){
+ die('{"hasError" : false, "action" : "'.Tools::getValue('action').'"}');
+ }
+ }
// @End adding Antadis
}
}
\ No newline at end of file
diff --git a/themes/site/css/style.css b/themes/site/css/style.css
index f937b85d..a696ec3e 100755
--- a/themes/site/css/style.css
+++ b/themes/site/css/style.css
@@ -7283,4 +7283,15 @@ table#carrierTable tbody td {
top: 0;
width: 100%;
z-index: 800;
+}
+
+#my_gift{
+ text-align: center;
+ margin-bottom: 10px;
+}
+.my_gift{
+ color: #514c8c;
+}
+#cart_remove_gift_message{
+ float:right;
}
\ No newline at end of file
diff --git a/themes/site/js/cart-summary.js b/themes/site/js/cart-summary.js
index 0cb806a2..0aeb8f75 100755
--- a/themes/site/js/cart-summary.js
+++ b/themes/site/js/cart-summary.js
@@ -32,7 +32,9 @@ $(document).ready(function()
$('.cart_quantity_up').unbind('click').click(function(){ upQuantity($(this).attr('id').replace('cart_quantity_up_', '')); return false; });
$('.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 });
+ $('.cart_quantity_input').typeWatch({ highlight: true, wait: 600, captureLength: 0, callback: updateQty });
+ $('#cart_add_gift_message').unbind('click').click(function(){ console.log('add'); giftMessage(true); return false; });
+ $('#cart_remove_gift_message').unbind('click').click(function(){ console.log('remove'); giftMessage(false); return false; });
}
});
@@ -473,6 +475,55 @@ function updateCartSummary(json)
ajaxCart.refresh();
}
+function giftMessage(add){
+ var action = "add_message";
+ if(add == false){
+ var action = "remove_message";
+ }
+ $.ajax({
+ type: 'POST',
+ url: baseDir + 'cart.php',
+ async: true,
+ cache: false,
+ dataType: 'json',
+ data: {
+ 'ajax':true,
+ 'giftmessage' : 1,
+ 'action': action,
+ 'message': $('#gift_message').val(),
+ 'token': static_token
+ },
+ success: function(jsonData)
+ {
+ if (jsonData.hasError)
+ {
+ var errors = '';
+ for(error in jsonData.errors)
+ //IE6 bug fix
+ if(error != 'indexOf')
+ errors += jsonData.errors[error] + "\n";
+ alert(errors);
+ }
+ else
+ {
+ console.log(jsonData);
+ if(jsonData.action == "add_message") {
+ message = escape($('#gift_message').val())
+ $('#my_gift_message').html($('#gift_message').val().replace(/\n/g, "
"));
+ $('#my_gift').show();
+ } else {
+ $('#my_gift_message').html('');
+ $('#my_gift').hide();
+ $('#gift_message').val('');
+ $('#gift_div').hide();
+ $('#gift').removeAttr('checked');
+ }
+ }
+ },
+ error: function(XMLHttpRequest, textStatus, errorThrown) {alert("TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);}
+ });
+}
+
function updateCustomizedDatas(json)
{
for(i in json)
diff --git a/themes/site/order-carrier.tpl b/themes/site/order-carrier.tpl
index 35ca2cfb..f44ac994 100755
--- a/themes/site/order-carrier.tpl
+++ b/themes/site/order-carrier.tpl
@@ -252,7 +252,7 @@
- {if $giftAllowed}
+ {* {if $giftAllowed}
{l s='Gift'}
gift == 1}checked="checked"{/if} onclick="$('#gift_div').toggle('slow');" />
@@ -269,7 +269,7 @@
- {/if}
+ {/if} *}
{/if}
{/if}
diff --git a/themes/site/shopping-cart.tpl b/themes/site/shopping-cart.tpl
index c42861b4..1c7c8672 100755
--- a/themes/site/shopping-cart.tpl
+++ b/themes/site/shopping-cart.tpl
@@ -316,6 +316,36 @@
+{if $giftAllowed}
+ gift == 0} style="display:none;" {/if}>
+ {l s='My message : '}
+ {nl2br($cart->gift_message)|escape:'UTF-8'}
+
+ {l s='Gift'}
+
+ gift == 1}checked="checked"{/if} onclick="$('#gift_div').toggle('slow');" />
+
+
+
+
+
+ {l s='Enregistré'} {l s='Supprimer'}
+
+
+ {if !$virtual_cart && $giftAllowed && $cart->gift == 1}
+
+ {/if}
+{/if}
+
{if $site_version == 'es'}
{l s='Pago seguro, datos encriptados'}
{/if}