moving gift message to shopping cart step

This commit is contained in:
Marion Muszynski 2017-06-30 12:57:06 +02:00
parent 967eac2c06
commit 13b68d20ae
7 changed files with 122 additions and 12 deletions

View File

@ -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')))
{

View File

@ -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),

View File

@ -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
}
}

View File

@ -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;
}

View File

@ -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, "<br/>"));
$('#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)

View File

@ -252,7 +252,7 @@
</table>
<div style="display: none;" id="extra_carrier"></div>
{if $giftAllowed}
{* {if $giftAllowed}
<h3 class="gift_title">{l s='Gift'}</h3>
<p class="checkbox">
<input type="checkbox" name="gift" id="gift" value="1" {if $cart->gift == 1}checked="checked"{/if} onclick="$('#gift_div').toggle('slow');" />
@ -269,7 +269,7 @@
<label for="gift_message">{l s='If you wish, you can add a note to the gift:'}</label>
<textarea rows="5" cols="35" id="gift_message" name="gift_message">{$cart->gift_message|escape:'htmlall':'UTF-8'}</textarea>
</p>
{/if}
{/if} *}
{/if}
{/if}

View File

@ -316,6 +316,36 @@
</table>
</div>
{if $giftAllowed}
<p id="my_gift" {if $cart->gift == 0} style="display:none;" {/if}>
<span class="my_gift">{l s='My message : '}</span><br>
<span id="my_gift_message">{nl2br($cart->gift_message)|escape:'UTF-8'}<span>
</p>
<h3 class="gift_title">{l s='Gift'}</h3>
<p class="checkbox">
<input type="checkbox" name="gift" id="gift" value="1" {if $cart->gift == 1}checked="checked"{/if} onclick="$('#gift_div').toggle('slow');" />
<label for="gift">{l s='I would like the order to be gift-wrapped.'}</label>
</p>
<p id="gift_div" class="textarea">
<label for="gift_message">{l s='If you wish, you can add a note to the gift:'}</label>
<textarea rows="5" cols="35" id="gift_message" name="gift_message">{$cart->gift_message|escape:'htmlall':'UTF-8'}</textarea>
<a id="cart_add_gift_message" class="exclusive">{l s='Enregistré'}</a> <a id="cart_remove_gift_message" class="exclusive">{l s='Supprimer'}</a>
<div class="clear"></div>
</p>
{if !$virtual_cart && $giftAllowed && $cart->gift == 1}
<script type="text/javascript">
{literal}
// <![CDATA[
$('document').ready( function(){
if ($('input#gift').is(':checked'))
$('p#gift_div').show();
});
//]]>
{/literal}
</script>
{/if}
{/if}
{if $site_version == 'es'}
<p class="safety-payment">{l s='Pago seguro, datos encriptados'}</p>
{/if}