update error mess from add to cart
This commit is contained in:
parent
deec098272
commit
0f5228f6e8
@ -3,209 +3,283 @@ require 'BusinessDaysCalculator.php';
|
|||||||
|
|
||||||
if (!class_exists('SaleDelay')) {
|
if (!class_exists('SaleDelay')) {
|
||||||
|
|
||||||
class SaleDelay {
|
class SaleDelay {
|
||||||
|
|
||||||
public static function associateDelay($products)
|
public static function associateDelay($products)
|
||||||
{
|
{
|
||||||
global $cookie;
|
global $cookie;
|
||||||
|
|
||||||
// products cart group by delay
|
// products cart group by delay
|
||||||
$products_final = array();
|
$products_final = array();
|
||||||
$categories_cached = array();
|
$categories_cached = array();
|
||||||
$sales_cached = array();
|
$sales_cached = array();
|
||||||
|
|
||||||
foreach ($products as $key => $product) {
|
foreach ($products as $key => $product) {
|
||||||
if (!isset($product['id_category_default'])) {
|
if (!isset($product['id_category_default'])) {
|
||||||
$product['id_category_default'] = Db::getInstance()->getValue('
|
$product['id_category_default'] = Db::getInstance()->getValue('
|
||||||
SELECT `id_category_default`
|
SELECT `id_category_default`
|
||||||
FROM `ps_product`
|
FROM `ps_product`
|
||||||
WHERE `id_product` = '.(int)$product['product_id'] .'
|
WHERE `id_product` = '.(int)$product['product_id'] .'
|
||||||
');
|
');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!in_array($product['id_category_default'], $categories_cached)) {
|
if (!in_array($product['id_category_default'], $categories_cached)) {
|
||||||
$sale = Sale::getSaleFromCategory((int) $product['id_category_default']);
|
$sale = Sale::getSaleFromCategory((int) $product['id_category_default']);
|
||||||
$sales_cached[(int) $product['id_category_default']] = $sale;
|
$sales_cached[(int) $product['id_category_default']] = $sale;
|
||||||
} else {
|
} else {
|
||||||
$sale = $sales_cached[(int) $product['id_category_default']];
|
$sale = $sales_cached[(int) $product['id_category_default']];
|
||||||
}
|
}
|
||||||
$delay = !empty($sale->delivery_delay) ? $sale->delivery_delay : 1;
|
$delay = !empty($sale->delivery_delay) ? $sale->delivery_delay : 1;
|
||||||
|
|
||||||
if(!isset($products_final[(int)$delay])) {
|
if(!isset($products_final[(int)$delay])) {
|
||||||
$products_final[(int)$delay] = array();
|
$products_final[(int)$delay] = array();
|
||||||
$array_delay = self::getDelay($delay, $cookie->id_lang);
|
$array_delay = self::getDelay($delay, $cookie->id_lang);
|
||||||
|
|
||||||
$products_final[(int)$delay]['title'] = $array_delay['short_name'];
|
$products_final[(int)$delay]['title'] = $array_delay['short_name'];
|
||||||
$products_final[(int)$delay]['products'] = array();
|
$products_final[(int)$delay]['products'] = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
$products_final[(int)$delay]['products'][] = $product;
|
$products_final[(int)$delay]['products'][] = $product;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $products_final;
|
return $products_final;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getDeliveryDate(array $delays, $id_lang = null, $date_calcul = null, $include_we =false)
|
public static function getDeliveryDate(array $delays, $id_lang = null, $date_calcul = null, $include_we =false)
|
||||||
{
|
{
|
||||||
global $cookie;
|
global $cookie;
|
||||||
if (!$date_calcul) {
|
if (!$date_calcul) {
|
||||||
$date_calcul = new DateTime();
|
$date_calcul = new DateTime();
|
||||||
}
|
}
|
||||||
if (!$id_lang) {
|
if (!$id_lang) {
|
||||||
$id_lang = $cookie->id_lang;
|
$id_lang = $cookie->id_lang;
|
||||||
}
|
}
|
||||||
if (empty($delays)) {
|
if (empty($delays)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$delivery_date = array();
|
$delivery_date = array();
|
||||||
foreach ($delays as $key => $delay) {
|
foreach ($delays as $key => $delay) {
|
||||||
if (!in_array($delay, array_keys($delivery_date))) {
|
if (!in_array($delay, array_keys($delivery_date))) {
|
||||||
$delivery_date[$delay] = self::getDayDelay($delay, $cookie->id_lang);
|
$delivery_date[$delay] = self::getDayDelay($delay, $cookie->id_lang);
|
||||||
$delivery_date[$delay]['date_start'] = self::getDateWithDelay((int)$delivery_date[$delay]['value'], $date_calcul, $include_we);
|
$delivery_date[$delay]['date_start'] = self::getDateWithDelay((int)$delivery_date[$delay]['value'], $date_calcul, $include_we);
|
||||||
|
|
||||||
// exception noel
|
// exception noel
|
||||||
if ($delay == 5) {
|
if ($delay == 5) {
|
||||||
$delivery_date[$delay]['date_end'] = self::getDateWithDelay((int) $delivery_date[$delay]['value'], $date_calcul, $include_we);
|
$delivery_date[$delay]['date_end'] = self::getDateWithDelay((int) $delivery_date[$delay]['value'], $date_calcul, $include_we);
|
||||||
} else {
|
} else {
|
||||||
$delivery_date[$delay]['date_end'] = self::getDateWithDelay((int) $delivery_date[$delay]['value_max'], $date_calcul, $include_we);
|
$delivery_date[$delay]['date_end'] = self::getDateWithDelay((int) $delivery_date[$delay]['value_max'], $date_calcul, $include_we);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($delay != 5) {
|
if ($delay != 5) {
|
||||||
$diff = (int)$delivery_date[$delay]['value_max'] - (int)$delivery_date[$delay]['value'];
|
$diff = (int)$delivery_date[$delay]['value_max'] - (int)$delivery_date[$delay]['value'];
|
||||||
$interval = $delivery_date[$delay]['date_end']->diff($delivery_date[$delay]['date_start']);
|
$interval = $delivery_date[$delay]['date_end']->diff($delivery_date[$delay]['date_start']);
|
||||||
if((int)$diff != (int)$interval->format('%a')){
|
if((int)$diff != (int)$interval->format('%a')){
|
||||||
$day_to_add = (int)$diff - (int)$interval->format('%a');
|
$day_to_add = (int)$diff - (int)$interval->format('%a');
|
||||||
if($day_to_add>1){
|
if($day_to_add>1){
|
||||||
$delivery_date[$delay]['date_end'] = $delivery_date[$delay]['date_end']->modify('+'.$day_to_add.' days');
|
$delivery_date[$delay]['date_end'] = $delivery_date[$delay]['date_end']->modify('+'.$day_to_add.' days');
|
||||||
}else{
|
}else{
|
||||||
$delivery_date[$delay]['date_end'] = $delivery_date[$delay]['date_end']->modify('+'.$day_to_add.' day');
|
$delivery_date[$delay]['date_end'] = $delivery_date[$delay]['date_end']->modify('+'.$day_to_add.' day');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $delivery_date;
|
return $delivery_date;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getDateWithDelay($nb_day, $date, $include_we = false)
|
public static function getDateWithDelay($nb_day, $date, $include_we = false)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($include_we) {
|
if ($include_we) {
|
||||||
$calculator = new BusinessDaysCalculator(
|
$calculator = new BusinessDaysCalculator(
|
||||||
new DateTime($date->format('Y-m-d H:i:s')),
|
new DateTime($date->format('Y-m-d H:i:s')),
|
||||||
array(),
|
array(),
|
||||||
[BusinessDaysCalculator::SUNDAY]
|
[BusinessDaysCalculator::SUNDAY]
|
||||||
);
|
);
|
||||||
$calculator->addDaysWithCheckLastDay($nb_day);
|
$calculator->addDaysWithCheckLastDay($nb_day);
|
||||||
} else {
|
} else {
|
||||||
$calculator = new BusinessDaysCalculator(
|
$calculator = new BusinessDaysCalculator(
|
||||||
new DateTime($date->format('Y-m-d H:i:s')),
|
new DateTime($date->format('Y-m-d H:i:s')),
|
||||||
array(),
|
array(),
|
||||||
[BusinessDaysCalculator::SATURDAY, BusinessDaysCalculator::SUNDAY]
|
[BusinessDaysCalculator::SATURDAY, BusinessDaysCalculator::SUNDAY]
|
||||||
);
|
);
|
||||||
$calculator->addBusinessDays($nb_day);
|
$calculator->addBusinessDays($nb_day);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $calculator->getDate();
|
return $calculator->getDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getDayDelay($id_delay, $id_lang)
|
public static function getDayDelay($id_delay, $id_lang)
|
||||||
{
|
{
|
||||||
return Db::getInstance()->getRow('
|
return Db::getInstance()->getRow('
|
||||||
SELECT `value`, `value_max`, `name`
|
SELECT `value`, `value_max`, `name`
|
||||||
FROM `ps_privatesale_delay_lang`
|
FROM `ps_privatesale_delay_lang`
|
||||||
WHERE `id_delay` = '.(int) $id_delay.'
|
WHERE `id_delay` = '.(int) $id_delay.'
|
||||||
AND `id_lang` = '.(int) $id_lang.'
|
AND `id_lang` = '.(int) $id_lang.'
|
||||||
');
|
');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getDelay($id_delay, $id_lang)
|
public static function getDelay($id_delay, $id_lang)
|
||||||
{
|
{
|
||||||
return Db::getInstance()->getRow('
|
return Db::getInstance()->getRow('
|
||||||
SELECT d.`id_delay`, dl.`name`, dl.`short_name`, dl.`value`
|
SELECT d.`id_delay`, dl.`name`, dl.`short_name`, dl.`value`
|
||||||
FROM `'._DB_PREFIX_.'privatesale_delay_lang` d
|
FROM `'._DB_PREFIX_.'privatesale_delay_lang` d
|
||||||
LEFT JOIN `'._DB_PREFIX_.'privatesale_delay_lang` dl ON (d.`id_delay` = dl.`id_delay`)
|
LEFT JOIN `'._DB_PREFIX_.'privatesale_delay_lang` dl ON (d.`id_delay` = dl.`id_delay`)
|
||||||
WHERE dl.`id_lang` = '.(int) $id_lang.'
|
WHERE dl.`id_lang` = '.(int) $id_lang.'
|
||||||
AND d.`id_delay` = '.(int) $id_delay.'
|
AND d.`id_delay` = '.(int) $id_delay.'
|
||||||
');
|
');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @todo - remove this function to use short name
|
* @todo - remove this function to use short name
|
||||||
*/
|
*/
|
||||||
public static function getDelaySmallName($id_delay, $id_lang) {
|
public static function getDelaySmallName($id_delay, $id_lang) {
|
||||||
if($id_lang == 2) {
|
if($id_lang == 2) {
|
||||||
switch ($id_delay) {
|
switch ($id_delay) {
|
||||||
case '1':
|
case '1':
|
||||||
return 'Classique';
|
return 'Classique';
|
||||||
break;
|
break;
|
||||||
case '2':
|
case '2':
|
||||||
return '48h';
|
return '48h';
|
||||||
break;
|
break;
|
||||||
case '3':
|
case '3':
|
||||||
return '7j';
|
return '7j';
|
||||||
break;
|
break;
|
||||||
case '4':
|
case '4':
|
||||||
return '10j';
|
return '10j';
|
||||||
break;
|
break;
|
||||||
case '5':
|
case '5':
|
||||||
return 'Noël';
|
return 'Noël';
|
||||||
break;
|
break;
|
||||||
case '6':
|
case '6':
|
||||||
return 'Star';
|
return 'Star';
|
||||||
break;
|
break;
|
||||||
case '7':
|
case '7':
|
||||||
return '72h';
|
return '72h';
|
||||||
break;
|
break;
|
||||||
case '8':
|
case '8':
|
||||||
return '48h Noël';
|
return '48h Noël';
|
||||||
break;
|
break;
|
||||||
case '9':
|
case '9':
|
||||||
return 'Spé';
|
return 'Spé';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return 'Inconnu';
|
return 'Inconnu';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} elseif($id_lang == 3){
|
} elseif($id_lang == 3){
|
||||||
switch ($id_delay) {
|
switch ($id_delay) {
|
||||||
case '1':
|
case '1':
|
||||||
return 'Classic';
|
return 'Classic';
|
||||||
break;
|
break;
|
||||||
case '2':
|
case '2':
|
||||||
return '48h';
|
return '48h';
|
||||||
break;
|
break;
|
||||||
case '3':
|
case '3':
|
||||||
return '7j';
|
return '7j';
|
||||||
break;
|
break;
|
||||||
case '4':
|
case '4':
|
||||||
return '10j';
|
return '10j';
|
||||||
break;
|
break;
|
||||||
case '5':
|
case '5':
|
||||||
return 'Noël';
|
return 'Noël';
|
||||||
break;
|
break;
|
||||||
case '6':
|
case '6':
|
||||||
return 'Star';
|
return 'Star';
|
||||||
break;
|
break;
|
||||||
case '7':
|
case '7':
|
||||||
return '72h';
|
return '72h';
|
||||||
break;
|
break;
|
||||||
case '9':
|
case '9':
|
||||||
return 'Spé';
|
return 'Spé';
|
||||||
break;
|
break;
|
||||||
case '8':
|
case '8':
|
||||||
return '48h Noël';
|
return '48h Noël';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return 'Unknown';
|
return 'Unknown';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 'Unknown';
|
return 'Unknown';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* @todo - remove this function to use short name
|
||||||
|
*/
|
||||||
|
public static function getDelayFrontSmallName($id_delay, $id_lang) {
|
||||||
|
if($id_lang == 2) {
|
||||||
|
switch ($id_delay) {
|
||||||
|
case '1':
|
||||||
|
return '3 semaines';
|
||||||
|
break;
|
||||||
|
case '2':
|
||||||
|
return '48h';
|
||||||
|
break;
|
||||||
|
case '3':
|
||||||
|
return '7 jours';
|
||||||
|
break;
|
||||||
|
case '4':
|
||||||
|
return '10 jours';
|
||||||
|
break;
|
||||||
|
case '5':
|
||||||
|
return 'Noël';
|
||||||
|
break;
|
||||||
|
case '6':
|
||||||
|
return 'Star';
|
||||||
|
break;
|
||||||
|
case '7':
|
||||||
|
return '72h';
|
||||||
|
break;
|
||||||
|
case '8':
|
||||||
|
return '48h';
|
||||||
|
break;
|
||||||
|
case '9':
|
||||||
|
return 'Spé';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return 'quelques jours';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} elseif($id_lang == 3){
|
||||||
|
switch ($id_delay) {
|
||||||
|
case '1':
|
||||||
|
return '3 semanas';
|
||||||
|
break;
|
||||||
|
case '2':
|
||||||
|
return '48h';
|
||||||
|
break;
|
||||||
|
case '3':
|
||||||
|
return '7 días';
|
||||||
|
break;
|
||||||
|
case '4':
|
||||||
|
return '10 días';
|
||||||
|
break;
|
||||||
|
case '5':
|
||||||
|
return 'Noël';
|
||||||
|
break;
|
||||||
|
case '6':
|
||||||
|
return 'Star';
|
||||||
|
break;
|
||||||
|
case '7':
|
||||||
|
return '72h';
|
||||||
|
break;
|
||||||
|
case '9':
|
||||||
|
return 'Spé';
|
||||||
|
break;
|
||||||
|
case '8':
|
||||||
|
return '48h';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return 'un poco días';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 'few days';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
include_once dirname(__FILE__).'/../../modules/privatesales/Sale.php';
|
include_once dirname(__FILE__).'/../../modules/privatesales/Sale.php';
|
||||||
|
include_once dirname(__FILE__).'/../../modules/privatesales_delay/saledelay.php';
|
||||||
class CartController extends CartControllerCore
|
class CartController extends CartControllerCore
|
||||||
{
|
{
|
||||||
public function preProcess()
|
public function preProcess()
|
||||||
@ -80,20 +81,22 @@ class CartController extends CartControllerCore
|
|||||||
|
|
||||||
if (!empty($current_sale)) {
|
if (!empty($current_sale)) {
|
||||||
global $smarty;
|
global $smarty;
|
||||||
|
$current_delay_name = SaleDelay::getDelayFrontSmallName($current_sale['delivery_delay'], self::$cookie->id_lang);
|
||||||
|
$adding_delay_name = SaleDelay::getDelayFrontSmallName($adding_sale['delivery_delay'], self::$cookie->id_lang));
|
||||||
if ((int)$current_sale['delivery_delay'] == 1 && !Sale::isCombinable($current_sale,$adding_sale)){
|
if ((int)$current_sale['delivery_delay'] == 1 && !Sale::isCombinable($current_sale,$adding_sale)){
|
||||||
// Product in cart comes from classic delivery sale
|
// Product in cart comes from classic delivery sale
|
||||||
if (Tools::getValue('ajax') == 'true') {
|
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).'"]}');
|
die('{"hasError" : true,"popup_error_cart": true, "errors" : ["'.sprintf(Tools::displayError('Sorry your cart already contains products from a sale shipped within %s. To continue, please confirm your order or empty your cart.', false), $current_delay_name).'"]}');
|
||||||
} else {
|
} 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);
|
$this->errors[] = sprintf(Tools::displayError('Sorry your cart already contains products from a sale shipped within %s. To continue, please confirm your order or empty your cart.', false),$current_delay_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif (!Sale::isCombinable($current_sale,$adding_sale)){
|
elseif (!Sale::isCombinable($current_sale,$adding_sale)){
|
||||||
// Product in cart comes from special delivery sale
|
// Product in cart comes from special delivery sale
|
||||||
if (Tools::getValue('ajax') == 'true') {
|
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).'"]}');
|
die('{"hasError" : true,"popup_error_cart": true, "errors" : ["'.sprintf(Tools::displayError('Sorry your cart already contains products from a sale shipped within a special period. We cannot add products from sales shipped within %s. To continue, please confirm your order or empty your cart.', false),$adding_delay_name).'"]}');
|
||||||
} else {
|
} 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);
|
$this->errors[] = sprintf(Tools::displayError('Sorry your cart already contains products from a sale shipped within a special period. We cannot add products from sales shipped within %s. To continue, please confirm your order or empty your cart.', false),$adding_delay_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user