51 lines
2.1 KiB
PHP
51 lines
2.1 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) {
|
|
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)){
|
|
return ApiTools::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);
|
|
} elseif (!\Sale::isCombinable($current_sale,$adding_sale)){
|
|
return ApiTools::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);
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|