diff --git a/packages/Webkul/API/Http/Controllers/Customer/AddressController.php b/packages/Webkul/API/Http/Controllers/Customer/AddressController.php deleted file mode 100755 index 818f0db61..000000000 --- a/packages/Webkul/API/Http/Controllers/Customer/AddressController.php +++ /dev/null @@ -1,125 +0,0 @@ - @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); - } -} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Controllers/Customer/AuthController.php b/packages/Webkul/API/Http/Controllers/Customer/AuthController.php deleted file mode 100755 index 5cdd21aeb..000000000 --- a/packages/Webkul/API/Http/Controllers/Customer/AuthController.php +++ /dev/null @@ -1,44 +0,0 @@ - @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); - } -} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Controllers/Customer/CustomerController.php b/packages/Webkul/API/Http/Controllers/Customer/CustomerController.php deleted file mode 100755 index 3888fb25f..000000000 --- a/packages/Webkul/API/Http/Controllers/Customer/CustomerController.php +++ /dev/null @@ -1,116 +0,0 @@ - @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']); - } - } - -} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Controllers/Customer/RegistrationController.php b/packages/Webkul/API/Http/Controllers/Customer/RegistrationController.php deleted file mode 100755 index ee6a07465..000000000 --- a/packages/Webkul/API/Http/Controllers/Customer/RegistrationController.php +++ /dev/null @@ -1,55 +0,0 @@ - @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); - } - } -} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Controllers/Customer/WishlistController.php b/packages/Webkul/API/Http/Controllers/Customer/WishlistController.php deleted file mode 100755 index 3f10f1545..000000000 --- a/packages/Webkul/API/Http/Controllers/Customer/WishlistController.php +++ /dev/null @@ -1,102 +0,0 @@ - @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]); - } - } -} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Controllers/Product/ProductController.php b/packages/Webkul/API/Http/Controllers/Product/ProductController.php deleted file mode 100755 index de3452dc7..000000000 --- a/packages/Webkul/API/Http/Controllers/Product/ProductController.php +++ /dev/null @@ -1,75 +0,0 @@ - @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); - } -} diff --git a/packages/Webkul/API/Http/Controllers/Product/ReviewController.php b/packages/Webkul/API/Http/Controllers/Product/ReviewController.php deleted file mode 100755 index dcbce5f01..000000000 --- a/packages/Webkul/API/Http/Controllers/Product/ReviewController.php +++ /dev/null @@ -1,127 +0,0 @@ - @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(); - } -} diff --git a/packages/Webkul/API/Http/Controllers/Shop/CartController.php b/packages/Webkul/API/Http/Controllers/Shop/CartController.php deleted file mode 100755 index eef1404f6..000000000 --- a/packages/Webkul/API/Http/Controllers/Shop/CartController.php +++ /dev/null @@ -1,126 +0,0 @@ - @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()]); - } -} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Controllers/Shop/CategoryController.php b/packages/Webkul/API/Http/Controllers/Shop/CategoryController.php deleted file mode 100755 index 56a0ba14e..000000000 --- a/packages/Webkul/API/Http/Controllers/Shop/CategoryController.php +++ /dev/null @@ -1,49 +0,0 @@ - @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; - } - -} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Controllers/Controller.php b/packages/Webkul/API/Http/Controllers/Shop/Controller.php similarity index 88% rename from packages/Webkul/API/Http/Controllers/Controller.php rename to packages/Webkul/API/Http/Controllers/Shop/Controller.php index 907d9c538..317c1d81c 100755 --- a/packages/Webkul/API/Http/Controllers/Controller.php +++ b/packages/Webkul/API/Http/Controllers/Shop/Controller.php @@ -1,6 +1,6 @@ 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; - } -} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Controllers/Shop/ProductController.php b/packages/Webkul/API/Http/Controllers/Shop/ProductController.php new file mode 100755 index 000000000..65d9b9ec1 --- /dev/null +++ b/packages/Webkul/API/Http/Controllers/Shop/ProductController.php @@ -0,0 +1,59 @@ + + * @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) + ); + } +} diff --git a/packages/Webkul/API/Http/Controllers/Shop/ResourceController.php b/packages/Webkul/API/Http/Controllers/Shop/ResourceController.php new file mode 100644 index 000000000..4ef6c8817 --- /dev/null +++ b/packages/Webkul/API/Http/Controllers/Shop/ResourceController.php @@ -0,0 +1,73 @@ + + * @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) + ); + } +} diff --git a/packages/Webkul/API/Http/Resources/Catalog/Attribute.php b/packages/Webkul/API/Http/Resources/Catalog/Attribute.php new file mode 100644 index 000000000..53d7be651 --- /dev/null +++ b/packages/Webkul/API/Http/Resources/Catalog/Attribute.php @@ -0,0 +1,27 @@ + $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, + ]; + } +} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Resources/Catalog/AttributeFamily.php b/packages/Webkul/API/Http/Resources/Catalog/AttributeFamily.php new file mode 100644 index 000000000..6c6743531 --- /dev/null +++ b/packages/Webkul/API/Http/Resources/Catalog/AttributeFamily.php @@ -0,0 +1,27 @@ + $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, + ]; + } +} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Resources/Catalog/AttributeGroup.php b/packages/Webkul/API/Http/Resources/Catalog/AttributeGroup.php new file mode 100644 index 000000000..81fbfbf8e --- /dev/null +++ b/packages/Webkul/API/Http/Resources/Catalog/AttributeGroup.php @@ -0,0 +1,25 @@ + $this->id, + 'code' => $this->code, + 'name' => $this->name, + 'swatch_type' => $this->swatch_type, + 'attributes' => Attribute::collection($this->custom_attributes) + ]; + } +} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Resources/Catalog/AttributeOption.php b/packages/Webkul/API/Http/Resources/Catalog/AttributeOption.php new file mode 100644 index 000000000..ff4f21e8e --- /dev/null +++ b/packages/Webkul/API/Http/Resources/Catalog/AttributeOption.php @@ -0,0 +1,24 @@ + $this->id, + 'admin_name' => $this->admin_name, + 'label' => $this->label, + 'swatch_value' => $this->swatch_value + ]; + } +} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Resources/Catalog/Category.php b/packages/Webkul/API/Http/Resources/Catalog/Category.php new file mode 100644 index 000000000..7a531428e --- /dev/null +++ b/packages/Webkul/API/Http/Resources/Catalog/Category.php @@ -0,0 +1,26 @@ + $this->id, + 'code' => $this->code, + 'name' => $this->name, + 'image_url' => $this->image_url, + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + ]; + } +} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Resources/Catalog/Product.php b/packages/Webkul/API/Http/Resources/Catalog/Product.php new file mode 100644 index 000000000..de23c8815 --- /dev/null +++ b/packages/Webkul/API/Http/Resources/Catalog/Product.php @@ -0,0 +1,52 @@ +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, + ]; + } +} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Resources/Catalog/ProductImage.php b/packages/Webkul/API/Http/Resources/Catalog/ProductImage.php new file mode 100644 index 000000000..6cbff228b --- /dev/null +++ b/packages/Webkul/API/Http/Resources/Catalog/ProductImage.php @@ -0,0 +1,26 @@ + $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) + ]; + } +} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Resources/Catalog/ProductReview.php b/packages/Webkul/API/Http/Resources/Catalog/ProductReview.php new file mode 100644 index 000000000..4b6799283 --- /dev/null +++ b/packages/Webkul/API/Http/Resources/Catalog/ProductReview.php @@ -0,0 +1,31 @@ + $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, + ]; + } +} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Resources/Core/Channel.php b/packages/Webkul/API/Http/Resources/Core/Channel.php new file mode 100644 index 000000000..e80393075 --- /dev/null +++ b/packages/Webkul/API/Http/Resources/Core/Channel.php @@ -0,0 +1,41 @@ + $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, + ]; + } +} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Resources/Core/Currency.php b/packages/Webkul/API/Http/Resources/Core/Currency.php new file mode 100644 index 000000000..5ef066daa --- /dev/null +++ b/packages/Webkul/API/Http/Resources/Core/Currency.php @@ -0,0 +1,25 @@ + $this->id, + 'code' => $this->code, + 'name' => $this->name, + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + ]; + } +} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Resources/Core/Locale.php b/packages/Webkul/API/Http/Resources/Core/Locale.php new file mode 100644 index 000000000..21e5e4399 --- /dev/null +++ b/packages/Webkul/API/Http/Resources/Core/Locale.php @@ -0,0 +1,25 @@ + $this->id, + 'code' => $this->code, + 'name' => $this->name, + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + ]; + } +} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Resources/Core/Slider.php b/packages/Webkul/API/Http/Resources/Core/Slider.php new file mode 100644 index 000000000..fada15f9b --- /dev/null +++ b/packages/Webkul/API/Http/Resources/Core/Slider.php @@ -0,0 +1,24 @@ + $this->id, + 'title' => $this->title, + 'image_url' => $this->image_url, + 'content' => $this->content + ]; + } +} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Resources/Customer/Customer.php b/packages/Webkul/API/Http/Resources/Customer/Customer.php new file mode 100644 index 000000000..7e7a98485 --- /dev/null +++ b/packages/Webkul/API/Http/Resources/Customer/Customer.php @@ -0,0 +1,32 @@ + $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, + ]; + } +} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Resources/Customer/CustomerAddress.php b/packages/Webkul/API/Http/Resources/Customer/CustomerAddress.php new file mode 100644 index 000000000..40daa2301 --- /dev/null +++ b/packages/Webkul/API/Http/Resources/Customer/CustomerAddress.php @@ -0,0 +1,30 @@ + $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, + ]; + } +} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Resources/Customer/CustomerGroup.php b/packages/Webkul/API/Http/Resources/Customer/CustomerGroup.php new file mode 100644 index 000000000..80765deb2 --- /dev/null +++ b/packages/Webkul/API/Http/Resources/Customer/CustomerGroup.php @@ -0,0 +1,24 @@ + $this->id, + 'name' => $this->name, + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + ]; + } +} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Resources/Customer/Wishlist.php b/packages/Webkul/API/Http/Resources/Customer/Wishlist.php new file mode 100644 index 000000000..75b04de44 --- /dev/null +++ b/packages/Webkul/API/Http/Resources/Customer/Wishlist.php @@ -0,0 +1,25 @@ + $this->id, + 'product' => new ProductResource($this->product), + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + ]; + } +} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Resources/Inventory/InventorySource.php b/packages/Webkul/API/Http/Resources/Inventory/InventorySource.php new file mode 100644 index 000000000..fab464195 --- /dev/null +++ b/packages/Webkul/API/Http/Resources/Inventory/InventorySource.php @@ -0,0 +1,39 @@ + $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, + ]; + } +} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Resources/Sales/Invoice.php b/packages/Webkul/API/Http/Resources/Sales/Invoice.php new file mode 100644 index 000000000..10cdad74c --- /dev/null +++ b/packages/Webkul/API/Http/Resources/Sales/Invoice.php @@ -0,0 +1,40 @@ + $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), + ]; + } +} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Resources/Sales/InvoiceItem.php b/packages/Webkul/API/Http/Resources/Sales/InvoiceItem.php new file mode 100644 index 000000000..5c134645a --- /dev/null +++ b/packages/Webkul/API/Http/Resources/Sales/InvoiceItem.php @@ -0,0 +1,36 @@ + $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) + ]; + } +} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Resources/Sales/Order.php b/packages/Webkul/API/Http/Resources/Sales/Order.php new file mode 100644 index 000000000..59d7dff63 --- /dev/null +++ b/packages/Webkul/API/Http/Resources/Sales/Order.php @@ -0,0 +1,76 @@ + $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 + ]; + } +} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Resources/Sales/OrderAddress.php b/packages/Webkul/API/Http/Resources/Sales/OrderAddress.php new file mode 100644 index 000000000..a10733aa6 --- /dev/null +++ b/packages/Webkul/API/Http/Resources/Sales/OrderAddress.php @@ -0,0 +1,33 @@ + $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, + ]; + } +} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Resources/Sales/OrderItem.php b/packages/Webkul/API/Http/Resources/Sales/OrderItem.php new file mode 100644 index 000000000..9401ca817 --- /dev/null +++ b/packages/Webkul/API/Http/Resources/Sales/OrderItem.php @@ -0,0 +1,57 @@ + $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) + ]; + } +} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Resources/Sales/Shipment.php b/packages/Webkul/API/Http/Resources/Sales/Shipment.php new file mode 100644 index 000000000..6e9df69b1 --- /dev/null +++ b/packages/Webkul/API/Http/Resources/Sales/Shipment.php @@ -0,0 +1,33 @@ + $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), + ]; + } +} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Resources/Sales/ShipmentItem.php b/packages/Webkul/API/Http/Resources/Sales/ShipmentItem.php new file mode 100644 index 000000000..7c4436867 --- /dev/null +++ b/packages/Webkul/API/Http/Resources/Sales/ShipmentItem.php @@ -0,0 +1,33 @@ + $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) + ]; + } +} \ No newline at end of file diff --git a/packages/Webkul/API/Http/api.php b/packages/Webkul/API/Http/api.php deleted file mode 100755 index 0da15a760..000000000 --- a/packages/Webkul/API/Http/api.php +++ /dev/null @@ -1,76 +0,0 @@ - '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'); -}); \ No newline at end of file diff --git a/packages/Webkul/API/Http/routes.php b/packages/Webkul/API/Http/routes.php new file mode 100755 index 000000000..1b349596c --- /dev/null +++ b/packages/Webkul/API/Http/routes.php @@ -0,0 +1,175 @@ + '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' + ]); + }); +}); \ No newline at end of file diff --git a/packages/Webkul/API/Providers/APIServiceProvider.php b/packages/Webkul/API/Providers/APIServiceProvider.php index b5aa363f4..1d166f21a 100755 --- a/packages/Webkul/API/Providers/APIServiceProvider.php +++ b/packages/Webkul/API/Providers/APIServiceProvider.php @@ -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); - // }); } } diff --git a/packages/Webkul/Admin/src/Exceptions/Handler.php b/packages/Webkul/Admin/src/Exceptions/Handler.php index 90c2c6862..bb75160c1 100755 --- a/packages/Webkul/Admin/src/Exceptions/Handler.php +++ b/packages/Webkul/Admin/src/Exceptions/Handler.php @@ -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); } - } \ No newline at end of file