Added api for get request
This commit is contained in:
parent
672f2f8c2b
commit
f489c42bdd
|
|
@ -1,125 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers\Customer;
|
||||
|
||||
use Webkul\API\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Webkul\Customer\Repositories\CustomerAddressRepository as CustomerAddress;
|
||||
use Auth;
|
||||
use Cart;
|
||||
use Validator;
|
||||
|
||||
/**
|
||||
* Address controller for the APIs Customer Address
|
||||
*
|
||||
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
class AddressController extends Controller
|
||||
{
|
||||
protected $customer;
|
||||
protected $customerAddress;
|
||||
|
||||
public function __construct(CustomerAddress $customerAddress)
|
||||
{
|
||||
$this->middleware('auth:customer');
|
||||
|
||||
$this->customerAddress = $customerAddress;
|
||||
|
||||
if (auth()->guard('customer')->check()) {
|
||||
$this->customer = auth()->guard('customer')->user();
|
||||
} else {
|
||||
$this->customer['message'] = 'unauthorized';
|
||||
$this->unAuthorized();
|
||||
}
|
||||
}
|
||||
|
||||
public function unAuthorized() {
|
||||
return response()->json($this->customer, 401);
|
||||
}
|
||||
|
||||
/**
|
||||
* To get the details of user to display on profile
|
||||
*
|
||||
* @return response JSON
|
||||
*/
|
||||
public function get() {
|
||||
if ($this->customer == false) {
|
||||
return response()->json($this->customer, 401);
|
||||
} else {
|
||||
$addresses = $this->customer->addresses;
|
||||
|
||||
return response()->json($addresses, 200);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDefault() {
|
||||
if ($this->customer == false) {
|
||||
return response()->json($this->customer, 401);
|
||||
} else {
|
||||
$defaultAddress = $this->customer->default_address;
|
||||
|
||||
if ($defaultAddress->count() > 0) {
|
||||
return response()->json($defaultAddress, 200);
|
||||
} else {
|
||||
return response()->json(['false, default address not found'], 200);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$data = request()->all();
|
||||
|
||||
$validator = Validator::make(request()->all(), [
|
||||
'address1' => 'string|required',
|
||||
'country' => 'string|required',
|
||||
'state' => 'string|required',
|
||||
'city' => 'string|required',
|
||||
'postcode' => 'required',
|
||||
'phone' => 'required'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->messages(), 400);
|
||||
}
|
||||
|
||||
$cust_id['customer_id'] = $this->customer->id;
|
||||
$data = array_merge($cust_id, $data);
|
||||
|
||||
if ($this->customer->addresses->count() == 0) {
|
||||
$data['default_address'] = 1;
|
||||
}
|
||||
|
||||
$result = $this->customerAddress->create($data);
|
||||
|
||||
if ($result) {
|
||||
return response()->json(true, 200);
|
||||
} else {
|
||||
return response()->json(false, 200);
|
||||
}
|
||||
}
|
||||
|
||||
public function delete($id) {
|
||||
$result = $this->customerAddress->delete($id);
|
||||
|
||||
return response()->json($result, 200);
|
||||
}
|
||||
|
||||
public function makeDefault($id) {
|
||||
$defaultAddress = $this->customer->default_address;
|
||||
|
||||
if ($defaultAddress != null && $defaultAddress->count() > 0) {
|
||||
$defaultAddress->update(['default_address' => 0]);
|
||||
}
|
||||
|
||||
if ($this->customerAddress->find($id)->default_address == 1) {
|
||||
return response()->json(false, 200);
|
||||
}
|
||||
|
||||
$result = $this->customerAddress->update(['default_address' => 1], $id);
|
||||
|
||||
return response()->json($result, 200);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers\Customer;
|
||||
|
||||
use Webkul\API\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
// use Webkul\Customer\Http\Listeners\CustomerEventsHandler;
|
||||
use Auth;
|
||||
use Cart;
|
||||
|
||||
/**
|
||||
* Session controller for the APIs of user customer
|
||||
*
|
||||
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
class AuthController extends Controller
|
||||
{
|
||||
/**
|
||||
* To get the details of user to display on profile
|
||||
*
|
||||
* @return response JSON
|
||||
*/
|
||||
public function create() {
|
||||
$data = request()->except('_token');
|
||||
|
||||
if (! auth()->guard('customer')->check()) {
|
||||
if (! auth()->guard('customer')->attempt($data)) {
|
||||
return response()->json(['message' => 'unauthenticated', 'details' => 'invalid creds'], 401);
|
||||
} else {
|
||||
return response()->json(['message' => 'authenticated', 'user' => auth()->guard('customer')->user()], 200);
|
||||
}
|
||||
} else {
|
||||
return response()->json(['message' => 'already authenticated'], 200);
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy() {
|
||||
auth()->guard('customer')->logout();
|
||||
return response()->json(['message' => 'logged out'], 200);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,116 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers\Customer;
|
||||
|
||||
use Webkul\API\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Auth;
|
||||
use Cart;
|
||||
use Validator;
|
||||
use Hash;
|
||||
|
||||
/**
|
||||
* Customer controller for the APIs of Profile customer
|
||||
*
|
||||
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
class CustomerController extends Controller
|
||||
{
|
||||
protected $customer;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
if (auth()->guard('customer')->check()) {
|
||||
$this->customer = auth()->guard('customer')->user();
|
||||
} else {
|
||||
$this->customer['message'] = 'unauthorized';
|
||||
$this->unAuthorized();
|
||||
}
|
||||
}
|
||||
|
||||
public function unAuthorized() {
|
||||
return response()->json($this->customer, 401);
|
||||
}
|
||||
|
||||
/**
|
||||
* To get the details of user to display on profile
|
||||
* Only accepts the id of simple or configurable product
|
||||
*
|
||||
* @return response JSON
|
||||
*/
|
||||
public function getProfile()
|
||||
{
|
||||
return response()->json($this->customer, 200);
|
||||
}
|
||||
|
||||
public function updateProfile($id)
|
||||
{
|
||||
$validator = Validator::make(request()->all(), [
|
||||
'first_name' => 'string|required',
|
||||
'last_name' => 'string|required',
|
||||
'gender' => 'required',
|
||||
'date_of_birth' => 'date',
|
||||
'email' => 'email|required|unique:customers,email,'.$id,
|
||||
'password' => 'confirmed|required_if:oldpassword,!=,null'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->messages(), 400);
|
||||
}
|
||||
|
||||
$data = collect(request()->all())->toArray();
|
||||
|
||||
if ($data['oldpassword'] == null) {
|
||||
$data = collect(request()->input())->except([ 'oldpassword', 'password', 'password_confirmation'])->toArray();
|
||||
} else {
|
||||
if (Hash::check($data['oldpassword'], auth()->guard('customer')->user()->password)) {
|
||||
$data = collect(request()->input())->toArray();
|
||||
|
||||
$data['password'] = bcrypt($data['password']);
|
||||
} else {
|
||||
return response()->json('Old password does not match', 200);
|
||||
}
|
||||
}
|
||||
|
||||
$result = $this->customer->update($data);
|
||||
|
||||
if ($result) {
|
||||
return response()->json(true, 200);
|
||||
} else {
|
||||
return response()->json(false, 200);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all instances of cart for currently logged in customer
|
||||
*
|
||||
* @return collection Cart
|
||||
*/
|
||||
public function getAllCart() {
|
||||
$carts = $this->customer->carts;
|
||||
|
||||
if ($cart->count() > 0) {
|
||||
return response()->json(['message' => 'successful','items' => $cart], 200);
|
||||
} else {
|
||||
return response()->json(['message' => 'empty', 'items' => null], 200);
|
||||
}
|
||||
}
|
||||
|
||||
public function getActiveCart() {
|
||||
$cart = Cart::getCart();
|
||||
|
||||
if ($cart == null) {
|
||||
return response()->json(['message' => 'empty', 'items' => 'null']);
|
||||
}
|
||||
|
||||
if ($cart->count() > 0 ) {
|
||||
return response()->json(['message' => 'success', 'items' => $cart]);
|
||||
} else {
|
||||
return response()->json(['message' => 'empty', 'items' => 'null']);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers\Customer;
|
||||
|
||||
use Webkul\API\Http\Controllers\Controller;
|
||||
use Webkul\Customer\Repositories\CustomerRepository as Customer;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Validator;
|
||||
|
||||
/**
|
||||
* Registration controller for the APIs of Customer Registration
|
||||
*
|
||||
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
class RegistrationController extends Controller
|
||||
{
|
||||
protected $customer;
|
||||
|
||||
public function __construct(Customer $customer) {
|
||||
$this->customer = $customer;
|
||||
}
|
||||
|
||||
public function create() {
|
||||
$validator = Validator::make(request()->all(), [
|
||||
'first_name' => 'string|required',
|
||||
'last_name' => 'string|required',
|
||||
'email' => 'email|required|unique:customers,email',
|
||||
'password' => 'confirmed|min:6|required',
|
||||
'agreement' => 'required'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($validator->messages(), 400);
|
||||
}
|
||||
|
||||
$data = request()->all();
|
||||
|
||||
$data['password'] = bcrypt($data['password']);
|
||||
|
||||
$data['channel_id'] = core()->getCurrentChannel()->id;
|
||||
|
||||
$data['is_verified'] = 0;
|
||||
|
||||
$result = $this->customer->create($data);
|
||||
|
||||
if ($result) {
|
||||
return response()->json(true, 200);
|
||||
} else {
|
||||
return response()->json(false, 200);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,102 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers\Customer;
|
||||
|
||||
use Webkul\API\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Webkul\Product\Repositories\ProductRepository as Product;
|
||||
use Webkul\Customer\Repositories\WishlistRepository as Wishlist;
|
||||
use Auth;
|
||||
use Cart;
|
||||
|
||||
/**
|
||||
* Wishlist controller for the APIs of User's Wishlist
|
||||
*
|
||||
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
class WishlistController extends Controller
|
||||
{
|
||||
protected $customer;
|
||||
protected $product;
|
||||
protected $wishlist;
|
||||
|
||||
public function __construct(Product $product, Wishlist $wishlist)
|
||||
{
|
||||
if (auth()->guard('customer')->check()) {
|
||||
$this->product = $product;
|
||||
$this->wishlist = $wishlist;
|
||||
$this->customer = auth()->guard('customer')->user();
|
||||
} else {
|
||||
$this->customer['message'] = 'unauthorized';
|
||||
$this->unAuthorized();
|
||||
}
|
||||
}
|
||||
|
||||
public function unAuthorized()
|
||||
{
|
||||
return response()->json($this->customer, 401);
|
||||
}
|
||||
|
||||
public function getWishlist()
|
||||
{
|
||||
$wishlist = $this->customer->wishlist_items;
|
||||
|
||||
if ($wishlist->count() > 0) {
|
||||
return response()->json($wishlist, 200);
|
||||
} else {
|
||||
return response()->json(['message' => 'Wishlist Empty', 'Items' => null], 200);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to add item to the wishlist.
|
||||
* Only accepts the id of simple or configurable product
|
||||
*
|
||||
* @param integer $productId
|
||||
*/
|
||||
public function add($productId)
|
||||
{
|
||||
$product = $this->product->findOneByField('id', $productId);
|
||||
|
||||
$data = [
|
||||
'channel_id' => core()->getCurrentChannel()->id,
|
||||
'product_id' => $productId,
|
||||
'customer_id' => auth()->guard('customer')->user()->id
|
||||
];
|
||||
|
||||
//accidental case if some one adds id of the product in the anchor tag amd gives id of a variant.
|
||||
if ($product->parent_id != null) {
|
||||
$data['product_id'] = $productId = $product->parent_id;
|
||||
}
|
||||
|
||||
$checked = $this->wishlist->findWhere(['channel_id' => core()->getCurrentChannel()->id, 'product_id' => $productId, 'customer_id' => auth()->guard('customer')->user()->id]);
|
||||
|
||||
if ($checked->isEmpty()) {
|
||||
if ($wishlistItem = $this->wishlist->create($data)) {
|
||||
return response()->json(['message' => 'Successfully Added Item To Wishlist', 'items' => $wishlistItem], 200);
|
||||
} else {
|
||||
return response()->json(['message' => 'Error! Cannot Add Item To Wishlist', 'items' => null], 401);
|
||||
}
|
||||
} else {
|
||||
return response()->json(['message' => trans('customer::app.wishlist.already'), 'items' => null], 200);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to remove item to the wishlist.
|
||||
*
|
||||
* @param integer $itemId
|
||||
*/
|
||||
public function delete($itemId)
|
||||
{
|
||||
$result = $this->wishlist->deleteWhere(['customer_id' => auth()->guard('customer')->user()->id, 'channel_id' => core()->getCurrentChannel()->id, 'id' => $itemId]);
|
||||
|
||||
if ($result) {
|
||||
return response()->json(['message' => 'Item Successfully Removed From Wishlist', 'status' => $result]);
|
||||
} else {
|
||||
return response()->json(['message' => 'Error! While Removing Item From Wishlist', 'status' => $result]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers\Product;
|
||||
|
||||
use Webkul\API\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Webkul\Product\Repositories\ProductRepository as Product;
|
||||
|
||||
/**
|
||||
* Product controller
|
||||
*
|
||||
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
class ProductController extends Controller
|
||||
{
|
||||
/**
|
||||
* Contains route related configuration
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_config;
|
||||
|
||||
/**
|
||||
* ProductRepository object
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $product;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @param Webkul\Product\Repositories\ProductRepository $product
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( Product $product)
|
||||
{
|
||||
$this->product = $product;
|
||||
|
||||
$this->_config = request('_config');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param string $slug
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function getBySlug($slug)
|
||||
{
|
||||
$product = $this->product->findBySlugOrFail($slug);
|
||||
|
||||
return response()->json(['message' => 'success', 'product' => $product]);
|
||||
}
|
||||
|
||||
public function getAll() {
|
||||
$products = $this->product->all();
|
||||
|
||||
return response()->json($products, 200);
|
||||
}
|
||||
|
||||
public function getNew() {
|
||||
$newProducts = $this->product->getNewProducts();
|
||||
|
||||
return response()->json($newProducts, 200);
|
||||
}
|
||||
|
||||
public function getFeatured() {
|
||||
$featuredProducts = $this->product->getFeaturedProducts();
|
||||
|
||||
return response()->json($featuredProducts, 200);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,127 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers\Product;
|
||||
|
||||
use Webkul\API\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Webkul\Product\Repositories\ProductRepository as Product;
|
||||
use Webkul\Product\Repositories\ProductReviewRepository as ProductReview;
|
||||
use Webkul\Product\Helpers\Review;
|
||||
use Validator;
|
||||
|
||||
/**
|
||||
* Review controller
|
||||
*
|
||||
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
class ReviewController extends Controller
|
||||
{
|
||||
/**
|
||||
* Contains route related configuration
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_config;
|
||||
|
||||
/**
|
||||
* ProductRepository object
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $product;
|
||||
|
||||
/**
|
||||
* ProductReviewRepository object
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $productReview;
|
||||
|
||||
/**
|
||||
* Review helper Object
|
||||
*
|
||||
*/
|
||||
protected $reviewHelper;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @param Webkul\Product\Repositories\ProductRepository $product
|
||||
* @param Webkul\Product\Repositories\ProductReviewRepository $productReview
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Product $product, ProductReview $productReview, Review $reviewHelper)
|
||||
{
|
||||
// $this->middleware('customer')->only(['create', 'store', 'destroy']);
|
||||
|
||||
$this->product = $product;
|
||||
|
||||
$this->productReview = $productReview;
|
||||
|
||||
$this->reviewHelper = $reviewHelper;
|
||||
|
||||
$this->_config = request('_config');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request , $id)
|
||||
{
|
||||
$this->validate(request(), [
|
||||
'comment' => 'required',
|
||||
'rating' => 'required',
|
||||
'title' => 'required',
|
||||
]);
|
||||
|
||||
$data = request()->all();
|
||||
|
||||
$customer_id = auth()->guard('customer')->user()->id;
|
||||
|
||||
$data['status'] = 'pending';
|
||||
$data['product_id'] = $id;
|
||||
$data['customer_id'] = $customer_id;
|
||||
|
||||
$result = $this->productReview->create($data);
|
||||
|
||||
if ($result) {
|
||||
return response()->json(['message' => 'success', 'status' => $result]);
|
||||
} else {
|
||||
return response()->json(['message' => 'failed', 'status' => $result]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display reviews accroding to product.
|
||||
*
|
||||
* @param string $slug
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($slug)
|
||||
{
|
||||
$product = $this->product->findBySlugOrFail($slug);
|
||||
|
||||
$productReviews = $this->reviewHelper->getReviews($product)->get();
|
||||
|
||||
return $productReviews;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the review of the current product
|
||||
*
|
||||
* @return response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->productReview->delete($id);
|
||||
|
||||
session()->flash('success', 'Product Review Successfully Deleted');
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,126 +0,0 @@
|
|||
<?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;
|
||||
use Webkul\Checkout\Repositories\CartItemRepository as CartItem;
|
||||
use Webkul\API\Http\Controllers\Shop\Presenter as Presenter;
|
||||
use Auth;
|
||||
use Cart;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
protected $cartItem;
|
||||
|
||||
public function __construct(CartRepository $cart, CartItem $cartItem)
|
||||
{
|
||||
$this->cart = $cart;
|
||||
|
||||
$this->cartItem = $cartItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get the current cart instance for customer or guest
|
||||
*
|
||||
* @return Response array && Collection Cart
|
||||
*/
|
||||
public function get() {
|
||||
$cart = Cart::getCart();
|
||||
|
||||
if ($cart == null || $cart == 'null') {
|
||||
return response()->json(['message' => 'empty', 'items' => null]);
|
||||
}
|
||||
|
||||
return response()->json(['message' => 'success', 'items' => $cart]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for guests user to add the product in the cart.
|
||||
*
|
||||
* @return Mixed
|
||||
*/
|
||||
public function add($id) {
|
||||
$result = Cart::add($id, request()->all());
|
||||
|
||||
if ($result) {
|
||||
Cart::collectTotals();
|
||||
|
||||
return response()->json(['message' => 'successful', 'items' => Cart::getCart()->items]);
|
||||
} else {
|
||||
return response()->json(['message' => 'failed', 'items' => Cart::getCart()->items]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the item from the cart if it exists
|
||||
*
|
||||
* @param integer $itemId
|
||||
*/
|
||||
public function remove($itemId) {
|
||||
$result = Cart::removeItem($itemId);
|
||||
|
||||
Cart::collectTotals();
|
||||
|
||||
return response()->json(['message' => $result, 'items' => Cart::getCart()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Before checkout starts or full details on the cart
|
||||
*
|
||||
* @return response json
|
||||
*/
|
||||
public function onePage() {
|
||||
$cart = Cart::getCart();
|
||||
|
||||
if ($cart == null || $cart == 'null') {
|
||||
return response()->json(['message' => 'empty', 'items' => null]);
|
||||
}
|
||||
|
||||
$presenter = new Presenter();
|
||||
$summary = $presenter->onePagePresenter($cart);
|
||||
|
||||
return response()->json(['message' => 'success', 'items' => $cart->items, 'summary' => $summary]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the quantity of the items present in the cart.
|
||||
*
|
||||
* @return response JSON
|
||||
*/
|
||||
public function updateOnePage() {
|
||||
$request = request()->except('_token');
|
||||
|
||||
foreach ($request['qty'] as $id => $quantity) {
|
||||
if ($quantity <= 0) {
|
||||
return response()->json(['message' => 'Illegal Quantity', 'status' => 'error']);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($request['qty'] as $key => $value) {
|
||||
$item = $this->cartItem->findOneByField('id', $key);
|
||||
|
||||
$data['quantity'] = $value;
|
||||
|
||||
$result = Cart::updateItem($item->product_id, $data, $key);
|
||||
|
||||
unset($item);
|
||||
unset($data);
|
||||
}
|
||||
|
||||
Cart::collectTotals();
|
||||
|
||||
return response()->json(['message' => 'success', 'items' => Cart::getCart()]);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
<?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 Illuminate\Support\Collection;
|
||||
use Webkul\Category\Repositories\CategoryRepository as Category;
|
||||
|
||||
/**
|
||||
* Category controller for getting the categories
|
||||
*
|
||||
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
class CategoryController extends Controller
|
||||
{
|
||||
/**
|
||||
* The category implementation.
|
||||
*
|
||||
* for shop bundle's navigation
|
||||
* menu
|
||||
*/
|
||||
protected $category;
|
||||
|
||||
/**
|
||||
* Category Repository DI.
|
||||
*
|
||||
* @param $category Category Instance
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Category $category)
|
||||
{
|
||||
$this->category = $category;
|
||||
}
|
||||
|
||||
public function get() {
|
||||
$categories = [];
|
||||
|
||||
foreach ($this->category->getVisibleCategoryTree() as $category) {
|
||||
array_push($categories, collect($category));
|
||||
}
|
||||
|
||||
return $categories;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers;
|
||||
namespace Webkul\API\Http\Controllers\Shop;
|
||||
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers\Shop;
|
||||
|
||||
/**
|
||||
* Presenter Class for cart and mini cart(if implemented)
|
||||
*/
|
||||
class Presenter {
|
||||
|
||||
/**
|
||||
* presenter method will handle the cart and collect all the necessary data to be displayed on the onepage cart
|
||||
*/
|
||||
public function onePagePresenter($cart) {
|
||||
$cartSummary['grand_total'] = $cart->grand_total;
|
||||
$cartSummary['tax_total'] = $cart->tax_total;
|
||||
$cartSummary['total_items'] = $cart->items_count;
|
||||
$cartSummary['total_items_qty'] = $cart->items_qty;
|
||||
$cartSummary['total_items_qty'] = $cart->items_qty;
|
||||
|
||||
return $cartSummary;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers\Shop;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Webkul\Product\Repositories\ProductRepository;
|
||||
use Webkul\API\Http\Resources\Catalog\Product as ProductResource;
|
||||
|
||||
/**
|
||||
* Product controller
|
||||
*
|
||||
* @author Jitendra Singh <jitendra@webkul.com>
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
class ProductController extends Controller
|
||||
{
|
||||
/**
|
||||
* ProductRepository object
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $productRepository;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @param Webkul\Product\Repositories\ProductRepository $productRepository
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(ProductRepository $productRepository)
|
||||
{
|
||||
// $this->middleware('auth:api');
|
||||
|
||||
$this->productRepository = $productRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return ProductResource::collection($this->productRepository->getAll());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a individual resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
return new ProductResource(
|
||||
$this->productRepository->findOrFail($id)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers\Shop;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
/**
|
||||
* Resource Controller
|
||||
*
|
||||
* @author Jitendra Singh <jitendra@webkul.com>
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
class ResourceController extends Controller
|
||||
{
|
||||
/**
|
||||
* Contains route related configuration
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_config;
|
||||
|
||||
/**
|
||||
* Repository object
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// $this->middleware('auth:api');
|
||||
|
||||
$this->_config = request('_config');
|
||||
|
||||
$this->repository = app($this->_config['repository']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$results = $this->repository->scopeQuery(function($query) {
|
||||
foreach (request()->except(['page', 'limit']) as $input => $value) {
|
||||
$query = $query->where($input, $value);
|
||||
}
|
||||
|
||||
return $query;
|
||||
})->paginate(request()->input('limit') ?? 10);
|
||||
|
||||
return $this->_config['resource']::collection($results);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a individual resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
return new $this->_config['resource'](
|
||||
$this->repository->findOrFail($id)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Catalog;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class Attribute extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'code' => $this->code,
|
||||
'name' => $this->name,
|
||||
'swatch_type' => $this->swatch_type,
|
||||
'options' => AttributeOption::collection($this->options),
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Catalog;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class AttributeFamily extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'code' => $this->code,
|
||||
'name' => $this->name,
|
||||
'status' => $this->status,
|
||||
'groups' => AttributeGroup::collection($this->attribute_groups),
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Catalog;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class AttributeGroup extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'code' => $this->code,
|
||||
'name' => $this->name,
|
||||
'swatch_type' => $this->swatch_type,
|
||||
'attributes' => Attribute::collection($this->custom_attributes)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Catalog;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class AttributeOption extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'admin_name' => $this->admin_name,
|
||||
'label' => $this->label,
|
||||
'swatch_value' => $this->swatch_value
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Catalog;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class Category extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'code' => $this->code,
|
||||
'name' => $this->name,
|
||||
'image_url' => $this->image_url,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Catalog;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class Product extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Create a new resource instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($resource)
|
||||
{
|
||||
$this->productPriceHelper = app('Webkul\Product\Helpers\Price');
|
||||
|
||||
parent::__construct($resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$product = $this->product ? $this->product : $this;
|
||||
|
||||
return [
|
||||
'id' => $product->id,
|
||||
'type' => $product->type,
|
||||
'name' => $this->name,
|
||||
'price' => $this->price,
|
||||
'description' => $this->description,
|
||||
'sku' => $this->sku,
|
||||
'images' => ProductImage::collection($product->images),
|
||||
'variants' => Self::collection($this->variants),
|
||||
'in_stock' => $product->haveSufficientQuantity(1),
|
||||
$this->mergeWhen($product->type == 'configurable', [
|
||||
'super_attributes' => Attribute::collection($product->super_attributes),
|
||||
]),
|
||||
'special_price' => $this->when(
|
||||
$this->productPriceHelper->haveSpecialPrice($product),
|
||||
$this->productPriceHelper->getSpecialPrice($product)
|
||||
),
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Catalog;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ProductImage extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'path' => $this->path,
|
||||
'url' => $this->url,
|
||||
'small_image_url' => url('cache/small/' . $this->path),
|
||||
'medium_image_url' => url('cache/medium/' . $this->path),
|
||||
'large_image_url' => url('cache/large/' . $this->path)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Catalog;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Webkul\API\Http\Resources\Customer\Customer as CustomerResource;
|
||||
|
||||
class ProductReview extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'rating' => $this->rating,
|
||||
'comment' => $this->comment,
|
||||
'name' => $this->name,
|
||||
'status' => $this->status,
|
||||
'product' => new Product($this->product),
|
||||
'customer' => $this->when($this->customer_id, new CustomerResource($this->customer)),
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Core;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Webkul\API\Http\Resources\Core\Locale as LocaleResource;
|
||||
use Webkul\API\Http\Resources\Core\Currency as CurrencyResource;
|
||||
use Webkul\API\Http\Resources\Catalog\Category as CategoryResource;
|
||||
|
||||
class Channel extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'code' => $this->code,
|
||||
'name' => $this->name,
|
||||
'description' => $this->description,
|
||||
'timezone' => $this->timezone,
|
||||
'theme' => $this->theme,
|
||||
'home_page_content' => $this->home_page_content,
|
||||
'footer_content' => $this->footer_content,
|
||||
'hostname' => $this->hostname,
|
||||
'logo' => $this->logo,
|
||||
'logo_url' => $this->logo_url,
|
||||
'favicon' => $this->favicon,
|
||||
'favicon_url' => $this->favicon_url,
|
||||
'default_locale' => $this->when($this->default_locale_id, new LocaleResource($this->default_locale)),
|
||||
'base_currency' => $this->when($this->default_currency_id, new CurrencyResource($this->default_currency)),
|
||||
'root_category' => $this->when($this->root_category_id, new CategoryResource($this->root_category)),
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Core;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class Currency extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'code' => $this->code,
|
||||
'name' => $this->name,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Core;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class Locale extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'code' => $this->code,
|
||||
'name' => $this->name,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Core;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class Slider extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'image_url' => $this->image_url,
|
||||
'content' => $this->content
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Customer;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class Customer extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'email' => $this->email,
|
||||
'first_name' => $this->first_name,
|
||||
'last_name' => $this->last_name,
|
||||
'name' => $this->name,
|
||||
'gender' => $this->gender,
|
||||
'date_of_birth' => $this->date_of_birth,
|
||||
'phone' => $this->phone,
|
||||
'status' => $this->status,
|
||||
'group' => $this->when($this->customer_group_id, new CustomerGroup($this->group)),
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Customer;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class CustomerAddress extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'address1' => $this->address1,
|
||||
'address2' => $this->address2,
|
||||
'country' => $this->country,
|
||||
'state' => $this->state,
|
||||
'city' => $this->city,
|
||||
'postcode' => $this->postcode,
|
||||
'phone' => $this->phone,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Customer;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class CustomerGroup extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Customer;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Webkul\API\Http\Resources\Catalog\Product as ProductResource;
|
||||
|
||||
class Wishlist extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'product' => new ProductResource($this->product),
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Inventory;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class InventorySource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'code' => $this->code,
|
||||
'name' => $this->name,
|
||||
'description' => $this->description,
|
||||
'contact_name' => $this->contact_name,
|
||||
'contact_email' => $this->contact_email,
|
||||
'contact_number' => $this->contact_number,
|
||||
'contact_fax' => $this->contact_fax,
|
||||
'country' => $this->country,
|
||||
'state' => $this->state,
|
||||
'city' => $this->city,
|
||||
'street' => $this->street,
|
||||
'postcode' => $this->postcode,
|
||||
'priority' => $this->priority,
|
||||
'latitude' => $this->latitude,
|
||||
'longitude' => $this->collongitudeongitudeuntry,
|
||||
'status' => $this->status,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Sales;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class Invoice extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'state' => $this->state,
|
||||
'email_sent' => $this->email_sent,
|
||||
'total_qty' => $this->total_qty,
|
||||
'base_currency_code' => $this->base_currency_code,
|
||||
'channel_currency_code' => $this->channel_currency_code,
|
||||
'order_currency_code' => $this->order_currency_code,
|
||||
'sub_total' => $this->sub_total,
|
||||
'base_sub_total' => $this->base_sub_total,
|
||||
'grand_total' => $this->grand_total,
|
||||
'base_grand_total' => $this->base_grand_total,
|
||||
'shipping_amount' => $this->shipping_amount,
|
||||
'base_shipping_amount' => $this->base_shipping_amount,
|
||||
'tax_amount' => $this->tax_amount,
|
||||
'base_tax_amount' => $this->base_tax_amount,
|
||||
'discount_amount' => $this->discount_amount,
|
||||
'base_discount_amount' => $this->base_discount_amount,
|
||||
'order_address' => new OrderAddress($this->address),
|
||||
'transaction_id' => $this->transaction_id,
|
||||
'items' => InvoiceItem::collection($this->items),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Sales;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class InvoiceItem extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'description' => $this->description,
|
||||
'sku' => $this->sku,
|
||||
'description' => $this->description,
|
||||
'qty' => $this->qty,
|
||||
'price' => $this->price,
|
||||
'base_price' => $this->base_price,
|
||||
'total' => $this->total,
|
||||
'base_total' => $this->base_total,
|
||||
'tax_amount' => $this->tax_amount,
|
||||
'base_tax_amount' => $this->base_tax_amount,
|
||||
'additional' => is_array($this->resource->additional)
|
||||
? $this->resource->additional
|
||||
: json_decode($this->resource->additional, true),
|
||||
'child' => new self($this->child)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Sales;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Webkul\API\Http\Resources\Core\Channel as ChannelResource;
|
||||
use Webkul\API\Http\Resources\Customer\Customer as CustomerResource;
|
||||
|
||||
class Order extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'status' => $this->status,
|
||||
'channel_name' => $this->channel_name,
|
||||
'is_guest' => $this->is_guest,
|
||||
'customer_email' => $this->customer_email,
|
||||
'customer_first_name' => $this->customer_first_name,
|
||||
'customer_last_name' => $this->customer_last_name,
|
||||
'shipping_method' => $this->shipping_method,
|
||||
'shipping_title' => $this->shipping_title,
|
||||
'shipping_description' => $this->shipping_description,
|
||||
'coupon_code' => $this->coupon_code,
|
||||
'is_gift' => $this->is_gift,
|
||||
'total_item_count' => $this->total_item_count,
|
||||
'total_qty_ordered' => $this->total_qty_ordered,
|
||||
'base_currency_code' => $this->base_currency_code,
|
||||
'channel_currency_code' => $this->channel_currency_code,
|
||||
'order_currency_code' => $this->order_currency_code,
|
||||
'grand_total' => $this->grand_total,
|
||||
'base_grand_total' => $this->base_grand_total,
|
||||
'grand_total_invoiced' => $this->grand_total_invoiced,
|
||||
'base_grand_total_invoiced' => $this->base_grand_total_invoiced,
|
||||
'grand_total_refunded' => $this->grand_total_refunded,
|
||||
'base_grand_total_refunded' => $this->base_grand_total_refunded,
|
||||
'sub_total' => $this->sub_total,
|
||||
'base_sub_total' => $this->base_sub_total,
|
||||
'sub_total_invoiced' => $this->sub_total_invoiced,
|
||||
'base_sub_total_invoiced' => $this->base_sub_total_invoiced,
|
||||
'sub_total_refunded' => $this->sub_total_refunded,
|
||||
'discount_percent' => $this->discount_percent,
|
||||
'discount_amount' => $this->discount_amount,
|
||||
'base_discount_amount' => $this->base_discount_amount,
|
||||
'discount_invoiced' => $this->discount_invoiced,
|
||||
'base_discount_invoiced' => $this->base_discount_invoiced,
|
||||
'discount_refunded' => $this->discount_refunded,
|
||||
'base_discount_refunded' => $this->base_discount_refunded,
|
||||
'tax_amount' => $this->tax_amount,
|
||||
'base_tax_amount' => $this->base_tax_amount,
|
||||
'tax_amount_invoiced' => $this->tax_amount_invoiced,
|
||||
'base_tax_amount_invoiced' => $this->base_tax_amount_invoiced,
|
||||
'tax_amount_refunded' => $this->tax_amount_refunded,
|
||||
'base_tax_amount_refunded' => $this->base_tax_amount_refunded,
|
||||
'shipping_amount' => $this->shipping_amount,
|
||||
'base_shipping_amount' => $this->base_shipping_amount,
|
||||
'shipping_invoiced' => $this->shipping_invoiced,
|
||||
'base_shipping_invoiced' => $this->base_shipping_invoiced,
|
||||
'shipping_refunded' => $this->shipping_refunded,
|
||||
'base_shipping_refunded' => $this->base_shipping_refunded,
|
||||
'customer' => $this->when($this->customer_id, new CustomerResource($this->customer)),
|
||||
'channel' => $this->when($this->channel_id, new ChannelResource($this->channel)),
|
||||
'updated_at' => $this->updated_at,
|
||||
'items' => OrderItem::collection($this->items),
|
||||
'invoices' => Invoice::collection($this->invoices),
|
||||
'shipments' => Shipment::collection($this->shipments),
|
||||
'created_at' => $this->created_at
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Sales;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class OrderAddress extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'email' => $this->email,
|
||||
'first_name' => $this->first_name,
|
||||
'last_name' => $this->last_name,
|
||||
'address1' => $this->address1,
|
||||
'address2' => $this->address2,
|
||||
'country' => $this->country,
|
||||
'state' => $this->state,
|
||||
'city' => $this->city,
|
||||
'postcode' => $this->postcode,
|
||||
'phone' => $this->phone,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Sales;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class OrderItem extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'sku' => $this->sku,
|
||||
'type' => $this->type,
|
||||
'name' => $this->name,
|
||||
'coupon_code' => $this->coupon_code,
|
||||
'weight' => $this->weight,
|
||||
'total_weight' => $this->total_weight,
|
||||
'qty_ordered' => $this->qty_ordered,
|
||||
'qty_canceled' => $this->qty_canceled,
|
||||
'qty_shipped' => $this->qty_shipped,
|
||||
'qty_refunded' => $this->qty_refunded,
|
||||
'price' => $this->price,
|
||||
'base_price' => $this->base_price,
|
||||
'total' => $this->total,
|
||||
'base_total' => $this->base_total,
|
||||
'total_invoiced' => $this->total_invoiced,
|
||||
'base_total_invoiced' => $this->base_total_invoiced,
|
||||
'amount_refunded' => $this->amount_refunded,
|
||||
'base_amount_refunded' => $this->base_amount_refunded,
|
||||
'discount_percent' => $this->discount_percent,
|
||||
'discount_amount' => $this->discount_amount,
|
||||
'base_discount_amount' => $this->base_discount_amount,
|
||||
'discount_invoiced' => $this->discount_invoiced,
|
||||
'base_discount_invoiced' => $this->base_discount_invoiced,
|
||||
'discount_refunded' => $this->discount_refunded,
|
||||
'base_discount_refunded' => $this->base_discount_refunded,
|
||||
'tax_percent' => $this->tax_percent,
|
||||
'tax_amount' => $this->tax_amount,
|
||||
'base_tax_amount' => $this->base_tax_amount,
|
||||
'tax_amount_invoiced' => $this->tax_amount_invoiced,
|
||||
'base_tax_amount_invoiced' => $this->base_tax_amount_invoiced,
|
||||
'tax_amount_refunded' => $this->tax_amount_refunded,
|
||||
'base_tax_amount_refunded' => $this->base_tax_amount_refunded,
|
||||
'additional' => is_array($this->resource->additional)
|
||||
? $this->resource->additional
|
||||
: json_decode($this->resource->additional, true),
|
||||
'child' => new self($this->child)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Sales;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Webkul\API\Http\Resources\Customer\Customer as CustomerResource;
|
||||
use Webkul\API\Http\Resources\Inventory\InventorySource as InventorySourceResource;
|
||||
|
||||
class Shipment extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'status' => $this->status,
|
||||
'total_qty' => $this->total_qty,
|
||||
'total_weight' => $this->total_weight,
|
||||
'carrier_code' => $this->carrier_code,
|
||||
'carrier_title' => $this->carrier_title,
|
||||
'track_number' => $this->track_number,
|
||||
'email_sent' => $this->email_sent,
|
||||
'customer' => $this->when($this->customer_id, new CustomerResource($this->customer)),
|
||||
'inventory_source' => $this->when($this->inventory_source_id, new InventorySourceResource($this->inventory_source)),
|
||||
'items' => ShipmentItem::collection($this->items),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Sales;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ShipmentItem extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'description' => $this->description,
|
||||
'sku' => $this->sku,
|
||||
'qty' => $this->qty,
|
||||
'weight' => $this->weight,
|
||||
'price' => $this->price,
|
||||
'base_price' => $this->base_price,
|
||||
'total' => $this->total,
|
||||
'base_total' => $this->base_total,
|
||||
'additional' => is_array($this->resource->additional)
|
||||
? $this->resource->additional
|
||||
: json_decode($this->resource->additional, true)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
<?php
|
||||
|
||||
Route::group(['namespace' => 'Webkul\API\Http\Controllers\Customer', 'prefix' => 'api/customer'], function ($router) {
|
||||
//customer registration API
|
||||
Route::post('/register', 'RegistrationController@create');
|
||||
|
||||
//auth route for customer
|
||||
Route::post('login', 'AuthController@create');
|
||||
//auth route for customer
|
||||
Route::post('logout', 'AuthController@destroy');
|
||||
|
||||
//get customer profile
|
||||
Route::get('get/profile', 'CustomerController@getProfile');
|
||||
Route::put('update/profile/{id}', 'CustomerController@updateProfile');
|
||||
|
||||
//wishlist
|
||||
//get wishlist
|
||||
Route::get('get/wishlist', 'WishlistController@getWishlist');
|
||||
//add the item in the wishlist
|
||||
Route::get('add/wishlist/{id}', 'WishlistController@add');
|
||||
//delete the item from the wishlist
|
||||
Route::get('delete/wishlist/{id}', 'WishlistController@delete');
|
||||
//Move the item from the wishlist to cart
|
||||
// Route::get('delete/wishlist/{id}', 'WishlistController@delete');
|
||||
|
||||
//address
|
||||
Route::get('get/address', 'AddressController@get');
|
||||
Route::get('get/default/address', 'AddressController@getDefault');
|
||||
Route::post('create/address', 'AddressController@create');
|
||||
Route::put('make/default/address/{id}', 'AddressController@makeDefault');
|
||||
Route::delete('delete/address/{id}', 'AddressController@delete');
|
||||
|
||||
//cart -> not to be used
|
||||
//active + inactive instances of cart for the current logged in user
|
||||
Route::get('get/all', 'CustomerController@getAllCart');
|
||||
//active instances of cart for the current logged in user
|
||||
Route::get('get/active', 'CustomerController@getActiveCart');
|
||||
});
|
||||
|
||||
//all the cart related API for customer and guests
|
||||
Route::group(['namespace' => 'Webkul\API\Http\Controllers\Shop', 'prefix' => 'api/cart'], function ($router) {
|
||||
//cart
|
||||
Route::get('get', 'CartController@get');
|
||||
//add item in the cart
|
||||
Route::post('add/{id}', 'CartController@add');
|
||||
//remove item to the cart
|
||||
Route::get('remove/{id}', 'CartController@remove');
|
||||
//get cart and all item for cart checkout
|
||||
Route::get('/onepage', 'CartController@onePage');
|
||||
//update OnePage
|
||||
Route::put('/update/onepage', 'CartController@updateOnePage');
|
||||
});
|
||||
|
||||
//all the product related API to be used for store front
|
||||
Route::group(['namespace' => 'Webkul\API\Http\Controllers\Product', 'prefix' => 'api/product'], function ($router) {
|
||||
//product
|
||||
//to get all products
|
||||
Route::get('get/all', 'ProductController@getAll');
|
||||
//to fetch the new products
|
||||
Route::get('get/new', 'ProductController@getNew');
|
||||
//to fetch the featured product
|
||||
Route::get('get/featured', 'ProductController@getFeatured');
|
||||
//to get the product by its slug
|
||||
Route::get('get/{slug}', 'ProductController@getBySlug');
|
||||
|
||||
//product reviews get and create
|
||||
//to get the reviews of the product
|
||||
Route::get('review/{slug}', 'ReviewController@show');
|
||||
//to store the review for a product
|
||||
Route::post('review/{slug}', 'ReviewController@create');
|
||||
});
|
||||
|
||||
//all the shop related API to be used for store front
|
||||
Route::group(['namespace' => 'Webkul\API\Http\Controllers\Shop', 'prefix' => 'api/shop'], function ($router) {
|
||||
Route::get('get/category', 'CategoryController@get');
|
||||
});
|
||||
|
|
@ -0,0 +1,175 @@
|
|||
<?php
|
||||
|
||||
Route::group(['prefix' => 'api'], function ($router) {
|
||||
|
||||
Route::group(['namespace' => 'Webkul\API\Http\Controllers\Shop'], function ($router) {
|
||||
|
||||
//Category routes
|
||||
Route::get('categories', 'ResourceController@index')->defaults('_config', [
|
||||
'repository' => 'Webkul\Category\Repositories\CategoryRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Catalog\Category'
|
||||
]);
|
||||
|
||||
Route::get('categories/{id}', 'ResourceController@get')->defaults('_config', [
|
||||
'repository' => 'Webkul\Category\Repositories\CategoryRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Catalog\Category'
|
||||
]);
|
||||
|
||||
|
||||
//Attribute routes
|
||||
Route::get('attributes', 'ResourceController@index')->defaults('_config', [
|
||||
'repository' => 'Webkul\Attribute\Repositories\AttributeRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Catalog\Attribute'
|
||||
]);
|
||||
|
||||
Route::get('attributes/{id}', 'ResourceController@get')->defaults('_config', [
|
||||
'repository' => 'Webkul\Attribute\Repositories\AttributeRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Catalog\Attribute'
|
||||
]);
|
||||
|
||||
|
||||
//AttributeFamily routes
|
||||
Route::get('families', 'ResourceController@index')->defaults('_config', [
|
||||
'repository' => 'Webkul\Attribute\Repositories\AttributeFamilyRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Catalog\AttributeFamily'
|
||||
]);
|
||||
|
||||
Route::get('families/{id}', 'ResourceController@get')->defaults('_config', [
|
||||
'repository' => 'Webkul\Attribute\Repositories\AttributeFamilyRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Catalog\AttributeFamily'
|
||||
]);
|
||||
|
||||
|
||||
//Product routes
|
||||
Route::get('products', 'ProductController@index');
|
||||
|
||||
Route::get('products/{id}', 'ProductController@get');
|
||||
|
||||
|
||||
//Product Review routes
|
||||
Route::get('reviews', 'ResourceController@index')->defaults('_config', [
|
||||
'repository' => 'Webkul\Product\Repositories\ProductReviewRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Catalog\ProductReview'
|
||||
]);
|
||||
|
||||
Route::get('reviews/{id}', 'ResourceController@get')->defaults('_config', [
|
||||
'repository' => 'Webkul\Product\Repositories\ProductReviewRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Catalog\ProductReview'
|
||||
]);
|
||||
|
||||
|
||||
//Channel routes
|
||||
Route::get('channels', 'ResourceController@index')->defaults('_config', [
|
||||
'repository' => 'Webkul\Core\Repositories\ChannelRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Core\Channel'
|
||||
]);
|
||||
|
||||
Route::get('channels/{id}', 'ResourceController@get')->defaults('_config', [
|
||||
'repository' => 'Webkul\Core\Repositories\ChannelRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Core\Channel'
|
||||
]);
|
||||
|
||||
|
||||
//Locale routes
|
||||
Route::get('locales', 'ResourceController@index')->defaults('_config', [
|
||||
'repository' => 'Webkul\Core\Repositories\LocaleRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Core\Locale'
|
||||
]);
|
||||
|
||||
Route::get('locales/{id}', 'ResourceController@get')->defaults('_config', [
|
||||
'repository' => 'Webkul\Core\Repositories\LocaleRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Core\Locale'
|
||||
]);
|
||||
|
||||
|
||||
//Slider routes
|
||||
Route::get('sliders', 'ResourceController@index')->defaults('_config', [
|
||||
'repository' => 'Webkul\Core\Repositories\SliderRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Core\Slider'
|
||||
]);
|
||||
|
||||
Route::get('sliders/{id}', 'ResourceController@get')->defaults('_config', [
|
||||
'repository' => 'Webkul\Core\Repositories\SliderRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Core\Slider'
|
||||
]);
|
||||
|
||||
|
||||
//Currency routes
|
||||
Route::get('currencies', 'ResourceController@index')->defaults('_config', [
|
||||
'repository' => 'Webkul\Core\Repositories\CurrencyRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Core\Currency'
|
||||
]);
|
||||
|
||||
Route::get('currencies/{id}', 'ResourceController@get')->defaults('_config', [
|
||||
'repository' => 'Webkul\Core\Repositories\CurrencyRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Core\Currency'
|
||||
]);
|
||||
|
||||
|
||||
//Customer routes
|
||||
Route::get('customers', 'ResourceController@index')->defaults('_config', [
|
||||
'repository' => 'Webkul\Customer\Repositories\CustomerRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Customer\Customer'
|
||||
]);
|
||||
|
||||
Route::get('customers/{id}', 'ResourceController@get')->defaults('_config', [
|
||||
'repository' => 'Webkul\Customer\Repositories\CustomerRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Customer\Customer'
|
||||
]);
|
||||
|
||||
|
||||
//Customer Address routes
|
||||
Route::get('addresses', 'ResourceController@index')->defaults('_config', [
|
||||
'repository' => 'Webkul\Customer\Repositories\CustomerAddressRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Customer\CustomerAddress'
|
||||
]);
|
||||
|
||||
Route::get('addresses/{id}', 'ResourceController@get')->defaults('_config', [
|
||||
'repository' => 'Webkul\Customer\Repositories\CustomerAddressRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Customer\CustomerAddress'
|
||||
]);
|
||||
|
||||
|
||||
//Order routes
|
||||
Route::get('orders', 'ResourceController@index')->defaults('_config', [
|
||||
'repository' => 'Webkul\Sales\Repositories\OrderRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Sales\Order'
|
||||
]);
|
||||
|
||||
Route::get('orders/{id}', 'ResourceController@get')->defaults('_config', [
|
||||
'repository' => 'Webkul\Sales\Repositories\OrderRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Sales\Order'
|
||||
]);
|
||||
|
||||
|
||||
//Invoice routes
|
||||
Route::get('invoices', 'ResourceController@index')->defaults('_config', [
|
||||
'repository' => 'Webkul\Sales\Repositories\InvoiceRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Sales\Invoice'
|
||||
]);
|
||||
|
||||
Route::get('invoices/{id}', 'ResourceController@get')->defaults('_config', [
|
||||
'repository' => 'Webkul\Sales\Repositories\InvoiceRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Sales\Invoice'
|
||||
]);
|
||||
|
||||
|
||||
//Invoice routes
|
||||
Route::get('shipments', 'ResourceController@index')->defaults('_config', [
|
||||
'repository' => 'Webkul\Sales\Repositories\ShipmentRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Sales\Shipment'
|
||||
]);
|
||||
|
||||
Route::get('shipments/{id}', 'ResourceController@get')->defaults('_config', [
|
||||
'repository' => 'Webkul\Sales\Repositories\ShipmentRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Sales\Shipment'
|
||||
]);
|
||||
|
||||
|
||||
//Wishlist routes
|
||||
Route::get('wishlist', 'ResourceController@index')->defaults('_config', [
|
||||
'repository' => 'Webkul\Customer\Repositories\WishlistRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Customer\Wishlist'
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
|
@ -13,9 +13,7 @@ class APIServiceProvider extends ServiceProvider
|
|||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->loadRoutesFrom(__DIR__.'/../Http/api.php');
|
||||
|
||||
$this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
|
||||
$this->loadRoutesFrom(__DIR__.'/../Http/routes.php');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -25,20 +23,5 @@ class APIServiceProvider extends ServiceProvider
|
|||
*/
|
||||
public function register()
|
||||
{
|
||||
// $app['Dingo\Api\Auth\Auth']->extend('oauth', function ($app) {
|
||||
// return new Dingo\Api\Auth\Provider\JWT($app['Tymon\JWTAuth\JWTAuth']);
|
||||
// });
|
||||
|
||||
// $app['Dingo\Api\Http\RateLimit\Handler']->extend(function ($app) {
|
||||
// return new Dingo\Api\Http\RateLimit\Throttle\Authenticated;
|
||||
// });
|
||||
|
||||
// $app['Dingo\Api\Transformer\Factory']->setAdapter(function ($app) {
|
||||
// $fractal = new League\Fractal\Manager;
|
||||
|
||||
// $fractal->setSerializer(new League\Fractal\Serializer\JsonApiSerializer);
|
||||
|
||||
// return new Dingo\Api\Transformer\Adapter\Fractal($fractal);
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,12 @@ use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
|||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
protected $jsonErrorMessages = [
|
||||
404 => 'Resource not found',
|
||||
403 => '403 forbidden Error',
|
||||
401 => 'Unauthenticated',
|
||||
500 => '500 Internal Server Error',
|
||||
];
|
||||
|
||||
/**
|
||||
* Render an exception into an HTTP response.
|
||||
|
|
@ -25,8 +31,8 @@ class Handler extends ExceptionHandler
|
|||
$path = $this->isAdminUri() ? 'admin' : 'shop';
|
||||
|
||||
if ($exception instanceof HttpException) {
|
||||
$statusCode = $exception->getStatusCode();
|
||||
$statusCode = in_array($statusCode, [401, 403, 404, 503]) ? $statusCode : 500;
|
||||
$statusCode = in_array($exception->getStatusCode(), [401, 403, 404, 503]) ? $exception->getStatusCode() : 500;
|
||||
|
||||
return $this->response($path, $statusCode);
|
||||
} else if ($exception instanceof ModelNotFoundException) {
|
||||
return $this->response($path, 404);
|
||||
|
|
@ -37,6 +43,22 @@ class Handler extends ExceptionHandler
|
|||
return parent::render($request, $exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an authentication exception into a response.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Illuminate\Auth\AuthenticationException $exception
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
protected function unauthenticated($request, AuthenticationException $exception)
|
||||
{
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json(['error' => $this->jsonErrorMessages[401]], 401);
|
||||
}
|
||||
|
||||
return redirect()->guest(route('auth.login'));
|
||||
}
|
||||
|
||||
private function isAdminUri()
|
||||
{
|
||||
return strpos($_SERVER['REQUEST_URI'], 'admin') !== false ? true : false;
|
||||
|
|
@ -44,7 +66,14 @@ class Handler extends ExceptionHandler
|
|||
|
||||
private function response($path, $statusCode)
|
||||
{
|
||||
if (request()->expectsJson()) {
|
||||
return response()->json([
|
||||
'error' => isset($this->jsonErrorMessages[$statusCode])
|
||||
? $this->jsonErrorMessages[$statusCode]
|
||||
: 'Something went wrong, please try again later.'
|
||||
], $statusCode);
|
||||
}
|
||||
|
||||
return response()->view("{$path}::errors.{$statusCode}", [], $statusCode);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue