58 lines
2.6 KiB
PHP
58 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Web\Controllers;
|
|
|
|
use App\Models\Carrier;
|
|
use Antadis\API\Front\Web\Controllers\CartController as BaseCartController;
|
|
use Illuminate\Http\Request;
|
|
|
|
use ApiProductCart;
|
|
use ApiTools;
|
|
|
|
|
|
|
|
class CartController extends BaseCartController
|
|
{
|
|
|
|
public function get(Request $request) {
|
|
return parent::get($request);
|
|
}
|
|
|
|
protected function checkProductToAdd($productToAdd, $id_product_attribute, $quantity) {
|
|
global $cookie;
|
|
|
|
include_once _PS_MODULE_DIR_.'privatesales_delay/saledelay.php';
|
|
if (($error = parent::checkProductToAdd($productToAdd, $id_product_attribute, $quantity)) === true) {
|
|
$current_sale = array();
|
|
foreach (static::$_cart->getProducts() as $product) {
|
|
$sale = \Sale::getSaleFromCategory((int)$product['id_category_default'], false);
|
|
$current_sale = array(
|
|
'id_sale'=> (int) $sale->id,
|
|
'delivery_delay'=> (int) $sale->delivery_delay,
|
|
'shipping' => \Sale::getShippingSale((int)$sale->id)
|
|
);
|
|
// Only one delivery id per cart, so we can break now
|
|
break;
|
|
}
|
|
$current_product = $productToAdd;
|
|
$sale2 = \Sale::getSaleFromCategory($current_product->id_category_default, false);
|
|
$adding_sale = array(
|
|
'id_sale'=> (int) $sale2->id,
|
|
'delivery_delay'=> (int) $sale2->delivery_delay,
|
|
'shipping' => \Sale::getShippingSale((int)$sale2->id)
|
|
);
|
|
|
|
if (!empty($current_sale)) {
|
|
if ((int)$current_sale['delivery_delay'] == 1 && !\Sale::isCombinable($current_sale,$adding_sale)){
|
|
$current_delay = \SaleDelay::getDelayFrontSmallName($current_sale['delivery_delay'], $cookie->id_lang);
|
|
return sprintf(ApiTools::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);
|
|
} elseif (!\Sale::isCombinable($current_sale,$adding_sale)){
|
|
$add_delay = \SaleDelay::getDelayFrontSmallName($adding_sale['delivery_delay'], $cookie->id_lang);
|
|
return sprintf(ApiTools::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);
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|