Merge branch 'feature/unique_cart_web_and_app' into develop
This commit is contained in:
commit
5a32991da8
@ -839,12 +839,12 @@ class Cart extends CartCore {
|
|||||||
|
|
||||||
if (!$order_total)
|
if (!$order_total)
|
||||||
return Tools::displayError('Cannot add voucher if order is free.');
|
return Tools::displayError('Cannot add voucher if order is free.');
|
||||||
|
|
||||||
// Only for API (application)
|
// Only for API (application)
|
||||||
if (!Tools::isApi() && $discountObj->appli == 1) {
|
if (!Tools::isApi() && $discountObj->appli == 1) {
|
||||||
return Tools::displayError('This voucher is only valid on the application');
|
return Tools::displayError('This voucher is only valid on the application');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$discountObj->active)
|
if (!$discountObj->active)
|
||||||
return Tools::displayError('This voucher has already been used or is disabled.');
|
return Tools::displayError('This voucher has already been used or is disabled.');
|
||||||
if (!$discountObj->quantity)
|
if (!$discountObj->quantity)
|
||||||
@ -1086,6 +1086,32 @@ class Cart extends CartCore {
|
|||||||
'free_ship' => $total_free_ship);
|
'free_ship' => $total_free_ship);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getMaxIdOrdered($id_customer) {
|
||||||
|
return Db::getInstance()->getValue('
|
||||||
|
SELECT MAX(c.`id_cart`)
|
||||||
|
FROM '._DB_PREFIX_.'cart c
|
||||||
|
LEFT JOIN '._DB_PREFIX_.'orders o ON (c.`id_cart` = o.`id_cart`)
|
||||||
|
WHERE o.`valid` = 1
|
||||||
|
AND c.`id_customer` = '.(int)$id_customer.'
|
||||||
|
');
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function lastNoneOrderedCart($id_customer)
|
||||||
|
{
|
||||||
|
if (($max_id_cart = self::getMaxIdOrdered($id_customer))) {
|
||||||
|
$id_cart = Db::getInstance()->getValue('
|
||||||
|
SELECT MIN(c.id_cart)
|
||||||
|
FROM '._DB_PREFIX_.'cart c
|
||||||
|
LEFT JOIN '._DB_PREFIX_.'orders o ON (c.`id_cart` = o.`id_cart`)
|
||||||
|
WHERE (o.`valid` = 0 OR o.`valid` IS NULL)
|
||||||
|
AND c.`id_customer` = '.(int)$id_customer.'
|
||||||
|
AND c.`id_cart` > '.(int)$max_id_cart.'
|
||||||
|
');
|
||||||
|
return $id_cart ? $id_cart : false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public function printVersion($value, $params)
|
public function printVersion($value, $params)
|
||||||
{
|
{
|
||||||
$versions = array(
|
$versions = array(
|
||||||
|
@ -143,6 +143,12 @@ class FrontController extends FrontControllerCore {
|
|||||||
if (!isset($cart) OR !$cart->id)
|
if (!isset($cart) OR !$cart->id)
|
||||||
{
|
{
|
||||||
$cart = new Cart();
|
$cart = new Cart();
|
||||||
|
if ($cookie->id_customer) {
|
||||||
|
if (($id_cart = Cart::lastNoneOrderedCart($cookie->id_customer))) {
|
||||||
|
$cart = new Cart($id_cart);
|
||||||
|
$cookie->id_cart = $id_cart;
|
||||||
|
}
|
||||||
|
}
|
||||||
$cart->id_lang = (int)($cookie->id_lang);
|
$cart->id_lang = (int)($cookie->id_lang);
|
||||||
$cart->id_currency = (int)($cookie->id_currency);
|
$cart->id_currency = (int)($cookie->id_currency);
|
||||||
$cart->id_guest = (int)($cookie->id_guest);
|
$cart->id_guest = (int)($cookie->id_guest);
|
||||||
@ -167,6 +173,10 @@ class FrontController extends FrontControllerCore {
|
|||||||
$cart->id_address_delivery = 0;
|
$cart->id_address_delivery = 0;
|
||||||
$cart->id_address_invoice = 0;
|
$cart->id_address_invoice = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($cookie->id_customer) {
|
||||||
|
$cart->update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$cart->nbProducts())
|
if (!$cart->nbProducts())
|
||||||
|
Loading…
Reference in New Issue
Block a user