fix conflict

This commit is contained in:
Marion Muszynski 2016-06-28 14:47:38 +02:00
commit 757c557a07
6 changed files with 479 additions and 9 deletions

View File

@ -218,8 +218,11 @@ var ajaxCart = {
WishlistAddProductCart(whishlist[0], idProduct, idCombination, whishlist[1]);
ajaxCart.updateCartInformation(jsonData, addedFromProductPage);
if(!jsonData.errors) {
confirmation(idProduct, idCombination, quantity);
} else if (jsonData.popup_error_cart){
cannotAdd(idProduct, idCombination, quantity, jsonData.errors[0]);
}
},
error: function(XMLHttpRequest, textStatus, errorThrown)
@ -535,12 +538,18 @@ var ajaxCart = {
//user errors display
if (jsonData.hasError)
{
var errors = '';
for(error in jsonData.errors)
//IE6 bug fix
if(error != 'indexOf')
errors += jsonData.errors[error] + "\n";
alert(errors);
if (jsonData.popup_error_cart) {
$('.overlay_bbb').fadeIn();
$('#box_error_cart_text').text(jsonData.errors[0]);
$('#box_error_cart').fadeIn();
} else {
var errors = '';
for(error in jsonData.errors)
//IE6 bug fix
if(error != 'indexOf')
errors += jsonData.errors[error] + "\n";
alert(errors);
}
}
else
{
@ -637,7 +646,7 @@ function confirmation(idProduct, idCombination, quantity) {
success: function(jsonData) {
window.parent.jQuery('body').append(jsonData);
window.parent.$('.overlay_bbb').fadeIn();
window.parent.$('.box_add_to_cart').fadeIn();
window.parent.$('.box_add_to_cart').fadeIn();
},
error: function() {alert('ERROR: unable to delete the product');}
});
@ -645,6 +654,41 @@ function confirmation(idProduct, idCombination, quantity) {
}
function cannotAdd(idProduct, idCombination, quantity, error_text){
$.ajax({
type: 'POST',
url: baseDir + 'modules/blockcartex/ajax.php',
async: true,
cache: false,
dataType : "html",
data: 'id_product=' + idProduct +'&idCombination='+ idCombination +'&quantity='+quantity,
success: function(jsonData) {
window.parent.jQuery('body').append(jsonData);
window.parent.$('#box_error_cart_text').text(error_text);
window.parent.$('.overlay_bbb').fadeIn();
window.parent.$('#box_error_cart').fadeIn();
},
error: function() {alert('ERROR: unable to delete the product');}
});
}
function removeAllCart() {
$.ajax({
type: 'POST',
url: baseDir + 'cart.php',
async: true,
cache: false,
dataType : "json",
data: 'removeall=1&token=' + static_token + '&ajax=true',
success: function(jsonData) {
ajaxCart.updateCart(jsonData);
$('.overlay_bbb').fadeOut();
$('#box_error_cart').fadeOut();
},
error: function() {alert('ERROR: unable to remove your cart');}
});
}
//when document is loaded...
$(document).ready(function(){
@ -664,9 +708,14 @@ $(document).ready(function(){
$('.overlay_bbb').fadeOut();
$('.box_add_to_cart').fadeOut();
});
$('#close_error_cart').live('click', function(e){
$('.overlay_bbb').fadeOut();
$('#box_error_cart').fadeOut();
});
$('.overlay_bbb').live('click', function(e){
$('.overlay_bbb').fadeOut();
$('.box_add_to_cart').fadeOut();
$('#box_error_cart').fadeOut();
});
});

View File

@ -31,4 +31,22 @@
<h3>{l s='Nos meilleures ventes' mod='blockcartex'}</h3>
{$bestSaleCart}
</div>
</div>
</div>
<div id="box_error_cart">
<div class="content">
<h3>{l s='Warning' mod='blockcartex'}</h3>
<div class="close" id="close_error_cart">
<img src="{$img_dir}close.jpg" alt="{l s='Fermer' mod='blockcartex'}">
</div>
<div class="product_box">
<p id='box_error_cart_text'></p>
</div>
<div class="others_links">
<a class="show_cart" href="{$link->getPageLink('order.php')}">{l s='Valider mon panier' mod='blockcartex'}</a>
<a class="show_sales" id="remove_cart" href="#" onclick="removeAllCart();">{l s='Vider mon panier' mod='blockcartex'}</a>
<a class="show_sales" href="{$link->getPageLink('index.php')}">{l s='Retourner à la vente' mod='blockcartex'}</a>
</div>
</div>
</div>

View File

@ -0,0 +1,284 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 10176 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
include_once dirname(__FILE__).'/../../modules/privatesales/Sale.php';
class CartController extends CartControllerCore
{
public function preProcess()
{
FrontController::preProcess();
$orderTotal = self::$cart->getOrderTotal(true, Cart::ONLY_PRODUCTS);
$this->cartDiscounts = self::$cart->getDiscounts();
foreach ($this->cartDiscounts AS $k => $this->cartDiscount)
if ($error = self::$cart->checkDiscountValidity(new Discount((int)($this->cartDiscount['id_discount'])), $this->cartDiscounts, $orderTotal, self::$cart->getProducts()))
self::$cart->deleteDiscount((int)($this->cartDiscount['id_discount']));
$add = Tools::getIsset('add') ? 1 : 0;
$delete = Tools::getIsset('delete') ? 1 : 0;
$removeAll = Tools::getIsset('removeall') ? 1 : 0;
if (Configuration::get('PS_TOKEN_ENABLE') == 1
&& strcasecmp(Tools::getToken(false), strval(Tools::getValue('token')))
&& self::$cookie->isLogged() === true)
$this->errors[] = Tools::displayError('Invalid token');
// Update the cart ONLY if $this->cookies are available, in order to avoid ghost carts created by bots
if (($add OR Tools::getIsset('update') OR $delete) AND isset($_COOKIE[self::$cookie->getName()]))
{
//get the values
$idProduct = (int)(Tools::getValue('id_product', NULL));
$idProductAttribute = (int)(Tools::getValue('id_product_attribute', Tools::getValue('ipa')));
$customizationId = (int)(Tools::getValue('id_customization', 0));
$qty = (int)(abs(Tools::getValue('qty', 1)));
// @Adding Antadis - Prevent multi sales
if ($add){
$current_sale = array();
foreach(self::$cart->getProducts() as $product) {
/*$current_sale = Db::getInstance()->getRow('
SELECT ps.`delivery_delay`, ps.`id_sale`
FROM `'._DB_PREFIX_.'product_ps_cache` psc
LEFT JOIN `'._DB_PREFIX_.'privatesale` ps ON (ps.`id_sale` = psc.`id_sale`)
WHERE psc.`id_product` = '.(int) $product['id_product']
);*/
$sale = Sale::getSaleFromCategory((int)$product['id_category_default'], false);
$current_sale = array(
'id_sale'=> (int) $sale->id,
'delivery_delay'=> (int) $sale->delivery_delay
);
// Only one delivery id per cart, so we can break now
break;
}
/*if (Tools::getValue('ajax') == 'true') {
die('{"hasError" : true, "id_current_sale": '.$sale->id.',"id_delivery": '.$sale->delivery_delay.', "errors" : ["'.Tools::displayError('Sorry your cart already contains products from a sale shipped within 3 weeks. To continue, please confirm your order or empty your cart.', false).'"]}');
}*/
/*$adding_sale = Db::getInstance()->getRow('
SELECT ps.`delivery_delay`, ps.`id_sale`
FROM `'._DB_PREFIX_.'product_ps_cache` psc
LEFT JOIN `'._DB_PREFIX_.'privatesale` ps ON (ps.`id_sale` = psc.`id_sale`)
WHERE psc.`id_product` = '.(int) $idProduct
);*/
$current_product = new Product((int) $idProduct);
$sale2 = Sale::getSaleFromCategory($current_product->id_category_default, false);
$adding_sale = array(
'id_sale'=> (int) $sale2->id,
'delivery_delay'=> (int) $sale2->delivery_delay
);
if (!empty($current_sale)) {
global $smarty;
// Only classic delivery sales can be added together or product of the same sale
if ($current_sale['delivery_delay'] != 1 && $adding_sale['id_sale'] != $current_sale['id_sale']) {
// Product in cart comes from special delivery sale - only products from the same sale can be added
if (Tools::getValue('ajax') == 'true') {
die('{"hasError" : true, "popup_error_cart": true, "errors" : ["'.Tools::displayError('Sorry your cart already contains products from a sale shipped within a special period. To continue, please confirm your order or empty your cart.', false).'"]}');
} else {
$this->errors[] = Tools::displayError('Sorry your cart already contains products from a sale shipped within a special period. To continue, please confirm your order or empty your cart.', false);
/*$smarty->assign("popup_error_cart",1);*/
}
} elseif ($current_sale['delivery_delay'] == 1 && $adding_sale['delivery_delay'] != 1) {
// Product in cart comes from classic delivery sale - only products from classic delivery sale can be added
if (Tools::getValue('ajax') == 'true') {
die('{"hasError" : true, "popup_error_cart": true, "errors" : ["'.Tools::displayError('Sorry your cart already contains products from a sale shipped within 3 weeks. To continue, please confirm your order or empty your cart.', false).'"]}');
} else {
$this->errors[] = Tools::displayError('Sorry your cart already contains products from a sale shipped within 3 weeks. To continue, please confirm your order or empty your cart.', false);
/*$smarty->assign("popup_error_cart",1);*/
}
}
}
}
// @End adding Antadis
if ($qty == 0)
$this->errors[] = Tools::displayError('Null quantity');
elseif (!$idProduct)
$this->errors[] = Tools::displayError('Product not found');
else
{
$producToAdd = new Product((int)($idProduct), true, (int)(self::$cookie->id_lang));
if ((!$producToAdd->id OR !$producToAdd->active) AND !$delete)
if (Tools::getValue('ajax') == 'true')
die('{"hasError" : true, "errors" : ["'.Tools::displayError('Product is no longer available.', false).'"]}');
else
$this->errors[] = Tools::displayError('Product is no longer available.', false);
else
{
/* Check the quantity availability */
if ($idProductAttribute AND is_numeric($idProductAttribute))
{
if (!$delete AND !$producToAdd->isAvailableWhenOutOfStock($producToAdd->out_of_stock) AND !Attribute::checkAttributeQty((int)$idProductAttribute, (int)$qty))
if (Tools::getValue('ajax') == 'true')
die('{"hasError" : true, "errors" : ["'.Tools::displayError('There is not enough product in stock.', false).'"]}');
else
$this->errors[] = Tools::displayError('There is not enough product in stock.');
}
elseif ($producToAdd->hasAttributes() AND !$delete)
{
$idProductAttribute = Product::getDefaultAttribute((int)$producToAdd->id, (int)$producToAdd->out_of_stock == 2 ? !(int)Configuration::get('PS_ORDER_OUT_OF_STOCK') : !(int)$producToAdd->out_of_stock);
if (!$idProductAttribute)
Tools::redirectAdmin($link->getProductLink($producToAdd));
elseif (!$delete AND !$producToAdd->isAvailableWhenOutOfStock($producToAdd->out_of_stock) AND !Attribute::checkAttributeQty((int)$idProductAttribute, (int)$qty))
if (Tools::getValue('ajax') == 'true')
die('{"hasError" : true, "errors" : ["'.Tools::displayError('There is not enough product in stock.', false).'"]}');
else
$this->errors[] = Tools::displayError('There is not enough product in stock.');
}
elseif (!$delete AND !$producToAdd->checkQty((int)$qty))
if (Tools::getValue('ajax') == 'true')
die('{"hasError" : true, "errors" : ["'.Tools::displayError('There is not enough product in stock.').'"]}');
else
$this->errors[] = Tools::displayError('There is not enough product in stock.');
/* Check vouchers compatibility */
if ($add AND (($producToAdd->specificPrice AND (float)($producToAdd->specificPrice['reduction'])) OR $producToAdd->on_sale))
{
$discounts = self::$cart->getDiscounts();
$hasUndiscountedProduct = null;
foreach($discounts as $discount)
{
if (is_null($hasUndiscountedProduct))
{
$hasUndiscountedProduct = false;
foreach(self::$cart->getProducts() as $product)
if ($product['reduction_applies'] === false)
{
$hasUndiscountedProduct = true;
break;
}
}
if (!$discount['cumulable_reduction'] && ($discount['id_discount_type'] != 1 || !$hasUndiscountedProduct))
if (Tools::getValue('ajax') == 'true')
die('{"hasError" : true, "errors" : ["'.Tools::displayError('Cannot add this product because current voucher does not allow additional discounts.').'"]}');
else
$this->errors[] = Tools::displayError('Cannot add this product because current voucher does not allow additional discounts.');
}
}
if (!sizeof($this->errors))
{
if ($add AND $qty >= 0)
{
/* Product addition to the cart */
if (!isset(self::$cart->id) OR !self::$cart->id)
{
self::$cart->add();
if (self::$cart->id)
self::$cookie->id_cart = (int)(self::$cart->id);
}
if ($add AND !$producToAdd->hasAllRequiredCustomizableFields() AND !$customizationId)
$this->errors[] = Tools::displayError('Please fill in all required fields, then save the customization.');
if (!sizeof($this->errors))
{
$updateQuantity = self::$cart->updateQty((int)($qty), (int)($idProduct), (int)($idProductAttribute), $customizationId, Tools::getValue('op', 'up'));
if ($updateQuantity < 0)
{
/* if product has attribute, minimal quantity is set with minimal quantity of attribute*/
if ((int)$idProductAttribute)
$minimal_quantity = Attribute::getAttributeMinimalQty((int)$idProductAttribute);
else
$minimal_quantity = $producToAdd->minimal_quantity;
if (Tools::getValue('ajax') == 'true')
die('{"hasError" : true, "errors" : ["'.Tools::displayError('You must add', false).' '.$minimal_quantity.' '.Tools::displayError('Minimum quantity', false).'"]}');
else
$this->errors[] = Tools::displayError('You must add').' '.$minimal_quantity.' '.Tools::displayError('Minimum quantity')
.((isset($_SERVER['HTTP_REFERER']) AND basename($_SERVER['HTTP_REFERER']) == 'order.php' OR (!Tools::isSubmit('ajax') AND substr(basename($_SERVER['REQUEST_URI']),0, strlen('cart.php')) == 'cart.php')) ? ('<script language="javascript">setTimeout("history.back()",5000);</script><br />- '.
Tools::displayError('You will be redirected to your cart in a few seconds.')) : '');
}
elseif (!$updateQuantity)
{
if (Tools::getValue('ajax') == 'true')
die('{"hasError" : true, "errors" : ["'.Tools::displayError('You already have the maximum quantity available for this product.', false).'"]}');
else
$this->errors[] = Tools::displayError('You already have the maximum quantity available for this product.')
.((isset($_SERVER['HTTP_REFERER']) AND basename($_SERVER['HTTP_REFERER']) == 'order.php' OR (!Tools::isSubmit('ajax') AND substr(basename($_SERVER['REQUEST_URI']),0, strlen('cart.php')) == 'cart.php')) ? ('<script language="javascript">setTimeout("history.back()",5000);</script><br />- '.
Tools::displayError('You will be redirected to your cart in a few seconds.')) : '');
}
}
}
elseif ($delete)
{
if (self::$cart->deleteProduct((int)($idProduct), (int)($idProductAttribute), (int)($customizationId)))
if (!Cart::getNbProducts((int)(self::$cart->id)))
{
self::$cart->id_carrier = 0;
self::$cart->gift = 0;
self::$cart->gift_message = '';
self::$cart->update();
}
}
}
$discounts = self::$cart->getDiscounts();
foreach($discounts AS $discount)
{
$discountObj = new Discount((int)($discount['id_discount']), (int)(self::$cookie->id_lang));
if ($error = self::$cart->checkDiscountValidity($discountObj, $discounts, self::$cart->getOrderTotal(true, Cart::ONLY_PRODUCTS), self::$cart->getProducts()))
{
self::$cart->deleteDiscount((int)($discount['id_discount']));
self::$cart->update();
$errors[] = $error;
}
}
if (!sizeof($this->errors))
{
$queryString = Tools::safeOutput(Tools::getValue('query', NULL));
if ($queryString AND !Configuration::get('PS_CART_REDIRECT'))
Tools::redirect('search.php?search='.$queryString);
if (isset($_SERVER['HTTP_REFERER']))
{
// Redirect to previous page
preg_match('!http(s?)://(.*)/(.*)!', $_SERVER['HTTP_REFERER'], $regs);
if (isset($regs[3]) AND !Configuration::get('PS_CART_REDIRECT') AND Tools::getValue('ajax') != 'true')
Tools::redirect($_SERVER['HTTP_REFERER']);
}
}
}
if (Tools::getValue('ajax') != 'true' AND !sizeof($this->errors))
Tools::redirect('order.php?'.(isset($idProduct) ? 'ipa='.(int)($idProduct) : ''));
}
}
// @Adding Antadis - remove whole cart
if ($removeAll) {
foreach(self::$cart->getProducts() as $product) {
if (self::$cart->deleteProduct((int)($product['id_product']), (int)($product['id_product_attribute']), (int)($product['id_customization']))) {
if (!Cart::getNbProducts((int)(self::$cart->id)))
{
self::$cart->id_carrier = 0;
self::$cart->gift = 0;
self::$cart->gift_message = '';
self::$cart->update();
}
}
}
}
// @End adding Antadis
}
}

View File

@ -6569,6 +6569,89 @@ table#carrierTable tbody td {
text-align: center;
}
/***** New popup error - ticket 10233 prevent multi ******/
#box_error_cart{
display: none;
box-shadow: 2px 2px 5px 0px rgba(0, 0, 0, 0.1);
position: fixed;
top: 150px;
z-index: 99999;
background: rgba(255,255,255,0.4);
width: 550px;
left: 50%;
margin: 0 auto;
margin-left: -295px;
padding: 20px;
}
#box_error_cart .close{
position: absolute;
right: 40px;
top: 40px;
cursor: pointer;
}
#box_error_cart .content{
background: #fff;
padding: 15px;
}
#box_error_cart .content_best_sales h3,
#box_error_cart .content h3{
color:#54508b;
font-size: 24px;
padding-bottom: 10px;
border-bottom: 4px double #ccc;
font-family: Georgia;
}
#box_error_cart .content .product_box{
float: left;
font-family: Tahoma;
width: 100%;
overflow: auto;
}
#box_error_cart_text {
text-align: center;
margin-bottom: 10px;
}
#box_error_cart .content .others_links{
border-top: 1px solid #ccc;
padding-top: 15px;
clear: both;
overflow: hidden;
text-align: center;
}
#box_error_cart .content .others_links .show_sales{
height: 15px;
line-height: 14px;
color: #FFF;
margin: 0px;
padding: 7px 20px 6px;
background:#B5B1B1;
border-radius: 20px;
text-decoration: none;
/* float: left; */
display: inline-block;
}
#box_error_cart .content .others_links #remove_cart{
margin:0 25px;
}
#box_error_cart .content .others_links .show_sales:hover{ background: #f45bb7;}
#box_error_cart .content .others_links .show_cart{
height: 15px;
line-height: 14px;
color: #FFF;
margin: 0px;
padding: 7px 20px 6px;
background:url("../img/achat_express.jpg") no-repeat scroll left center #504D8B;
border-radius: 20px;
text-decoration: none;
/* float: left; */
display: inline-block;
padding-left: 50px;
}
#box_error_cart .content .others_links .show_cart:hover {
background: url("../img/achat_express.jpg") no-repeat scroll left center #f45bb7;
}
@keyframes slideInDown {
0% {
-webkit-transform: translateY(-500px);

View File

@ -31,4 +31,22 @@
<h3>{l s='Nos meilleures ventes' mod='blockcartex'}</h3>
{$bestSaleCart}
</div>
</div>
</div>
<div id="box_error_cart">
<div class="content">
<h3>{l s='Warning' mod='blockcartex'}</h3>
<div class="close" id="close_error_cart">
<img src="{$img_dir}close.jpg" alt="{l s='Fermer' mod='blockcartex'}">
</div>
<div class="product_box">
<p id='box_error_cart_text'></p>
</div>
<div class="others_links">
<a class="show_cart" href="{$link->getPageLink('order.php')}">{l s='Valider mon panier' mod='blockcartex'}</a>
<a class="show_sales" id="remove_cart" href="#" onclick="removeAllCart();">{l s='Vider mon panier' mod='blockcartex'}</a>
<a class="show_sales" href="{$link->getPageLink('index.php')}">{l s='Retourner à la vente' mod='blockcartex'}</a>
</div>
</div>
</div>

View File

@ -32,4 +32,22 @@
<h3>{l s='Nos meilleures ventes'}</h3>
{$bestSaleCart}
</div>
</div>
<div id="box_error_cart">
<div class="content">
<h3>{l s='Warning' mod='blockcartex'}</h3>
<div class="close" id="close_error_cart">
<img src="{$img_dir}close.jpg" alt="{l s='Fermer' mod='blockcartex'}">
</div>
<div class="product_box">
<p id='box_error_cart_text'></p>
</div>
<div class="others_links">
<a class="show_cart" href="{$link->getPageLink('order.php')}">{l s='Valider mon panier' mod='blockcartex'}</a>
<a class="show_sales" id="remove_cart" href="#" onclick="removeAllCart();">{l s='Vider mon panier' mod='blockcartex'}</a>
<a class="show_sales" href="{$link->getPageLink('index.php')}">{l s='Retourner à la vente' mod='blockcartex'}</a>
</div>
</div>
</div>