2018-11-21 06:29:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Webkul\API\Http\Controllers\Shop;
|
|
|
|
|
|
|
|
|
|
use Webkul\API\Http\Controllers\Controller;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Http\Response;
|
|
|
|
|
use Illuminate\Support\Facades\Event;
|
|
|
|
|
use Webkul\Checkout\Repositories\CartRepository;
|
2018-11-24 09:56:31 +00:00
|
|
|
use Auth;
|
2018-11-21 06:29:18 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Cart controller for the APIs of User Cart
|
|
|
|
|
*
|
|
|
|
|
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
|
|
|
|
|
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
|
|
|
|
*/
|
|
|
|
|
class CartController extends Controller
|
|
|
|
|
{
|
|
|
|
|
protected $customer;
|
|
|
|
|
|
|
|
|
|
protected $cart;
|
|
|
|
|
|
|
|
|
|
public function __construct(CartRepository $cart)
|
|
|
|
|
{
|
|
|
|
|
$this->cart = $cart;
|
|
|
|
|
|
|
|
|
|
if(auth()->guard('customer')->check()) {
|
|
|
|
|
$this->customer = auth()->guard('customer')->user();
|
|
|
|
|
} else {
|
2018-11-24 09:56:31 +00:00
|
|
|
$this->customer['message'] = 'unauthorized';
|
|
|
|
|
$this->unAuthorized();
|
2018-11-21 06:29:18 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-24 09:56:31 +00:00
|
|
|
public function unAuthorized() {
|
|
|
|
|
return response()->json($this->customer, 401);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-21 06:29:18 +00:00
|
|
|
public function getAllCart() {
|
|
|
|
|
$carts = $this->customer->carts;
|
|
|
|
|
|
|
|
|
|
if($cart->count() > 0) {
|
|
|
|
|
return response()->json($cart, 200);
|
|
|
|
|
} else {
|
|
|
|
|
return response()->json('Cart Empty', 200);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getActiveCart() {
|
|
|
|
|
return $this->customer->cart;
|
|
|
|
|
}
|
2018-11-24 09:56:31 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a new item in the cart
|
|
|
|
|
*/
|
|
|
|
|
public function add($id) {
|
|
|
|
|
dd('add to cart', $id);
|
|
|
|
|
}
|
2018-11-21 06:29:18 +00:00
|
|
|
}
|