bebeboutik-api/app/Web/Controllers/CartController.php

58 lines
2.6 KiB
PHP
Raw Normal View History

2017-07-21 16:40:11 +02:00
<?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;
2017-10-17 19:10:54 +02:00
2017-07-21 16:40:11 +02:00
class CartController extends BaseCartController
{
public function get(Request $request) {
return parent::get($request);
}
protected function checkProductToAdd($productToAdd, $id_product_attribute, $quantity) {
2017-10-17 19:10:54 +02:00
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)){
2017-10-17 19:10:54 +02:00
$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)){
2017-10-17 19:10:54 +02:00
$add_delay = \SaleDelay::getDelayFrontSmallName($adding_sale['delivery_delay'], $cookie->id_lang);
2017-10-24 17:55:05 +02:00
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),$add_delay);
}
}
}
return true;
}
2017-07-21 16:40:11 +02:00
}