Merge branch 'ticket-13564-giftOnShoppingCart' into develop

This commit is contained in:
Marion Muszynski 2017-07-03 10:15:38 +02:00
commit eef4d0f4b9
9 changed files with 203 additions and 42 deletions

View File

@ -1,6 +1,6 @@
<?php
/*
* 2007-2011 PrestaShop
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
@ -37,7 +37,7 @@ class AdminCustomers extends AdminTab
$this->delete = true;
$this->deleted = true;
$this->requiredDatabase = true;
$this->_select = '
IFNULL(ci.`version`, "fr") AS `version`
';
@ -78,11 +78,11 @@ class AdminCustomers extends AdminTab
parent::__construct();
}
public function postProcess()
{
global $currentIndex;
if (Tools::isSubmit('submitDel'.$this->table) OR Tools::isSubmit('delete'.$this->table))
{
$deleteForm = '
@ -108,11 +108,11 @@ class AdminCustomers extends AdminTab
</form>
<div class="clear">&nbsp;</div>';
}
if (Tools::getValue('submitAdd'.$this->table))
{
$groupList = Tools::getValue('groupBox');
/* Checking fields validity */
$this->validateRules();
if (!sizeof($this->_errors))
@ -128,7 +128,7 @@ class AdminCustomers extends AdminTab
if (Validate::isLoadedObject($object))
{
$customer_email = strval(Tools::getValue('email'));
// check if e-mail already used
if ($customer_email != $object->email)
{
@ -137,14 +137,14 @@ class AdminCustomers extends AdminTab
if ($customer->id)
$this->_errors[] = Tools::displayError('An account already exists for this e-mail address:').' '.$customer_email;
}
if (!is_array($groupList) OR sizeof($groupList) == 0)
$this->_errors[] = Tools::displayError('Customer must be in at least one group.');
else
if (!in_array(Tools::getValue('id_default_group'), $groupList))
$this->_errors[] = Tools::displayError('Default customer group must be selected in group box.');
// Updating customer use credits
// Updating customer use credits
$sql = 'SELECT id_customer FROM `'._DB_PREFIX_.'customer_credits` WHERE id_customer = ' .$object->id;
if(Db::getInstance()->getValue($sql)){
// already present
@ -157,7 +157,7 @@ class AdminCustomers extends AdminTab
Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'customer_credits` VALUES ('. $object->id . ')');
}
}
// Updating customer's group
if (!sizeof($this->_errors))
{
@ -207,6 +207,7 @@ class AdminCustomers extends AdminTab
case 'real':
$this->deleted = false;
Discount::deleteByIdCustomer((int)(Tools::getValue('id_customer')));
Db::getInstance()->Execute('UPDATE `'._DB_PREFIX_.'customer_thread` SET `id_customer` = 0 WHERE `id_customer` = '.(int)(Tools::getValue('id_customer')));
break;
case 'deleted':
$this->deleted = true;
@ -226,8 +227,10 @@ class AdminCustomers extends AdminTab
{
case 'real':
$this->deleted = false;
foreach (Tools::getValue('customerBox') as $id_customer)
foreach (Tools::getValue('customerBox') as $id_customer){
Db::getInstance()->Execute('UPDATE `'._DB_PREFIX_.'customer_thread` SET `id_customer` = 0 WHERE `id_customer` = '.(int)$id_customer);
Discount::deleteByIdCustomer((int)($id_customer));
}
break;
case 'deleted':
$this->deleted = true;
@ -266,7 +269,7 @@ class AdminCustomers extends AdminTab
$update = Db::getInstance()->Execute('UPDATE `'._DB_PREFIX_.'customer` SET newsletter = '.($customer->newsletter ? 0 : 1).' WHERE `id_customer` = '.(int)($customer->id));
if (!$update)
$this->_errors[] = Tools::displayError('An error occurred while updating customer.');
Tools::redirectAdmin($currentIndex.'&token='.$this->token);
Tools::redirectAdmin($currentIndex.'&token='.$this->token);
}elseif (Tools::isSubmit('changeOptinVal') AND Tools::getValue('id_customer'))
{
@ -279,7 +282,7 @@ class AdminCustomers extends AdminTab
$this->_errors[] = Tools::displayError('An error occurred while updating customer.');
Tools::redirectAdmin($currentIndex.'&token='.$this->token);
}
return parent::postProcess();
}
@ -351,7 +354,7 @@ class AdminCustomers extends AdminTab
echo '
</fieldset>
<div class="clear">&nbsp;</div>';
echo '<fieldset style="height:190px"><legend><img src="../img/admin/cms.gif" /> '.$this->l('Add a private note').'</legend>
<p>'.$this->l('This note will be displayed to all the employees but not to the customer.').'</p>
<form action="ajax.php" method="post" onsubmit="saveCustomerNote();return false;" id="customer_note">
@ -381,8 +384,8 @@ class AdminCustomers extends AdminTab
});
}
</script>';
echo '<h2>'.$this->l('Messages').' ('.sizeof($messages).')</h2>';
if (sizeof($messages))
{
@ -496,7 +499,7 @@ class AdminCustomers extends AdminTab
}
else
echo $customer->firstname.' '.$customer->lastname.' '.$this->l('has not placed any orders yet');
if ($products AND sizeof($products))
{
echo '<div class="clear">&nbsp;</div>
@ -592,7 +595,7 @@ class AdminCustomers extends AdminTab
else
echo $customer->firstname.' '.$customer->lastname.' '.$this->l('has no discount vouchers').'.';
echo '<div class="clear">&nbsp;</div>';
echo '<div style="float:left">
<h2>'.$this->l('Carts').' ('.sizeof($carts).')</h2>';
if ($carts AND sizeof($carts))
@ -628,7 +631,7 @@ class AdminCustomers extends AdminTab
else
echo $this->l('No cart available').'.';
echo '</div>';
$interested = Db::getInstance()->ExecuteS('SELECT DISTINCT id_product FROM '._DB_PREFIX_.'cart_product cp INNER JOIN '._DB_PREFIX_.'cart c on c.id_cart = cp.id_cart WHERE c.id_customer = '.(int)$customer->id.' AND cp.id_product NOT IN (
SELECT product_id FROM '._DB_PREFIX_.'orders o inner join '._DB_PREFIX_.'order_detail od ON o.id_order = od.id_order WHERE o.valid = 1 AND o.id_customer = '.(int)$customer->id.')');
if (count($interested))
@ -648,12 +651,12 @@ class AdminCustomers extends AdminTab
}
echo '</table></div>';
}
echo '<div class="clear">&nbsp;</div>';
/* Last connections */
$connections = $customer->getLastConnections();
if (sizeof($connections))
if (sizeof($connections))
{
echo '<h2>'.$this->l('Last connections').'</h2>
<table cellspacing="0" cellpadding="0" class="table">
@ -674,7 +677,7 @@ class AdminCustomers extends AdminTab
</tr>';
echo '</table><div class="clear">&nbsp;</div>';
}
if (sizeof($referrers))
if (sizeof($referrers))
{
echo '<h2>'.$this->l('Referrers').'</h2>
<table cellspacing="0" cellpadding="0" class="table">
@ -696,10 +699,10 @@ class AdminCustomers extends AdminTab
{
global $currentIndex;
parent::displayForm();
if (!($obj = $this->loadObject(true)))
return;
$birthday = explode('-', $this->getFieldValue($obj, 'birthday'));
$customer_groups = Tools::getValue('groupBox', $obj->getGroups());
$groups = Group::getGroups($this->_defaultFormLanguage, true);
@ -710,7 +713,7 @@ class AdminCustomers extends AdminTab
}else{
$obj->use_credits = "1";
}
echo '
<form action="'.$currentIndex.'&submitAdd'.$this->table.'=1&token='.$this->token.'" method="post" autocomplete="off">
'.($obj->id ? '<input type="hidden" name="id_'.$this->table.'" value="'.$obj->id.'" />' : '').'
@ -805,7 +808,7 @@ class AdminCustomers extends AdminTab
<input type="radio" name="optin" id="optin_off" value="0" '.(!$this->getFieldValue($obj, 'optin') ? 'checked="checked" ' : '').'/>
<label class="t" for="optin_off"><img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>
<p>'.$this->l('Customer will receive your ads via e-mail').'</p>
</div>
</div>
<label>'.$this->l('Parrainage:').' </label>
<div class="margin-form">
<input type="radio" name="use_credits" id="credits_on" value="1" '.($this->getFieldValue($obj, 'use_credits') ? 'checked="checked" ' : '').'/>
@ -865,7 +868,7 @@ class AdminCustomers extends AdminTab
global $cookie;
return parent::getList((int)($cookie->id_lang), !Tools::getValue($this->table.'Orderby') ? 'date_add' : NULL, !Tools::getValue($this->table.'Orderway') ? 'DESC' : NULL);
}
public function beforeDelete($object)
{
return $object->isUsed();

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

@ -7371,4 +7371,60 @@ table#carrierTable tbody td {
top: 0;
width: 100%;
z-index: 800;
}
#order #center_column #gift_div textarea {
margin-bottom: 5px;
}
#my_gift{
text-align: center;
margin-bottom: 10px;
border: 1px solid #BDC2C9;
padding: 5px;
background-color: #F1F2F4;
position: relative;
}
.my_gift{
font-size: 16px;
color: #514c8c;
font-weight: normal;
text-shadow: 0px 1px 0px #ffffff;
line-height: 1.5em;
text-transform: none;
margin-bottom: 10px;
font-family: georgia, times new roman, serif;
font-style: italic;
}
.remove_message_gift{
background: #e26ea2;
color: #fff;
position: absolute;
top: 5px;
right: 5px;
padding: 2px 7px;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
border-radius: 50%;
cursor: pointer;
}
#cart_add_gift_message,
#cart_remove_gift_message{
text-align: center;
text-transform: none;
border: 0px;
color: #ffffff;
padding: 5px 10px;
text-decoration: none;
font-weight: normal;
background: #504d8b;
-moz-border-radius: 20px;
-webkit-border-radius: 20px;
border-radius: 20px;
font-family: georgia, times new roman, serif;
font-style: italic;
font-size: 13px;
}
#cart_remove_gift_message{
float:right;
background: #e26ea2;
}

View File

@ -32,7 +32,10 @@ $(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(){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); return false; });
}
});
@ -473,6 +476,54 @@ 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
{
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="remove_message_gift">X</span>
<span class="my_gift">{l s='My message : '}</span><br>
<span id="my_gift_message">{nl2br($cart->gift_message)|escape:'UTF-8'}<span>
</p>
<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}

View File

@ -100,11 +100,14 @@ var oneQuantityAvailableSentence = '{l s='Warning: 1 item in stock!' js=1}';
<div class="product_title">
<h1 class="title sale_title">
{if isset($smarty.server.HTTP_REFERER) && preg_replace('#^https?://[^/]+/#', '/', $smarty.server.HTTP_REFERER) != $request_uri}
<span class="gradient">
<a href="javascript:history.back()" class="button_small back" title="{l s='Back'}">{l s='Back'}</a>
</span>
{* {if isset($smarty.server.HTTP_REFERER) && preg_replace('#^https?://[^/]+/#', '/', $smarty.server.HTTP_REFERER) != $request_uri}
<span class="gradient">
<a href="{$smarty.server.HTTP_REFERER|escape:'htmlall':'UTF-8'|secureReferrer}" class="button_small back" title="{l s='Back'}">{l s='Back'}</a>
</span>
{/if}
{/if} *}
<span>{$product->name|truncate:30:'...':true:false}</span>
</h1>
</div>