2023-03-08 22:13:03 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace AhmadFatoni\ApiGenerator\Controllers\API;
|
2023-02-15 15:52:41 +00:00
|
|
|
|
|
|
|
|
use Cms\Classes\Controller;
|
|
|
|
|
use BackendMenu;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use AhmadFatoni\ApiGenerator\Helpers\Helpers;
|
|
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
|
use Lovata\OrdersShopaholic\Models\Cart;
|
2023-03-08 22:13:03 +00:00
|
|
|
use Lovata\OrdersShopaholic\Classes\Processor\CartProcessor;
|
|
|
|
|
use Lovata\OrdersShopaholic\Classes\Processor\OfferCartPositionProcessor;
|
|
|
|
|
use Kharanenka\Helper\Result;
|
|
|
|
|
use Input;
|
|
|
|
|
|
2023-02-15 15:52:41 +00:00
|
|
|
class CartAPIController extends Controller
|
|
|
|
|
{
|
2023-03-08 22:13:03 +00:00
|
|
|
protected $Cart;
|
2023-02-15 15:52:41 +00:00
|
|
|
|
|
|
|
|
protected $helpers;
|
|
|
|
|
|
|
|
|
|
public function __construct(Cart $Cart, Helpers $helpers)
|
|
|
|
|
{
|
|
|
|
|
parent::__construct();
|
|
|
|
|
$this->Cart = $Cart;
|
|
|
|
|
$this->helpers = $helpers;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-08 22:13:03 +00:00
|
|
|
public function index()
|
|
|
|
|
{
|
|
|
|
|
// $currentUser = JWTAuth::parseToken()->authenticate();
|
|
|
|
|
// $currentUser = \JWTAuth::parseToken()->toUser();
|
2023-02-15 15:52:41 +00:00
|
|
|
|
2023-03-08 22:13:03 +00:00
|
|
|
// dd($currentUser);
|
|
|
|
|
$data = CartProcessor::instance()->getCartData();
|
2023-02-15 15:52:41 +00:00
|
|
|
|
|
|
|
|
return $this->helpers->apiArrayResponseBuilder(200, 'success', $data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-03-08 22:13:03 +00:00
|
|
|
public function addCart()
|
|
|
|
|
{
|
|
|
|
|
//$arRequestData = Input::get('cart');
|
2023-02-15 15:52:41 +00:00
|
|
|
|
2023-03-08 22:13:03 +00:00
|
|
|
$offerId = input('offer_id');
|
|
|
|
|
$quantity = input('quantity');
|
2023-02-15 15:52:41 +00:00
|
|
|
|
2023-03-08 22:13:03 +00:00
|
|
|
$cart = array('cart' => array('offer_id' => $offerId, 'quantity' => $quantity));
|
2023-02-15 15:52:41 +00:00
|
|
|
|
2023-03-08 22:13:03 +00:00
|
|
|
CartProcessor::instance()->add($cart, OfferCartPositionProcessor::class);
|
|
|
|
|
Result::setData(CartProcessor::instance()->getCartData());
|
2023-02-15 15:52:41 +00:00
|
|
|
|
2023-03-08 22:13:03 +00:00
|
|
|
$data = Result::get();
|
2023-02-15 15:52:41 +00:00
|
|
|
|
2023-03-08 22:13:03 +00:00
|
|
|
return $this->helpers->apiArrayResponseBuilder(200, 'success', $data);
|
|
|
|
|
}
|
2023-02-15 15:52:41 +00:00
|
|
|
|
|
|
|
|
|
2023-03-08 22:13:03 +00:00
|
|
|
public function updateCart()
|
|
|
|
|
{
|
|
|
|
|
//$arRequestData = Input::get('cart');
|
2023-02-15 15:52:41 +00:00
|
|
|
|
2023-03-08 22:13:03 +00:00
|
|
|
$offerId = input('offer_id');
|
|
|
|
|
$quantity = input('quantity');
|
2023-02-15 15:52:41 +00:00
|
|
|
|
2023-03-08 22:13:03 +00:00
|
|
|
$cart = array('cart' => array('offer_id' => $offerId, 'quantity' => $quantity));
|
2023-02-15 15:52:41 +00:00
|
|
|
|
2023-03-08 22:13:03 +00:00
|
|
|
CartProcessor::instance()->add($cart, OfferCartPositionProcessor::class);
|
|
|
|
|
Result::setData(CartProcessor::instance()->getCartData());
|
2023-02-15 15:52:41 +00:00
|
|
|
|
2023-03-08 22:13:03 +00:00
|
|
|
$data = Result::get();
|
2023-02-15 15:52:41 +00:00
|
|
|
|
2023-03-08 22:13:03 +00:00
|
|
|
return $this->helpers->apiArrayResponseBuilder(200, 'success', $data);
|
|
|
|
|
}
|
2023-02-15 15:52:41 +00:00
|
|
|
|
2023-03-08 22:13:03 +00:00
|
|
|
public function removeProdCart()
|
|
|
|
|
{
|
|
|
|
|
$offerId = input('offer_id');
|
|
|
|
|
// $arRequestData = Input::get('cart');
|
|
|
|
|
$sType = Input::get('type', 'offer');
|
|
|
|
|
$cart = array('cart' => array('offer_id' => $offerId));
|
2023-02-15 15:52:41 +00:00
|
|
|
|
2023-03-08 22:13:03 +00:00
|
|
|
CartProcessor::instance()->remove($cart, OfferCartPositionProcessor::class, $sType);
|
|
|
|
|
Result::setData(CartProcessor::instance()->getCartData());
|
2023-02-15 15:52:41 +00:00
|
|
|
|
2023-03-08 22:13:03 +00:00
|
|
|
$data = Result::get();
|
2023-02-15 15:52:41 +00:00
|
|
|
|
2023-03-08 22:13:03 +00:00
|
|
|
return $this->helpers->apiArrayResponseBuilder(200, 'success', $data);
|
|
|
|
|
}
|
2023-02-15 15:52:41 +00:00
|
|
|
|
2023-03-08 22:13:03 +00:00
|
|
|
public function clearCart()
|
|
|
|
|
{
|
|
|
|
|
$data = CartProcessor::instance()->clear();
|
|
|
|
|
Result::setData(CartProcessor::instance()->getCartData());
|
|
|
|
|
$data = Result::get();
|
|
|
|
|
return $this->helpers->apiArrayResponseBuilder(200, 'success', $data);
|
|
|
|
|
}
|
2023-02-15 15:52:41 +00:00
|
|
|
|
2023-03-08 22:13:03 +00:00
|
|
|
public static function getAfterFilters()
|
|
|
|
|
{
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
public static function getBeforeFilters()
|
|
|
|
|
{
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
public static function getMiddleware()
|
|
|
|
|
{
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
public function callAction($method, $parameters = false)
|
|
|
|
|
{
|
2023-02-15 15:52:41 +00:00
|
|
|
return call_user_func_array(array($this, $method), $parameters);
|
|
|
|
|
}
|
2023-03-08 22:13:03 +00:00
|
|
|
}
|