cart api
This commit is contained in:
parent
da70b633a7
commit
f84d505d0f
|
|
@ -1,4 +1,4 @@
|
||||||
config/database.php
|
/config/database.php
|
||||||
|
|
||||||
# Composer ignores
|
# Composer ignores
|
||||||
/vendor
|
/vendor
|
||||||
|
|
|
||||||
|
|
@ -57,9 +57,9 @@ return [
|
||||||
'engine' => 'InnoDB',
|
'engine' => 'InnoDB',
|
||||||
'host' => 'localhost',
|
'host' => 'localhost',
|
||||||
'port' => 3306,
|
'port' => 3306,
|
||||||
'database' => 'sapaly_october',
|
'database' => 'sapaly_new',
|
||||||
'username' => 'sapaly',
|
'username' => 'root',
|
||||||
'password' => '22MOcP6^I#8tI5ovcXluXDT#%vWC^CtsFvKHOygi8TMnzaMuLYx@123',
|
'password' => 'bt110226',
|
||||||
'charset' => 'utf8mb4',
|
'charset' => 'utf8mb4',
|
||||||
'collation' => 'utf8mb4_unicode_ci',
|
'collation' => 'utf8mb4_unicode_ci',
|
||||||
'prefix' => '',
|
'prefix' => '',
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
<?php namespace AhmadFatoni\ApiGenerator\Controllers\API;
|
<?php
|
||||||
|
|
||||||
|
namespace AhmadFatoni\ApiGenerator\Controllers\API;
|
||||||
|
|
||||||
use Cms\Classes\Controller;
|
use Cms\Classes\Controller;
|
||||||
use BackendMenu;
|
use BackendMenu;
|
||||||
|
|
@ -7,9 +9,14 @@ use Illuminate\Http\Request;
|
||||||
use AhmadFatoni\ApiGenerator\Helpers\Helpers;
|
use AhmadFatoni\ApiGenerator\Helpers\Helpers;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Lovata\OrdersShopaholic\Models\Cart;
|
use Lovata\OrdersShopaholic\Models\Cart;
|
||||||
|
use Lovata\OrdersShopaholic\Classes\Processor\CartProcessor;
|
||||||
|
use Lovata\OrdersShopaholic\Classes\Processor\OfferCartPositionProcessor;
|
||||||
|
use Kharanenka\Helper\Result;
|
||||||
|
use Input;
|
||||||
|
|
||||||
class CartAPIController extends Controller
|
class CartAPIController extends Controller
|
||||||
{
|
{
|
||||||
protected $Cart;
|
protected $Cart;
|
||||||
|
|
||||||
protected $helpers;
|
protected $helpers;
|
||||||
|
|
||||||
|
|
@ -20,88 +27,90 @@ class CartAPIController extends Controller
|
||||||
$this->helpers = $helpers;
|
$this->helpers = $helpers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function index(){
|
public function index()
|
||||||
$currentUser = JWTAuth::parseToken()->authenticate();
|
{
|
||||||
|
// $currentUser = JWTAuth::parseToken()->authenticate();
|
||||||
|
// $currentUser = \JWTAuth::parseToken()->toUser();
|
||||||
|
|
||||||
dd($currentUser);
|
// dd($currentUser);
|
||||||
$data = $this->Cart
|
$data = CartProcessor::instance()->getCartData();
|
||||||
->paginate(10);
|
|
||||||
|
|
||||||
return $this->helpers->apiArrayResponseBuilder(200, 'success', $data);
|
return $this->helpers->apiArrayResponseBuilder(200, 'success', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function show($id){
|
|
||||||
|
|
||||||
$data = $this->Cart::with('translations:locale,model_id,attribute_data')
|
public function addCart()
|
||||||
->with(['category' => function ($query) {
|
{
|
||||||
$query->with('translations:locale,model_id,attribute_data');
|
//$arRequestData = Input::get('cart');
|
||||||
}])
|
|
||||||
->find($id);
|
|
||||||
|
|
||||||
|
$offerId = input('offer_id');
|
||||||
|
$quantity = input('quantity');
|
||||||
|
|
||||||
if ($data){
|
$cart = array('cart' => array('offer_id' => $offerId, 'quantity' => $quantity));
|
||||||
return $this->helpers->apiArrayResponseBuilder(200, 'success', [$data]);
|
|
||||||
} else {
|
|
||||||
$this->helpers->apiArrayResponseBuilder(404, 'not found', ['error' => 'Resource id=' . $id . ' could not be found']);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
CartProcessor::instance()->add($cart, OfferCartPositionProcessor::class);
|
||||||
|
Result::setData(CartProcessor::instance()->getCartData());
|
||||||
|
|
||||||
|
$data = Result::get();
|
||||||
|
|
||||||
|
return $this->helpers->apiArrayResponseBuilder(200, 'success', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public function store(Request $request){
|
|
||||||
|
|
||||||
// $arr = $request->all();
|
public function updateCart()
|
||||||
|
{
|
||||||
|
//$arRequestData = Input::get('cart');
|
||||||
|
|
||||||
// while ( $data = current($arr)) {
|
$offerId = input('offer_id');
|
||||||
// $this->Cart->{key($arr)} = $data;
|
$quantity = input('quantity');
|
||||||
// next($arr);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// $validation = Validator::make($request->all(), $this->Cart->rules);
|
$cart = array('cart' => array('offer_id' => $offerId, 'quantity' => $quantity));
|
||||||
|
|
||||||
// if( $validation->passes() ){
|
CartProcessor::instance()->add($cart, OfferCartPositionProcessor::class);
|
||||||
// $this->Cart->save();
|
Result::setData(CartProcessor::instance()->getCartData());
|
||||||
// return $this->helpers->apiArrayResponseBuilder(201, 'created', ['id' => $this->Cart->id]);
|
|
||||||
// }else{
|
|
||||||
// return $this->helpers->apiArrayResponseBuilder(400, 'fail', $validation->errors() );
|
|
||||||
// }
|
|
||||||
|
|
||||||
// }
|
$data = Result::get();
|
||||||
|
|
||||||
// public function update($id, Request $request){
|
return $this->helpers->apiArrayResponseBuilder(200, 'success', $data);
|
||||||
|
}
|
||||||
|
|
||||||
// $status = $this->Cart->where('id',$id)->update($data);
|
public function removeProdCart()
|
||||||
|
{
|
||||||
|
$offerId = input('offer_id');
|
||||||
|
// $arRequestData = Input::get('cart');
|
||||||
|
$sType = Input::get('type', 'offer');
|
||||||
|
$cart = array('cart' => array('offer_id' => $offerId));
|
||||||
|
|
||||||
// if( $status ){
|
CartProcessor::instance()->remove($cart, OfferCartPositionProcessor::class, $sType);
|
||||||
|
Result::setData(CartProcessor::instance()->getCartData());
|
||||||
|
|
||||||
// return $this->helpers->apiArrayResponseBuilder(200, 'success', 'Data has been updated successfully.');
|
$data = Result::get();
|
||||||
|
|
||||||
// }else{
|
return $this->helpers->apiArrayResponseBuilder(200, 'success', $data);
|
||||||
|
}
|
||||||
|
|
||||||
// return $this->helpers->apiArrayResponseBuilder(400, 'bad request', 'Error, data failed to update.');
|
public function clearCart()
|
||||||
|
{
|
||||||
|
$data = CartProcessor::instance()->clear();
|
||||||
|
Result::setData(CartProcessor::instance()->getCartData());
|
||||||
|
$data = Result::get();
|
||||||
|
return $this->helpers->apiArrayResponseBuilder(200, 'success', $data);
|
||||||
|
}
|
||||||
|
|
||||||
// }
|
public static function getAfterFilters()
|
||||||
// }
|
{
|
||||||
|
return [];
|
||||||
// public function delete($id){
|
}
|
||||||
|
public static function getBeforeFilters()
|
||||||
// $this->Cart->where('id',$id)->delete();
|
{
|
||||||
|
return [];
|
||||||
// return $this->helpers->apiArrayResponseBuilder(200, 'success', 'Data has been deleted successfully.');
|
}
|
||||||
// }
|
public static function getMiddleware()
|
||||||
|
{
|
||||||
// public function destroy($id){
|
return [];
|
||||||
|
}
|
||||||
// $this->Cart->where('id',$id)->delete();
|
public function callAction($method, $parameters = false)
|
||||||
|
{
|
||||||
// return $this->helpers->apiArrayResponseBuilder(200, 'success', 'Data has been deleted successfully.');
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
public static function getAfterFilters() {return [];}
|
|
||||||
public static function getBeforeFilters() {return [];}
|
|
||||||
public static function getMiddleware() {return [];}
|
|
||||||
public function callAction($method, $parameters=false) {
|
|
||||||
return call_user_func_array(array($this, $method), $parameters);
|
return call_user_func_array(array($this, $method), $parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,67 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace AhmadFatoni\ApiGenerator\Controllers\API;
|
||||||
|
|
||||||
|
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;
|
||||||
|
use Lovata\OrdersShopaholic\Classes\Processor\CartProcessor;
|
||||||
|
use Lovata\OrdersShopaholic\Classes\Processor\OfferCartPositionProcessor;
|
||||||
|
use Kharanenka\Helper\Result;
|
||||||
|
use Input;
|
||||||
|
use Lovata\OrdersShopaholic\Models\ShippingType;
|
||||||
|
use Lovata\OrdersShopaholic\Models\PaymentMethod;
|
||||||
|
|
||||||
|
class CheckoutAPIController extends Controller
|
||||||
|
{
|
||||||
|
// protected $Cart;
|
||||||
|
|
||||||
|
protected $helpers;
|
||||||
|
|
||||||
|
public function __construct(Cart $Cart, Helpers $helpers)
|
||||||
|
{
|
||||||
|
// parent::__construct();
|
||||||
|
// $this->Cart = $Cart;
|
||||||
|
$this->helpers = $helpers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function shippingTypes()
|
||||||
|
{
|
||||||
|
$data = ShippingType::where("active", 1)
|
||||||
|
->with('translations:locale,model_id,attribute_data')
|
||||||
|
->get();
|
||||||
|
|
||||||
|
return $this->helpers->apiArrayResponseBuilder(200, 'success', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function paymentTypes()
|
||||||
|
{
|
||||||
|
$data = PaymentMethod::where("active", 1)
|
||||||
|
->with('translations:locale,model_id,attribute_data')
|
||||||
|
->get();
|
||||||
|
|
||||||
|
return $this->helpers->apiArrayResponseBuilder(200, 'success', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getAfterFilters()
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
public static function getBeforeFilters()
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
public static function getMiddleware()
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
public function callAction($method, $parameters = false)
|
||||||
|
{
|
||||||
|
return call_user_func_array(array($this, $method), $parameters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -16,10 +16,19 @@ Route::group(['prefix' =>'api/v1','namespace' =>'AhmadFatoni\ApiGenerator\Contro
|
||||||
Route::get('sliders', 'SliderAPIController@index');
|
Route::get('sliders', 'SliderAPIController@index');
|
||||||
|
|
||||||
|
|
||||||
//Route::middleware([\ReaZzon\JWTAuth\Http\Middlewares\ResolveUser::class])->group(function () {
|
Route::middleware([\ReaZzon\JWTAuth\Http\Middlewares\ResolveUser::class])->group(function () {
|
||||||
|
|
||||||
//Route::get('cart', 'CartAPIController@index');
|
//Route::get('cart', 'CartAPIController@index');
|
||||||
|
Route::get('cart', 'CartAPIController@index');
|
||||||
|
Route::post('add/cart', 'CartAPIController@addCart');
|
||||||
|
Route::post('update/cart', 'CartAPIController@updateCart');
|
||||||
|
Route::post('remove/cart', 'CartAPIController@removeProdCart');
|
||||||
|
Route::post('clear/cart', 'CartAPIController@clearCart');
|
||||||
|
|
||||||
// });
|
|
||||||
|
Route::get('shippings', 'CheckoutAPIController@shippingTypes');
|
||||||
|
Route::get('payments', 'CheckoutAPIController@paymentTypes');
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ use Lovata\OrdersShopaholic\Classes\PromoMechanism\ItemPriceContainer;
|
||||||
use Lovata\OrdersShopaholic\Classes\PromoMechanism\TotalPriceContainer;
|
use Lovata\OrdersShopaholic\Classes\PromoMechanism\TotalPriceContainer;
|
||||||
use Lovata\OrdersShopaholic\Classes\Collection\CartPositionCollection;
|
use Lovata\OrdersShopaholic\Classes\Collection\CartPositionCollection;
|
||||||
use Lovata\OrdersShopaholic\Classes\PromoMechanism\CartPromoMechanismProcessor;
|
use Lovata\OrdersShopaholic\Classes\PromoMechanism\CartPromoMechanismProcessor;
|
||||||
|
use Lovata\Shopaholic\Models\Offer as OfferModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class CartProcessor
|
* Class CartProcessor
|
||||||
|
|
@ -439,9 +440,12 @@ class CartProcessor
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($obCartPositionList as $obCartPositionItem) {
|
foreach ($obCartPositionList as $obCartPositionItem) {
|
||||||
|
$product = OfferModel::where("id", $obCartPositionItem->item_id)->with('product')->first();
|
||||||
|
// dd($product);
|
||||||
$arPositionData = [
|
$arPositionData = [
|
||||||
'id' => $obCartPositionItem->id,
|
'id' => $obCartPositionItem->id,
|
||||||
'item_id' => $obCartPositionItem->item_id,
|
'item_id' => $obCartPositionItem->item_id,
|
||||||
|
'product' => $product,
|
||||||
'item_type' => $obCartPositionItem->item_type,
|
'item_type' => $obCartPositionItem->item_type,
|
||||||
'quantity' => (int) $obCartPositionItem->quantity,
|
'quantity' => (int) $obCartPositionItem->quantity,
|
||||||
'max_quantity' => (int) $obCartPositionItem->item->quantity,
|
'max_quantity' => (int) $obCartPositionItem->item->quantity,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue