Merge branch 'ticket-12397-LinkCategoryWithDiscount' into develop

This commit is contained in:
Marion Muszynski 2017-01-30 15:08:27 +01:00
commit fce0de0f03
2 changed files with 95 additions and 35 deletions

View File

@ -955,9 +955,15 @@ $(document).ready(function () {
// Check contact infos
var phone_mobile = /^((\+|00)33\s?|0)[67](\s?\d{2}){4}$/i;
var phone_mobile_es = /^((\+|00)34\s?|0)[67](\s?\d{2}){4}$/i;
var phone_mobile_without_zero = /^[67](\s?\d{2}){4}$/i;
var phone_mobile_be = /^((\+|00)32\s?|0)4(60|[789]\d)(\s?\d{2}){3}$/i;
var phone_mobile_without_zero_be = /^4(60|[789]\d)(\s?\d{2}){3}$/i;
var phone_mobile_es = /^((\+|00)34\s?\d{1}|6)(\s?\d{2}){4}$/i;
var phone_mobile_it = /^(((\+|00)39\s?[03])|[03])(\s?\d{1}){9}$/i;
var email = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/i;
if (!email.test($('#custMail').val())) {
@ -973,15 +979,52 @@ $(document).ready(function () {
return (false);
}
if($('#custPhone').val().length == 9 && !phone_mobile_without_zero.test($('#custPhone').val())){
if($('#sl-0-country').val() == 'FR') {
if($('#custPhone').val().length == 9 && !phone_mobile_without_zero.test($('#custPhone').val())) {
ev.preventDefault();
alert($('#error-mobile-invalid').val() + '\n\nFormat : 0681010203 ou 0033681010203');
return (false);
} else if($('#custPhone').val().length > 9 && !(phone_mobile.test($('#custPhone').val()))) {
ev.preventDefault();
alert($('#error-mobile-invalid').val() + '\n\nFormat : 0681010203 ou 0033681010203');
return (false);
}
}
if($('#sl-0-country').val() == 'BE'){
if($('#custPhone').val().length == 9 && !(phone_mobile_without_zero_be.test($('#custPhone').val()))){
ev.preventDefault();
alert($('#error-mobile-invalid').val() + '\n\nFormat : 0461010203 ou 0032461010203');
return (false);
}else if($('#custPhone').val().length > 9 && !(phone_mobile_be.test($('#custPhone').val()))) {
ev.preventDefault();
alert($('#error-mobile-invalid').val() + '\n\nFormat : 0461010203 ou 0032461010203');
return (false);
}
}
if($('#sl-0-country').val() == 'ES'){
if(!(phone_mobile_es.test($('#custPhone').val()))) {
ev.preventDefault();
alert($('#error-mobile-invalid').val() + '\n\nFormat : 610102031 ou 0034610102031');
return (false);
}
}
if($('#sl-0-country').val() == 'IT' && !(phone_mobile_it.test($('#custPhone').val()))){
ev.preventDefault();
alert($('#error-mobile-invalid').val() + '\n\nFormat : 0661010203');
return (false);
} else if($('#custPhone').val().length > 9 && !(phone_mobile.test($('#custPhone').val()) || phone_mobile_be.test($('#custPhone').val()))) {
ev.preventDefault();
alert($('#error-mobile-invalid').val() + '\n\nFormat : 0681010203');
alert($('#error-mobile-invalid').val() + '\n\nFormat : 0661010203 / 3354765864 ou 00390661010203 / 00393354765864');
return (false);
}
// if($('#custPhone').val().length == 9 && !phone_mobile_without_zero.test($('#custPhone').val())){
// ev.preventDefault();
// alert($('#error-mobile-invalid').val() + '\n\nFormat : 0661010203');
// return (false);
// } else if($('#custPhone').val().length > 9 && !(phone_mobile.test($('#custPhone').val()) || phone_mobile_be.test($('#custPhone').val()))) {
// ev.preventDefault();
// alert($('#error-mobile-invalid').val() + '\n\nFormat : 0681010203');
// return (false);
// }
return (true);
});

View File

@ -884,20 +884,30 @@ class Cart extends CartCore {
$total_cart += $discountObj->include_tax ? $product['total_wt'] : $product['total'];
}
// $categories = Discount::getCategories($discountObj->id);
// $returnErrorNoProductCategory = true;
// foreach($products AS $product)
// {
// if (count($categories))
// if (Product::idIsOnCategoryId($product['id_product'], $categories))
// {
// if ((!$discountObj->cumulable_reduction AND !$product['reduction_applies'] AND !$product['on_sale']) OR $discountObj->cumulable_reduction)
// $total_cart += $discountObj->include_tax ? $product['total_wt'] : $product['total'];
// $returnErrorNoProductCategory = false;
// }
// }
// if ($returnErrorNoProductCategory)
// return Tools::displayError('This discount does not apply to that product category.');
// @Override Antadis - check discount category
$categories = Discount::getCategories($discountObj->id);
$returnErrorNoProductCategory = true;
foreach($products AS $product)
{
if (count($categories)) {
if (Product::idIsOnCategoryId($product['id_product'], $categories))
{
if ((!$discountObj->cumulable_reduction AND !$product['reduction_applies'] AND !$product['on_sale']) OR $discountObj->cumulable_reduction)
$total_cart += $discountObj->include_tax ? $product['total_wt'] : $product['total'];
$returnErrorNoProductCategory = false;
} else {
$returnErrorNoProductCategory = true;
break;
}
} else {
$returnErrorNoProductCategory = false;
}
}
// @End Override Antadis - check discount category
if ($returnErrorNoProductCategory) {
return Tools::displayError('This discount does not apply to that product category.');
}
if ($total_cart < $discountObj->minimal)
return Tools::displayError('The order total is not high enough or this voucher cannot be used with those products.');
@ -924,20 +934,27 @@ class Cart extends CartCore {
LEFT JOIN `'._DB_PREFIX_.'discount` d ON c.`id_discount` = d.`id_discount`
WHERE `id_cart` = '.(int)($this->id));
// $products = $this->getProducts();
// foreach ($result AS $k => $discount)
// {
// $categories = Discount::getCategories((int)($discount['id_discount']));
// $in_category = false;
// foreach ($products AS $product)
// if (Product::idIsOnCategoryId((int)($product['id_product']), $categories))
// {
// $in_category = true;
// break;
// }
// if (!$in_category)
// unset($result[$k]);
// }
// @Override Antadis - check discount category
$products = $this->getProducts();
foreach ($result AS $k => $discount)
{
$categories = Discount::getCategories((int)($discount['id_discount']));
if(count($categories)) {
$in_category = false;
foreach ($products AS $product) {
if (Product::idIsOnCategoryId((int)($product['id_product']), $categories))
{
$in_category = true;
} else{
$in_category = false;
break;
}
}
if (!$in_category)
unset($result[$k]);
}
}
// @End Override Antadis - check discount category
if ($lite)
{