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 ;
2017-08-31 12:58:27 +02:00
use ApiProductCart ;
use ApiTools ;
2017-07-21 16:40:11 +02:00
class CartController extends BaseCartController
{
2017-08-31 12:58:27 +02:00
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 ;
}
2017-07-21 16:40:11 +02:00
}