Added api for front shop
This commit is contained in:
parent
af8705d8e8
commit
a72d054cb5
|
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers\Shop;
|
||||
|
||||
use Webkul\Customer\Repositories\CustomerAddressRepository;
|
||||
use Webkul\API\Http\Resources\Customer\CustomerAddress as CustomerAddressResource;
|
||||
|
||||
/**
|
||||
* Address controller
|
||||
*
|
||||
* @author Jitendra Singh <jitendra@webkul.com>
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
class AddressController extends Controller
|
||||
{
|
||||
/**
|
||||
* Contains current guard
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guard;
|
||||
|
||||
/**
|
||||
* Contains route related configuration
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_config;
|
||||
|
||||
/**
|
||||
* CustomerAddressRepository object
|
||||
*
|
||||
* @var Object
|
||||
*/
|
||||
protected $customerAddressRepository;
|
||||
|
||||
/**
|
||||
* Controller instance
|
||||
*
|
||||
* @param Webkul\Customer\Repositories\CustomerAddressRepository $customerAddressRepository
|
||||
*/
|
||||
public function __construct(
|
||||
CustomerAddressRepository $customerAddressRepository
|
||||
)
|
||||
{
|
||||
$this->guard = request()->has('token') ? 'api' : 'customer';
|
||||
|
||||
auth()->setDefaultDriver($this->guard);
|
||||
|
||||
$this->middleware('auth:' . $this->guard);
|
||||
|
||||
$this->_config = request('_config');
|
||||
|
||||
$this->customerAddressRepository = $customerAddressRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store()
|
||||
{
|
||||
$customer = auth($this->guard)->user();
|
||||
|
||||
request()->merge([
|
||||
'address1' => implode(PHP_EOL, array_filter(request()->input('address1'))),
|
||||
'customer_id' => $customer->id
|
||||
]);
|
||||
|
||||
$this->validate(request(), [
|
||||
'address1' => 'string|required',
|
||||
'country' => 'string|required',
|
||||
'state' => 'string|required',
|
||||
'city' => 'string|required',
|
||||
'postcode' => 'required',
|
||||
'phone' => 'required'
|
||||
]);
|
||||
|
||||
$customerAddress = $this->customerAddressRepository->create(request()->all());
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Your address has been created successfully.',
|
||||
'data' => new CustomerAddressResource($customerAddress)
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
$customer = auth($this->guard)->user();
|
||||
|
||||
request()->merge(['address1' => implode(PHP_EOL, array_filter(request()->input('address1')))]);
|
||||
|
||||
$this->validate(request(), [
|
||||
'address1' => 'string|required',
|
||||
'country' => 'string|required',
|
||||
'state' => 'string|required',
|
||||
'city' => 'string|required',
|
||||
'postcode' => 'required',
|
||||
'phone' => 'required'
|
||||
]);
|
||||
|
||||
$this->customerAddressRepository->update(request()->all(), request()->input('id'));
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Your address has been updated successfully.',
|
||||
'data' => new CustomerAddressResource($this->customerAddressRepository->find(request()->input('id')))
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,214 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers\Shop;
|
||||
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Webkul\Checkout\Repositories\CartRepository;
|
||||
use Webkul\Checkout\Repositories\CartItemRepository;
|
||||
use Webkul\API\Http\Resources\Checkout\Cart as CartResource;
|
||||
use Cart;
|
||||
|
||||
/**
|
||||
* Cart controller
|
||||
*
|
||||
* @author Jitendra Singh <jitendra@webkul.com>
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
class CartController extends Controller
|
||||
{
|
||||
/**
|
||||
* Contains current guard
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guard;
|
||||
|
||||
/**
|
||||
* CartRepository object
|
||||
*
|
||||
* @var Object
|
||||
*/
|
||||
protected $cartRepository;
|
||||
|
||||
/**
|
||||
* CartItemRepository object
|
||||
*
|
||||
* @var Object
|
||||
*/
|
||||
protected $cartItemRepository;
|
||||
|
||||
/**
|
||||
* Controller instance
|
||||
*
|
||||
* @param Webkul\Checkout\Repositories\CartRepository $cartRepository
|
||||
* @param Webkul\Checkout\Repositories\CartItemRepository $cartItemRepository
|
||||
*/
|
||||
public function __construct(
|
||||
CartRepository $cartRepository,
|
||||
CartItemRepository $cartItemRepository
|
||||
)
|
||||
{
|
||||
$this->guard = request()->has('token') ? 'api' : 'customer';
|
||||
|
||||
auth()->setDefaultDriver($this->guard);
|
||||
|
||||
// $this->middleware('auth:' . $this->guard);
|
||||
|
||||
$this->_config = request('_config');
|
||||
|
||||
$this->cartRepository = $cartRepository;
|
||||
|
||||
$this->cartItemRepository = $cartItemRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get customer cart
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
$customer = auth($this->guard)->user();
|
||||
|
||||
$cart = Cart::getCart();
|
||||
|
||||
return response()->json([
|
||||
'data' => $cart ? new CartResource($cart) : null
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store($id)
|
||||
{
|
||||
Event::fire('checkout.cart.item.add.before', $id);
|
||||
|
||||
$result = Cart::add($id, request()->except('_token'));
|
||||
|
||||
if (! $result) {
|
||||
return response()->json([
|
||||
'error' => 'Something went wrong, please again later.'
|
||||
], 401);
|
||||
}
|
||||
|
||||
Event::fire('checkout.cart.item.add.after', $result);
|
||||
|
||||
Cart::collectTotals();
|
||||
|
||||
$cart = Cart::getCart();
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Product added to cart successfully.',
|
||||
'data' => $cart ? new CartResource($cart) : null
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
foreach (request()->get('qty') as$qty) {
|
||||
if ($qty <= 0) {
|
||||
return response()->json([
|
||||
'message' => trans('shop::app.checkout.cart.quantity.illegal')
|
||||
], 401);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (request()->get('qty') as $itemId => $qty) {
|
||||
$item = $this->cartItemRepository->findOneByField('id', $itemId);
|
||||
|
||||
Event::fire('checkout.cart.item.update.before', $itemId);
|
||||
|
||||
Cart::updateItem($item->product_id, ['quantity' => $qty], $itemId);
|
||||
|
||||
Event::fire('checkout.cart.item.update.after', $item);
|
||||
}
|
||||
|
||||
Cart::collectTotals();
|
||||
|
||||
$cart = Cart::getCart();
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Cart updated successfully.',
|
||||
'data' => $cart ? new CartResource($cart) : null
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy()
|
||||
{
|
||||
Event::fire('checkout.cart.delete.before');
|
||||
|
||||
Cart::deActivateCart();
|
||||
|
||||
Event::fire('checkout.cart.delete.after');
|
||||
|
||||
$cart = Cart::getCart();
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Cart removed successfully.',
|
||||
'data' => $cart ? new CartResource($cart) : null
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroyItem($id)
|
||||
{
|
||||
Event::fire('checkout.cart.item.delete.before', $id);
|
||||
|
||||
Cart::removeItem($id);
|
||||
|
||||
Event::fire('checkout.cart.item.delete.after', $id);
|
||||
|
||||
Cart::collectTotals();
|
||||
|
||||
$cart = Cart::getCart();
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Cart removed successfully.',
|
||||
'data' => $cart ? new CartResource($cart) : null
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to move a already added product to wishlist
|
||||
* will run only on customer authentication.
|
||||
*
|
||||
* @param instance cartItem $id
|
||||
*/
|
||||
public function moveToWishlist($id)
|
||||
{
|
||||
Event::fire('checkout.cart.item.move-to-wishlist.before', $id);
|
||||
|
||||
Cart::moveToWishlist($id);
|
||||
|
||||
Event::fire('checkout.cart.item.move-to-wishlist.after', $id);
|
||||
|
||||
Cart::collectTotals();
|
||||
|
||||
$cart = Cart::getCart();
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Cart item moved to wishlist successfully.',
|
||||
'data' => $cart ? new CartResource($cart) : null
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,6 @@
|
|||
namespace Webkul\API\Http\Controllers\Shop;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Webkul\Category\Repositories\CategoryRepository;
|
||||
use Webkul\API\Http\Resources\Catalog\Category as CategoryResource;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,220 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers\Shop;
|
||||
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Webkul\Checkout\Repositories\CartRepository;
|
||||
use Webkul\Checkout\Repositories\CartItemRepository;
|
||||
use Webkul\Shipping\Facades\Shipping;
|
||||
use Webkul\Payment\Facades\Payment;
|
||||
use Webkul\API\Http\Resources\Checkout\Cart as CartResource;
|
||||
use Webkul\API\Http\Resources\Checkout\CartShippingRate as CartShippingRateResource;
|
||||
use Webkul\API\Http\Resources\Sales\Order as OrderResource;
|
||||
use Webkul\Checkout\Http\Requests\CustomerAddressForm;
|
||||
use Webkul\Sales\Repositories\OrderRepository;
|
||||
use Cart;
|
||||
|
||||
/**
|
||||
* Checkout controller
|
||||
*
|
||||
* @author Jitendra Singh <jitendra@webkul.com>
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
class CheckoutController extends Controller
|
||||
{
|
||||
/**
|
||||
* Contains current guard
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guard;
|
||||
|
||||
/**
|
||||
* CartRepository object
|
||||
*
|
||||
* @var Object
|
||||
*/
|
||||
protected $cartRepository;
|
||||
|
||||
/**
|
||||
* CartItemRepository object
|
||||
*
|
||||
* @var Object
|
||||
*/
|
||||
protected $cartItemRepository;
|
||||
|
||||
/**
|
||||
* Controller instance
|
||||
*
|
||||
* @param Webkul\Checkout\Repositories\CartRepository $cartRepository
|
||||
* @param Webkul\Checkout\Repositories\CartItemRepository $cartItemRepository
|
||||
* @param Webkul\Sales\Repositories\OrderRepository $orderRepository
|
||||
*/
|
||||
public function __construct(
|
||||
CartRepository $cartRepository,
|
||||
CartItemRepository $cartItemRepository,
|
||||
OrderRepository $orderRepository
|
||||
)
|
||||
{
|
||||
$this->guard = request()->has('token') ? 'api' : 'customer';
|
||||
|
||||
auth()->setDefaultDriver($this->guard);
|
||||
|
||||
|
||||
// $this->middleware('auth:' . $this->guard);
|
||||
|
||||
$this->_config = request('_config');
|
||||
|
||||
$this->cartRepository = $cartRepository;
|
||||
|
||||
$this->cartItemRepository = $cartItemRepository;
|
||||
|
||||
$this->orderRepository = $orderRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves customer address.
|
||||
*
|
||||
* @param \Webkul\Checkout\Http\Requests\CustomerAddressForm $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function saveAddress(CustomerAddressForm $request)
|
||||
{
|
||||
$data = request()->all();
|
||||
|
||||
$data['billing']['address1'] = implode(PHP_EOL, array_filter($data['billing']['address1']));
|
||||
$data['shipping']['address1'] = implode(PHP_EOL, array_filter($data['shipping']['address1']));
|
||||
|
||||
if (isset($data['billing']['id']) && str_contains($data['billing']['id'], 'address_')) {
|
||||
unset($data['billing']['id']);
|
||||
unset($data['billing']['address_id']);
|
||||
}
|
||||
|
||||
if (isset($data['shipping']['id']) && str_contains($data['shipping']['id'], 'address_')) {
|
||||
unset($data['shipping']['id']);
|
||||
unset($data['shipping']['address_id']);
|
||||
}
|
||||
|
||||
|
||||
if (Cart::hasError() || ! Cart::saveCustomerAddress($data) || ! Shipping::collectRates())
|
||||
abort(400);
|
||||
|
||||
$rates = [];
|
||||
|
||||
foreach (Shipping::getGroupedAllShippingRates() as $code => $shippingMethod) {
|
||||
$rates[] = [
|
||||
'carrier_title' => $shippingMethod['carrier_title'],
|
||||
'rates' => CartShippingRateResource::collection(collect($shippingMethod['rates']))
|
||||
];
|
||||
}
|
||||
|
||||
Cart::collectTotals();
|
||||
|
||||
return response()->json([
|
||||
'data' => [
|
||||
'rates' => $rates,
|
||||
'cart' => new CartResource(Cart::getCart())
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves shipping method.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function saveShipping()
|
||||
{
|
||||
$shippingMethod = request()->get('shipping_method');
|
||||
|
||||
if (Cart::hasError() || !$shippingMethod || ! Cart::saveShippingMethod($shippingMethod))
|
||||
abort(400);
|
||||
|
||||
Cart::collectTotals();
|
||||
|
||||
return response()->json([
|
||||
'data' => [
|
||||
'methods' => Payment::getPaymentMethods(),
|
||||
'cart' => new CartResource(Cart::getCart())
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves payment method.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function savePayment()
|
||||
{
|
||||
$payment = request()->get('payment');
|
||||
|
||||
if (Cart::hasError() || ! $payment || ! Cart::savePaymentMethod($payment))
|
||||
abort(400);
|
||||
|
||||
return response()->json([
|
||||
'data' => [
|
||||
'cart' => new CartResource(Cart::getCart())
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves order.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function saveOrder()
|
||||
{
|
||||
if (Cart::hasError())
|
||||
abort(400);
|
||||
|
||||
Cart::collectTotals();
|
||||
|
||||
$this->validateOrder();
|
||||
|
||||
$cart = Cart::getCart();
|
||||
|
||||
if ($redirectUrl = Payment::getRedirectUrl($cart)) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'redirect_url' => $redirectUrl
|
||||
]);
|
||||
}
|
||||
|
||||
$order = $this->orderRepository->create(Cart::prepareDataForOrder());
|
||||
|
||||
Cart::deActivateCart();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'order' => new OrderResource($order),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate order before creation
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function validateOrder()
|
||||
{
|
||||
$cart = Cart::getCart();
|
||||
|
||||
if (! $cart->shipping_address) {
|
||||
throw new \Exception(trans('Please check shipping address.'));
|
||||
}
|
||||
|
||||
if (! $cart->billing_address) {
|
||||
throw new \Exception(trans('Please check billing address.'));
|
||||
}
|
||||
|
||||
if (! $cart->selected_shipping_rate) {
|
||||
throw new \Exception(trans('Please specify shipping method.'));
|
||||
}
|
||||
|
||||
if (! $cart->payment) {
|
||||
throw new \Exception(trans('Please specify payment method.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,6 @@
|
|||
namespace Webkul\API\Http\Controllers\Shop;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
/**
|
||||
* Core controller
|
||||
|
|
@ -13,6 +12,36 @@ use Illuminate\Http\Response;
|
|||
*/
|
||||
class CoreController extends Controller
|
||||
{
|
||||
/**
|
||||
* Returns a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
$configValues = [];
|
||||
|
||||
foreach (explode(',', request()->input('_config')) as $config) {
|
||||
$configValues[$config] = core()->getConfigData($config);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'data' => $configValues
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function getCountryStateGroup()
|
||||
{
|
||||
return response()->json([
|
||||
'data' => core()->groupedStatesByCountries()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a listing of the resource.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers\Shop;
|
||||
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Webkul\Customer\Repositories\CustomerRepository;
|
||||
|
||||
/**
|
||||
* Customer controller
|
||||
*
|
||||
* @author Jitendra Singh <jitendra@webkul.com>
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
class CustomerController extends Controller
|
||||
{
|
||||
/**
|
||||
* Contains route related configuration
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_config;
|
||||
|
||||
/**
|
||||
* Repository object
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $customerRepository;
|
||||
|
||||
/**
|
||||
* @param CustomerRepository object $customer
|
||||
*/
|
||||
public function __construct(CustomerRepository $customerRepository)
|
||||
{
|
||||
$this->_config = request('_config');
|
||||
|
||||
$this->customerRepository = $customerRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to store user's sign up form data to DB.
|
||||
*
|
||||
* @return Mixed
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
request()->validate([
|
||||
'first_name' => 'required',
|
||||
'last_name' => 'required',
|
||||
'email' => 'email|required|unique:customers,email',
|
||||
'password' => 'confirmed|min:6|required'
|
||||
]);
|
||||
|
||||
$data = request()->input();
|
||||
|
||||
$data = array_merge($data, [
|
||||
'password' => bcrypt($data['password']),
|
||||
'channel_id' => core()->getCurrentChannel()->id,
|
||||
'is_verified' => 1,
|
||||
'customer_group_id' => 1
|
||||
]);
|
||||
|
||||
Event::fire('customer.registration.before');
|
||||
|
||||
$customer = $this->customerRepository->create($data);
|
||||
|
||||
Event::fire('customer.registration.after', $customer);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Your account has been created successfully.'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -30,8 +30,6 @@ class ProductController extends Controller
|
|||
*/
|
||||
public function __construct(ProductRepository $productRepository)
|
||||
{
|
||||
// $this->middleware('auth:api');
|
||||
|
||||
$this->productRepository = $productRepository;
|
||||
}
|
||||
|
||||
|
|
@ -42,7 +40,7 @@ class ProductController extends Controller
|
|||
*/
|
||||
public function index()
|
||||
{
|
||||
return ProductResource::collection($this->productRepository->getAll());
|
||||
return ProductResource::collection($this->productRepository->getAll(request()->input('category_id')));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -56,4 +54,28 @@ class ProductController extends Controller
|
|||
$this->productRepository->findOrFail($id)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns product's additional information.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function additionalInformation($id)
|
||||
{
|
||||
return response()->json([
|
||||
'data' => app('Webkul\Product\Helpers\View')->getAdditionalData($this->productRepository->findOrFail($id))
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns product's additional information.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function configurableConfig($id)
|
||||
{
|
||||
return response()->json([
|
||||
'data' => app('Webkul\Product\Helpers\ConfigurableOption')->getConfigurationConfig($this->productRepository->findOrFail($id))
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
namespace Webkul\API\Http\Controllers\Shop;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
/**
|
||||
* Resource Controller
|
||||
|
|
@ -13,6 +12,13 @@ use Illuminate\Http\Response;
|
|||
*/
|
||||
class ResourceController extends Controller
|
||||
{
|
||||
/**
|
||||
* Contains current guard
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guard;
|
||||
|
||||
/**
|
||||
* Contains route related configuration
|
||||
*
|
||||
|
|
@ -34,10 +40,17 @@ class ResourceController extends Controller
|
|||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// $this->middleware('auth:api');
|
||||
$this->guard = request()->has('token') ? 'api' : 'customer';
|
||||
|
||||
$this->_config = request('_config');
|
||||
|
||||
if (isset($this->_config['authorization_required']) && $this->_config['authorization_required']) {
|
||||
|
||||
auth()->setDefaultDriver($this->guard);
|
||||
|
||||
$this->middleware('auth:' . $this->guard);
|
||||
}
|
||||
|
||||
$this->repository = app($this->_config['repository']);
|
||||
}
|
||||
|
||||
|
|
@ -49,12 +62,14 @@ class ResourceController extends Controller
|
|||
public function index()
|
||||
{
|
||||
$query = $this->repository->scopeQuery(function($query) {
|
||||
foreach (request()->except(['page', 'limit', 'pagination', 'sort', 'order']) as $input => $value) {
|
||||
$query = $query->where($input, $value);
|
||||
foreach (request()->except(['page', 'limit', 'pagination', 'sort', 'order', 'token']) as $input => $value) {
|
||||
$query = $query->whereIn($input, array_map('trim', explode(',', $value)));
|
||||
}
|
||||
|
||||
if ($sort = request()->input('sort')) {
|
||||
$query = $query->orderBy($sort, request()->input('order') ?? 'desc');
|
||||
} else {
|
||||
$query = $query->orderBy('id', 'desc');
|
||||
}
|
||||
|
||||
return $query;
|
||||
|
|
@ -80,4 +95,20 @@ class ResourceController extends Controller
|
|||
$this->repository->findOrFail($id)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete's a individual resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$wishlistProduct = $this->repository->findOrFail($id);
|
||||
|
||||
$this->repository->delete($id);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Item removed successfully.'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers\Shop;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Webkul\Product\Repositories\ProductReviewRepository;
|
||||
use Webkul\API\Http\Resources\Catalog\ProductReview as ProductReviewResource;
|
||||
|
||||
/**
|
||||
* Review controller
|
||||
*
|
||||
* @author Jitendra Singh <jitendra@webkul.com>
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
class ReviewController extends Controller
|
||||
{
|
||||
/**
|
||||
* Contains current guard
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guard;
|
||||
|
||||
/**
|
||||
* ProductReviewRepository object
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $reviewRepository;
|
||||
|
||||
/**
|
||||
* Controller instance
|
||||
*
|
||||
* @param Webkul\Product\Repositories\ProductReviewRepository $reviewRepository
|
||||
*/
|
||||
public function __construct(ProductReviewRepository $reviewRepository)
|
||||
{
|
||||
$this->guard = request()->has('token') ? 'api' : 'customer';
|
||||
|
||||
auth()->setDefaultDriver($this->guard);
|
||||
|
||||
$this->reviewRepository = $reviewRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request, $id)
|
||||
{
|
||||
$customer = auth($this->guard)->user();
|
||||
|
||||
$this->validate(request(), [
|
||||
'comment' => 'required',
|
||||
'rating' => 'required|numeric|min:1|max:5',
|
||||
'title' => 'required',
|
||||
]);
|
||||
|
||||
$data = array_merge(request()->all(), [
|
||||
'customer_id' => $customer ? $customer->id : null,
|
||||
'name' => $customer ? $customer->name : request()->input('name'),
|
||||
'status' => 'pending',
|
||||
'product_id' => $id
|
||||
]);
|
||||
|
||||
$productReview = $this->reviewRepository->create($data);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Your review submitted successfully.',
|
||||
'data' => new ProductReviewResource($this->reviewRepository->find($productReview->id))
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,145 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers\Shop;
|
||||
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Webkul\Customer\Repositories\CustomerRepository;
|
||||
use Webkul\API\Http\Resources\Customer\Customer as CustomerResource;
|
||||
|
||||
/**
|
||||
* Session controller
|
||||
*
|
||||
* @author Jitendra Singh <jitendra@webkul.com>
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
class SessionController extends Controller
|
||||
{
|
||||
/**
|
||||
* Contains current guard
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guard;
|
||||
|
||||
/**
|
||||
* Contains route related configuration
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_config;
|
||||
|
||||
/**
|
||||
* Controller instance
|
||||
*
|
||||
* @param Webkul\Customer\Repositories\CustomerRepository $customerRepository
|
||||
*/
|
||||
public function __construct(CustomerRepository $customerRepository)
|
||||
{
|
||||
$this->guard = request()->has('token') ? 'api' : 'customer';
|
||||
|
||||
auth()->setDefaultDriver($this->guard);
|
||||
|
||||
$this->middleware('auth:' . $this->guard, ['only' => ['get', 'update', 'destroy']]);
|
||||
|
||||
$this->_config = request('_config');
|
||||
|
||||
$this->customerRepository = $customerRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to store user's sign up form data to DB.
|
||||
*
|
||||
* @return Mixed
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
request()->validate([
|
||||
'email' => 'required|email',
|
||||
'password' => 'required'
|
||||
]);
|
||||
|
||||
$jwtToken = null;
|
||||
|
||||
if (! $jwtToken = auth()->guard($this->guard)->attempt(request()->only('email', 'password'))) {
|
||||
return response()->json([
|
||||
'error' => 'Invalid Email or Password',
|
||||
], 401);
|
||||
}
|
||||
|
||||
Event::fire('customer.after.login', request()->input('email'));
|
||||
|
||||
$customer = auth($this->guard)->user();
|
||||
|
||||
return response()->json([
|
||||
'token' => $jwtToken,
|
||||
'message' => 'Logged in successfully.',
|
||||
'data' => new CustomerResource($customer)
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get details for current logged in customer
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
$customer = auth($this->guard)->user();
|
||||
|
||||
return response()->json([
|
||||
'data' => new CustomerResource($customer)
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
$customer = auth($this->guard)->user();
|
||||
|
||||
$this->validate(request(), [
|
||||
'first_name' => 'required',
|
||||
'last_name' => 'required',
|
||||
'gender' => 'required',
|
||||
'date_of_birth' => 'nullable|date|before:today',
|
||||
'email' => 'email|unique:customers,email,' . $customer->id,
|
||||
'password' => 'confirmed|min:6'
|
||||
]);
|
||||
|
||||
$data = request()->all();
|
||||
|
||||
if (! $data['date_of_birth']) {
|
||||
unset($data['date_of_birth']);
|
||||
}
|
||||
|
||||
if (!isset($data['password']) || ! $data['password']) {
|
||||
unset($data['password']);
|
||||
} else {
|
||||
$data['password'] = bcrypt($data['password']);
|
||||
}
|
||||
|
||||
$this->customerRepository->update($data, $customer->id);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Your account has been created successfully.',
|
||||
'data' => new CustomerResource($this->customerRepository->find($customer->id))
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy()
|
||||
{
|
||||
auth()->guard($this->guard)->logout();
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Logged out successfully.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,135 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers\Shop;
|
||||
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Webkul\Customer\Repositories\WishlistRepository;
|
||||
use Webkul\Product\Repositories\ProductRepository;
|
||||
use Webkul\API\Http\Resources\Customer\Wishlist as WishlistResource;
|
||||
use Cart;
|
||||
|
||||
/**
|
||||
* Wishlist controller
|
||||
*
|
||||
* @author Jitendra Singh <jitendra@webkul.com>
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
class WishlistController extends Controller
|
||||
{
|
||||
/**
|
||||
* WishlistRepository object
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $wishlistRepository;
|
||||
|
||||
/**
|
||||
* ProductRepository object
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $productRepository;
|
||||
|
||||
/**
|
||||
* @param Webkul\Customer\Repositories\WishlistRepository $wishlistRepository
|
||||
* @param Webkul\Product\Repositories\ProductRepository $productRepository
|
||||
*/
|
||||
public function __construct(
|
||||
WishlistRepository $wishlistRepository,
|
||||
ProductRepository $productRepository
|
||||
)
|
||||
{
|
||||
$this->guard = request()->has('token') ? 'api' : 'customer';
|
||||
|
||||
auth()->setDefaultDriver($this->guard);
|
||||
|
||||
$this->middleware('auth:' . $this->guard);
|
||||
|
||||
$this->wishlistRepository = $wishlistRepository;
|
||||
|
||||
$this->productRepository = $productRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to add item to the wishlist.
|
||||
*
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create($id)
|
||||
{
|
||||
$product = $this->productRepository->findOrFail($id);
|
||||
|
||||
$customer = auth()->guard($this->guard)->user();
|
||||
|
||||
$wishlistItem = $this->wishlistRepository->findOneWhere([
|
||||
'channel_id' => core()->getCurrentChannel()->id,
|
||||
'product_id' => $id,
|
||||
'customer_id' => $customer->id
|
||||
]);
|
||||
|
||||
if (! $wishlistItem) {
|
||||
$wishlistItem = $this->wishlistRepository->create([
|
||||
'channel_id' => core()->getCurrentChannel()->id,
|
||||
'product_id' => $id,
|
||||
'customer_id' => $customer->id
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'data' => new WishlistResource($wishlistItem),
|
||||
'message' => trans('customer::app.wishlist.success')
|
||||
]);
|
||||
} else {
|
||||
$this->wishlistRepository->delete($wishlistItem->id);
|
||||
|
||||
return response()->json([
|
||||
'data' => null,
|
||||
'message' => 'Item removed from wishlist successfully.'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Move product from wishlist to cart.
|
||||
*
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function moveToCart($id)
|
||||
{
|
||||
$wishlistItem = $this->wishlistRepository->findOrFail($id);
|
||||
|
||||
if ($wishlistItem->customer_id != auth()->guard($this->guard)->user()->id)
|
||||
return response()->json([
|
||||
'message' => trans('shop::app.security-warning')
|
||||
], 400);
|
||||
|
||||
$result = Cart::moveToCart($wishlistItem);
|
||||
|
||||
if ($result == 1) {
|
||||
if ($wishlistItem->delete()) {
|
||||
Cart::collectTotals();
|
||||
|
||||
return response()->json([
|
||||
'data' => 1,
|
||||
'message' => trans('shop::app.wishlist.moved')
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'data' => 1,
|
||||
'error' => trans('shop::app.wishlist.move-error')
|
||||
], 400);
|
||||
}
|
||||
} else if ($result == 0) {
|
||||
return response()->json([
|
||||
'data' => 0,
|
||||
'error' => trans('shop::app.wishlist.error')
|
||||
], 400);
|
||||
} else if ($result == -1) {
|
||||
return response()->json([
|
||||
'data' => -1,
|
||||
'error' => trans('shop::app.checkout.cart.add-config-warning')
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -17,6 +17,7 @@ class Attribute extends JsonResource
|
|||
return [
|
||||
'id' => $this->id,
|
||||
'code' => $this->code,
|
||||
'type' => $this->type,
|
||||
'name' => $this->name,
|
||||
'swatch_type' => $this->swatch_type,
|
||||
'options' => AttributeOption::collection($this->options),
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ class Category extends JsonResource
|
|||
'code' => $this->code,
|
||||
'name' => $this->name,
|
||||
'slug' => $this->slug,
|
||||
'display_mode' => $this->display_mode,
|
||||
'description' => $this->description,
|
||||
'meta_title' => $this->meta_title,
|
||||
'meta_description' => $this->meta_description,
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ class Product extends JsonResource
|
|||
|
||||
$this->productImageHelper = app('Webkul\Product\Helpers\ProductImage');
|
||||
|
||||
$this->productReviewHelper = app('Webkul\Product\Helpers\Review');
|
||||
|
||||
parent::__construct($resource);
|
||||
}
|
||||
|
||||
|
|
@ -34,14 +36,15 @@ class Product extends JsonResource
|
|||
'id' => $product->id,
|
||||
'type' => $product->type,
|
||||
'name' => $this->name,
|
||||
'price' => $this->price,
|
||||
'formated_price' => core()->currency($this->price),
|
||||
'price' => $product->type == 'configurable' ? $this->productPriceHelper->getVariantMinPrice($product) : $this->price,
|
||||
'formated_price' => $product->type == 'configurable' ? core()->currency($this->productPriceHelper->getVariantMinPrice($product)) : core()->currency($this->price),
|
||||
'short_description' => $this->short_description,
|
||||
'description' => $this->description,
|
||||
'sku' => $this->sku,
|
||||
'images' => ProductImage::collection($product->images),
|
||||
'base_image' => $this->productImageHelper->getProductBaseImage($product),
|
||||
'variants' => Self::collection($this->variants),
|
||||
'in_stock' => $product->haveSufficientQuantity(1),
|
||||
'in_stock' => $product->type == 'configurable' ? 1 : $product->haveSufficientQuantity(1),
|
||||
$this->mergeWhen($product->type == 'configurable', [
|
||||
'super_attributes' => Attribute::collection($product->super_attributes),
|
||||
]),
|
||||
|
|
@ -53,6 +56,13 @@ class Product extends JsonResource
|
|||
$this->productPriceHelper->haveSpecialPrice($product),
|
||||
core()->currency($this->productPriceHelper->getSpecialPrice($product))
|
||||
),
|
||||
'reviews' => [
|
||||
'total' => $total = $this->productReviewHelper->getTotalReviews($product),
|
||||
'total_rating' => $total ? $this->productReviewHelper->getTotalRating($product) : 0,
|
||||
'average_rating' => $total ? $this->productReviewHelper->getAverageRating($product) : 0,
|
||||
'percentage' => $total ? json_encode($this->productReviewHelper->getPercentageRating($product)) : [],
|
||||
],
|
||||
'is_saved' => false,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ class ProductImage extends JsonResource
|
|||
'id' => $this->id,
|
||||
'path' => $this->path,
|
||||
'url' => $this->url,
|
||||
'original_image_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)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class ProductReview extends JsonResource
|
|||
return [
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'rating' => $this->rating,
|
||||
'rating' => number_format($this->rating, 1, '.', ''),
|
||||
'comment' => $this->comment,
|
||||
'name' => $this->name,
|
||||
'status' => $this->status,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Checkout;
|
||||
|
||||
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 Cart extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'customer_email' => $this->customer_email,
|
||||
'customer_first_name' => $this->customer_first_name,
|
||||
'customer_last_name' => $this->customer_last_name,
|
||||
'shipping_method' => $this->shipping_method,
|
||||
'coupon_code' => $this->coupon_code,
|
||||
'is_gift' => $this->is_gift,
|
||||
'items_count' => $this->items_count,
|
||||
'items_qty' => $this->items_qty,
|
||||
'exchange_rate' => $this->exchange_rate,
|
||||
'global_currency_code' => $this->global_currency_code,
|
||||
'base_currency_code' => $this->base_currency_code,
|
||||
'channel_currency_code' => $this->channel_currency_code,
|
||||
'cart_currency_code' => $this->cart_currency_code,
|
||||
'grand_total' => $this->grand_total,
|
||||
'formated_grand_total' => core()->formatPrice($this->grand_total, $this->cart_currency_code),
|
||||
'base_grand_total' => $this->base_grand_total,
|
||||
'formated_base_grand_total' => core()->formatBasePrice($this->base_grand_total),
|
||||
'sub_total' => $this->sub_total,
|
||||
'formated_sub_total' => core()->formatPrice($this->sub_total, $this->cart_currency_code),
|
||||
'base_sub_total' => $this->base_sub_total,
|
||||
'formated_base_sub_total' => core()->formatBasePrice($this->base_sub_total),
|
||||
'tax_total' => $this->tax_total,
|
||||
'formated_tax_total' => core()->formatPrice($this->tax_total, $this->cart_currency_code),
|
||||
'base_tax_total' => $this->base_tax_total,
|
||||
'formated_base_tax_total' => core()->formatBasePrice($this->base_tax_total),
|
||||
'discount' => $this->discount,
|
||||
'formated_discount' => core()->formatPrice($this->discount, $this->cart_currency_code),
|
||||
'base_discount' => $this->base_discount,
|
||||
'formated_base_discount' => core()->formatBasePrice($this->base_discount),
|
||||
'checkout_method' => $this->checkout_method,
|
||||
'is_guest' => $this->is_guest,
|
||||
'is_active' => $this->is_active,
|
||||
'conversion_time' => $this->conversion_time,
|
||||
'customer' => $this->when($this->customer_id, new CustomerResource($this->customer)),
|
||||
'channel' => $this->when($this->channel_id, new ChannelResource($this->channel)),
|
||||
'items' => CartItem::collection($this->items),
|
||||
'selected_shipping_rate' => new CartShippingRate($this->selected_shipping_rate),
|
||||
'payment' => new CartPayment($this->payment),
|
||||
'billing_address' => new CartAddress($this->billing_address),
|
||||
'shipping_address' => new CartAddress($this->shipping_address),
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Checkout;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class CartAddress extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'first_name' => $this->first_name,
|
||||
'last_name' => $this->last_name,
|
||||
'name' => $this->name,
|
||||
'email' => $this->email,
|
||||
'address1' => explode(PHP_EOL, $this->address1),
|
||||
'country' => $this->country,
|
||||
'country_name' => country()->name($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\Checkout;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Webkul\API\Http\Resources\Catalog\Product as ProductResource;
|
||||
|
||||
class CartItem extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'quantity' => $this->quantity,
|
||||
'sku' => $this->sku,
|
||||
'type' => $this->type,
|
||||
'name' => $this->name,
|
||||
'coupon_code' => $this->coupon_code,
|
||||
'weight' => $this->weight,
|
||||
'total_weight' => $this->total_weight,
|
||||
'base_total_weight' => $this->base_total_weight,
|
||||
'price' => $this->price,
|
||||
'formated_price' => core()->formatPrice($this->price, $this->cart->cart_currency_code),
|
||||
'base_price' => $this->base_price,
|
||||
'formated_base_price' => core()->formatBasePrice($this->base_price),
|
||||
'custom_price' => $this->custom_price,
|
||||
'formated_custom_price' => core()->formatPrice($this->custom_price, $this->cart->cart_currency_code),
|
||||
'total' => $this->total,
|
||||
'formated_total' => core()->formatPrice($this->total, $this->cart->cart_currency_code),
|
||||
'base_total' => $this->base_total,
|
||||
'formated_base_total' => core()->formatBasePrice($this->base_total),
|
||||
'tax_percent' => $this->tax_percent,
|
||||
'tax_amount' => $this->tax_amount,
|
||||
'formated_tax_amount' => core()->formatPrice($this->tax_amount, $this->cart->cart_currency_code),
|
||||
'base_tax_amount' => $this->base_tax_amount,
|
||||
'formated_base_tax_amount' => core()->formatBasePrice($this->base_tax_amount),
|
||||
'discount_percent' => $this->discount_percent,
|
||||
'discount_amount' => $this->discount_amount,
|
||||
'formated_discount_amount' => core()->formatPrice($this->discount_amount, $this->cart->cart_currency_code),
|
||||
'base_discount_amount' => $this->base_discount_amount,
|
||||
'formated_base_discount_amount' => core()->formatBasePrice($this->base_discount_amount),
|
||||
'additional' => is_array($this->resource->additional)
|
||||
? $this->resource->additional
|
||||
: json_decode($this->resource->additional, true),
|
||||
'child' => new self($this->child),
|
||||
'product' => $this->when($this->product_id, new ProductResource($this->product)),
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Checkout;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class CartPayment extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'method' => $this->method,
|
||||
'method_title' => core()->getConfigData('sales.paymentmethods.' . $this->method . '.title'),
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Checkout;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Cart;
|
||||
|
||||
class CartShippingRate extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$cart = Cart::getCart();
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'carrier' => $this->carrier,
|
||||
'carrier_title' => $this->carrier_title,
|
||||
'method' => $this->method,
|
||||
'method_title' => $this->method_title,
|
||||
'method_description' => $this->method_description,
|
||||
'price' => $this->price,
|
||||
'formated_price' => core()->formatPrice($this->price, $cart->cart_currency_code),
|
||||
'base_price' => $this->base_price,
|
||||
'formated_base_price' => core()->formatBasePrice($this->base_price),
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Core;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class Country 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
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -16,9 +16,9 @@ class CustomerAddress extends JsonResource
|
|||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'address1' => $this->address1,
|
||||
'address2' => $this->address2,
|
||||
'address1' => explode(PHP_EOL, $this->address1),
|
||||
'country' => $this->country,
|
||||
'country_name' => country()->name($this->country),
|
||||
'state' => $this->state,
|
||||
'city' => $this->city,
|
||||
'postcode' => $this->postcode,
|
||||
|
|
|
|||
|
|
@ -23,18 +23,29 @@ class Invoice extends JsonResource
|
|||
'channel_currency_code' => $this->channel_currency_code,
|
||||
'order_currency_code' => $this->order_currency_code,
|
||||
'sub_total' => $this->sub_total,
|
||||
'formated_sub_total' => core()->formatPrice($this->sub_total, $this->order_currency_code),
|
||||
'base_sub_total' => $this->base_sub_total,
|
||||
'formated_base_sub_total' => core()->formatBasePrice($this->base_sub_total),
|
||||
'grand_total' => $this->grand_total,
|
||||
'formated_grand_total' => core()->formatPrice($this->grand_total, $this->order_currency_code),
|
||||
'base_grand_total' => $this->base_grand_total,
|
||||
'formated_base_grand_total' => core()->formatBasePrice($this->base_grand_total),
|
||||
'shipping_amount' => $this->shipping_amount,
|
||||
'formated_shipping_amount' => core()->formatPrice($this->shipping_amount, $this->order_currency_code),
|
||||
'base_shipping_amount' => $this->base_shipping_amount,
|
||||
'formated_base_shipping_amount' => core()->formatBasePrice($this->base_shipping_amount),
|
||||
'tax_amount' => $this->tax_amount,
|
||||
'formated_tax_amount' => core()->formatPrice($this->tax_amount, $this->order_currency_code),
|
||||
'base_tax_amount' => $this->base_tax_amount,
|
||||
'formated_base_tax_amount' => core()->formatBasePrice($this->base_tax_amount),
|
||||
'discount_amount' => $this->discount_amount,
|
||||
'formated_discount_amount' => core()->formatPrice($this->discount_amount, $this->order_currency_code),
|
||||
'base_discount_amount' => $this->base_discount_amount,
|
||||
'formated_base_discount_amount' => core()->formatBasePrice($this->base_discount_amount),
|
||||
'order_address' => new OrderAddress($this->address),
|
||||
'transaction_id' => $this->transaction_id,
|
||||
'items' => InvoiceItem::collection($this->items),
|
||||
'created_at' => $this->created_at
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -17,16 +17,27 @@ class InvoiceItem extends JsonResource
|
|||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
// 'product' => $this->when($this->product, new ProductResource($this->product)),
|
||||
'description' => $this->description,
|
||||
'sku' => $this->sku,
|
||||
'description' => $this->description,
|
||||
'qty' => $this->qty,
|
||||
'price' => $this->price,
|
||||
'formated_price' => core()->formatPrice($this->price, $this->invoice->order_currency_code),
|
||||
'base_price' => $this->base_price,
|
||||
'formated_base_price' => core()->formatBasePrice($this->base_price),
|
||||
'total' => $this->total,
|
||||
'formated_total' => core()->formatPrice($this->total, $this->invoice->order_currency_code),
|
||||
'base_total' => $this->base_total,
|
||||
'formated_base_total' => core()->formatBasePrice($this->base_total),
|
||||
'tax_amount' => $this->tax_amount,
|
||||
'formated_tax_amount' => core()->formatPrice($this->tax_amount, $this->invoice->order_currency_code),
|
||||
'base_tax_amount' => $this->base_tax_amount,
|
||||
'formated_base_tax_amount' => core()->formatBasePrice($this->base_tax_amount),
|
||||
'grand_total' => $this->total + $this->tax_amount,
|
||||
'formated_grand_total' => core()->formatPrice($this->total + $this->tax_amount, $this->invoice->order_currency_code),
|
||||
'base_grand_total' => $this->base_total + $this->base_tax_amount,
|
||||
'formated_base_grand_total' => core()->formatBasePrice($this->base_total + $this->base_tax_amount),
|
||||
'additional' => is_array($this->resource->additional)
|
||||
? $this->resource->additional
|
||||
: json_decode($this->resource->additional, true),
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ class Order extends JsonResource
|
|||
return [
|
||||
'id' => $this->id,
|
||||
'status' => $this->status,
|
||||
'status_label' => $this->status_label,
|
||||
'channel_name' => $this->channel_name,
|
||||
'is_guest' => $this->is_guest,
|
||||
'customer_email' => $this->customer_email,
|
||||
|
|
@ -26,6 +27,7 @@ class Order extends JsonResource
|
|||
'customer_last_name' => $this->customer_last_name,
|
||||
'shipping_method' => $this->shipping_method,
|
||||
'shipping_title' => $this->shipping_title,
|
||||
'payment_title' => core()->getConfigData('sales.paymentmethods.' . $this->payment->method . '.title'),
|
||||
'shipping_description' => $this->shipping_description,
|
||||
'coupon_code' => $this->coupon_code,
|
||||
'is_gift' => $this->is_gift,
|
||||
|
|
@ -35,37 +37,68 @@ class Order extends JsonResource
|
|||
'channel_currency_code' => $this->channel_currency_code,
|
||||
'order_currency_code' => $this->order_currency_code,
|
||||
'grand_total' => $this->grand_total,
|
||||
'formated_grand_total' => core()->formatPrice($this->grand_total, $this->order_currency_code),
|
||||
'base_grand_total' => $this->base_grand_total,
|
||||
'formated_base_grand_total' => core()->formatBasePrice($this->base_grand_total),
|
||||
'grand_total_invoiced' => $this->grand_total_invoiced,
|
||||
'formated_grand_total_invoiced' => core()->formatPrice($this->grand_total_invoiced, $this->order_currency_code),
|
||||
'base_grand_total_invoiced' => $this->base_grand_total_invoiced,
|
||||
'formated_base_grand_total_invoiced' => core()->formatBasePrice($this->base_grand_total_invoiced),
|
||||
'grand_total_refunded' => $this->grand_total_refunded,
|
||||
'formated_grand_total_refunded' => core()->formatPrice($this->grand_total_refunded, $this->order_currency_code),
|
||||
'base_grand_total_refunded' => $this->base_grand_total_refunded,
|
||||
'formated_base_grand_total_refunded' => core()->formatBasePrice($this->base_grand_total_refunded),
|
||||
'sub_total' => $this->sub_total,
|
||||
'formated_sub_total' => core()->formatPrice($this->sub_total, $this->order_currency_code),
|
||||
'base_sub_total' => $this->base_sub_total,
|
||||
'formated_base_sub_total' => core()->formatBasePrice($this->base_sub_total),
|
||||
'sub_total_invoiced' => $this->sub_total_invoiced,
|
||||
'formated_sub_total_invoiced' => core()->formatPrice($this->sub_total_invoiced, $this->order_currency_code),
|
||||
'base_sub_total_invoiced' => $this->base_sub_total_invoiced,
|
||||
'formated_base_sub_total_invoiced' => core()->formatBasePrice($this->base_sub_total_invoiced),
|
||||
'sub_total_refunded' => $this->sub_total_refunded,
|
||||
'formated_sub_total_refunded' => core()->formatPrice($this->sub_total_refunded, $this->order_currency_code),
|
||||
'discount_percent' => $this->discount_percent,
|
||||
'discount_amount' => $this->discount_amount,
|
||||
'formated_discount_amount' => core()->formatPrice($this->discount_amount, $this->order_currency_code),
|
||||
'base_discount_amount' => $this->base_discount_amount,
|
||||
'formated_base_discount_amount' => core()->formatBasePrice($this->base_discount_amount),
|
||||
'discount_invoiced' => $this->discount_invoiced,
|
||||
'formated_discount_invoiced' => core()->formatPrice($this->discount_invoiced, $this->order_currency_code),
|
||||
'base_discount_invoiced' => $this->base_discount_invoiced,
|
||||
'formated_base_discount_invoiced' => core()->formatBasePrice($this->base_discount_invoiced),
|
||||
'discount_refunded' => $this->discount_refunded,
|
||||
'formated_discount_refunded' => core()->formatPrice($this->discount_refunded, $this->order_currency_code),
|
||||
'base_discount_refunded' => $this->base_discount_refunded,
|
||||
'formated_base_discount_refunded' => core()->formatBasePrice($this->base_discount_refunded),
|
||||
'tax_amount' => $this->tax_amount,
|
||||
'formated_tax_amount' => core()->formatPrice($this->tax_amount, $this->order_currency_code),
|
||||
'base_tax_amount' => $this->base_tax_amount,
|
||||
'formated_base_tax_amount' => core()->formatBasePrice($this->base_tax_amount),
|
||||
'tax_amount_invoiced' => $this->tax_amount_invoiced,
|
||||
'formated_tax_amount_invoiced' => core()->formatPrice($this->tax_amount_invoiced, $this->order_currency_code),
|
||||
'base_tax_amount_invoiced' => $this->base_tax_amount_invoiced,
|
||||
'formated_base_tax_amount_invoiced' => core()->formatBasePrice($this->base_tax_amount_invoiced),
|
||||
'tax_amount_refunded' => $this->tax_amount_refunded,
|
||||
'formated_tax_amount_refunded' => core()->formatPrice($this->tax_amount_refunded, $this->order_currency_code),
|
||||
'base_tax_amount_refunded' => $this->base_tax_amount_refunded,
|
||||
'formated_base_tax_amount_refunded' => core()->formatBasePrice($this->base_tax_amount_refunded),
|
||||
'shipping_amount' => $this->shipping_amount,
|
||||
'formated_shipping_amount' => core()->formatPrice($this->shipping_amount, $this->order_currency_code),
|
||||
'base_shipping_amount' => $this->base_shipping_amount,
|
||||
'formated_base_shipping_amount' => core()->formatBasePrice($this->base_shipping_amount),
|
||||
'shipping_invoiced' => $this->shipping_invoiced,
|
||||
'formated_shipping_invoiced' => core()->formatPrice($this->shipping_invoiced, $this->order_currency_code),
|
||||
'base_shipping_invoiced' => $this->base_shipping_invoiced,
|
||||
'formated_base_shipping_invoiced' => core()->formatBasePrice($this->base_shipping_invoiced),
|
||||
'shipping_refunded' => $this->shipping_refunded,
|
||||
'formated_shipping_refunded' => core()->formatPrice($this->shipping_refunded, $this->order_currency_code),
|
||||
'base_shipping_refunded' => $this->base_shipping_refunded,
|
||||
'formated_base_shipping_refunded' => core()->formatBasePrice($this->base_shipping_refunded),
|
||||
'customer' => $this->when($this->customer_id, new CustomerResource($this->customer)),
|
||||
'channel' => $this->when($this->channel_id, new ChannelResource($this->channel)),
|
||||
'shipping_address' => new OrderAddress($this->shipping_address),
|
||||
'billing_address' => new OrderAddress($this->billing_address),
|
||||
'updated_at' => $this->updated_at,
|
||||
'items' => OrderItem::collection($this->items),
|
||||
'invoices' => Invoice::collection($this->invoices),
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@ class OrderAddress extends JsonResource
|
|||
'email' => $this->email,
|
||||
'first_name' => $this->first_name,
|
||||
'last_name' => $this->last_name,
|
||||
'address1' => $this->address1,
|
||||
'address2' => $this->address2,
|
||||
'address1' => explode(PHP_EOL, $this->address1),
|
||||
'country' => $this->country,
|
||||
'country_name' => country()->name($this->country),
|
||||
'state' => $this->state,
|
||||
'city' => $this->city,
|
||||
'postcode' => $this->postcode,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace Webkul\API\Http\Resources\Sales;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Webkul\API\Http\Resources\Catalog\Product as ProductResource;
|
||||
|
||||
class OrderItem extends JsonResource
|
||||
{
|
||||
|
|
@ -19,35 +20,61 @@ class OrderItem extends JsonResource
|
|||
'sku' => $this->sku,
|
||||
'type' => $this->type,
|
||||
'name' => $this->name,
|
||||
'product' => $this->when($this->product, new ProductResource($this->product)),
|
||||
'coupon_code' => $this->coupon_code,
|
||||
'weight' => $this->weight,
|
||||
'total_weight' => $this->total_weight,
|
||||
'qty_ordered' => $this->qty_ordered,
|
||||
'qty_canceled' => $this->qty_canceled,
|
||||
'qty_invoiced' => $this->qty_invoiced,
|
||||
'qty_shipped' => $this->qty_shipped,
|
||||
'qty_refunded' => $this->qty_refunded,
|
||||
'price' => $this->price,
|
||||
'formated_price' => core()->formatPrice($this->price, $this->order->order_currency_code),
|
||||
'base_price' => $this->base_price,
|
||||
'formated_base_price' => core()->formatBasePrice($this->base_price),
|
||||
'total' => $this->total,
|
||||
'formated_total' => core()->formatPrice($this->total, $this->order->order_currency_code),
|
||||
'base_total' => $this->base_total,
|
||||
'formated_base_total' => core()->formatBasePrice($this->base_total),
|
||||
'total_invoiced' => $this->total_invoiced,
|
||||
'formated_total_invoiced' => core()->formatPrice($this->total_invoiced, $this->order->order_currency_code),
|
||||
'base_total_invoiced' => $this->base_total_invoiced,
|
||||
'formated_base_total_invoiced' => core()->formatBasePrice($this->base_total_invoiced),
|
||||
'amount_refunded' => $this->amount_refunded,
|
||||
'formated_amount_refunded' => core()->formatPrice($this->amount_refunded, $this->order->order_currency_code),
|
||||
'base_amount_refunded' => $this->base_amount_refunded,
|
||||
'formated_base_amount_refunded' => core()->formatBasePrice($this->base_amount_refunded),
|
||||
'discount_percent' => $this->discount_percent,
|
||||
'discount_amount' => $this->discount_amount,
|
||||
'formated_discount_amount' => core()->formatPrice($this->discount_amount, $this->order->order_currency_code),
|
||||
'base_discount_amount' => $this->base_discount_amount,
|
||||
'formated_base_discount_amount' => core()->formatBasePrice($this->base_discount_amount),
|
||||
'discount_invoiced' => $this->discount_invoiced,
|
||||
'formated_discount_invoiced' => core()->formatPrice($this->discount_invoiced, $this->order->order_currency_code),
|
||||
'base_discount_invoiced' => $this->base_discount_invoiced,
|
||||
'formated_base_discount_invoiced' => core()->formatBasePrice($this->base_discount_invoiced),
|
||||
'discount_refunded' => $this->discount_refunded,
|
||||
'formated_discount_refunded' => core()->formatPrice($this->discount_refunded, $this->order->order_currency_code),
|
||||
'base_discount_refunded' => $this->base_discount_refunded,
|
||||
'formated_base_discount_refunded' => core()->formatBasePrice($this->base_discount_refunded),
|
||||
'tax_percent' => $this->tax_percent,
|
||||
'tax_amount' => $this->tax_amount,
|
||||
'formated_tax_amount' => core()->formatPrice($this->tax_amount, $this->order->order_currency_code),
|
||||
'base_tax_amount' => $this->base_tax_amount,
|
||||
'formated_base_tax_amount' => core()->formatBasePrice($this->base_tax_amount),
|
||||
'tax_amount_invoiced' => $this->tax_amount_invoiced,
|
||||
'formated_tax_amount_invoiced' => core()->formatPrice($this->tax_amount_invoiced, $this->order->order_currency_code),
|
||||
'base_tax_amount_invoiced' => $this->base_tax_amount_invoiced,
|
||||
'formated_base_tax_amount_invoiced' => core()->formatBasePrice($this->base_tax_amount_invoiced),
|
||||
'tax_amount_refunded' => $this->tax_amount_refunded,
|
||||
'formated_tax_amount_refunded' => core()->formatPrice($this->tax_amount_refunded, $this->order->order_currency_code),
|
||||
'base_tax_amount_refunded' => $this->base_tax_amount_refunded,
|
||||
'formated_base_tax_amount_refunded' => core()->formatBasePrice($this->base_tax_amount_refunded),
|
||||
'grant_total' => $this->total + $this->tax_amount,
|
||||
'formated_grant_total' => core()->formatPrice($this->total + $this->tax_amount, $this->order->order_currency_code),
|
||||
'base_grant_total' => $this->base_total + $this->base_tax_amount,
|
||||
'formated_base_grant_total' => core()->formatPrice($this->base_total + $this->base_tax_amount, $this->order->order_currency_code),
|
||||
'additional' => is_array($this->resource->additional)
|
||||
? $this->resource->additional
|
||||
: json_decode($this->resource->additional, true),
|
||||
|
|
|
|||
|
|
@ -22,9 +22,13 @@ class ShipmentItem extends JsonResource
|
|||
'qty' => $this->qty,
|
||||
'weight' => $this->weight,
|
||||
'price' => $this->price,
|
||||
'formated_price' => core()->formatPrice($this->price, $this->shipment->order->order_currency_code),
|
||||
'base_price' => $this->base_price,
|
||||
'formated_base_price' => core()->formatBasePrice($this->base_price),
|
||||
'total' => $this->total,
|
||||
'formated_total' => core()->formatPrice($this->total, $this->shipment->order->order_currency_code),
|
||||
'base_total' => $this->base_total,
|
||||
'formated_base_total' => core()->formatBasePrice($this->base_total),
|
||||
'additional' => is_array($this->resource->additional)
|
||||
? $this->resource->additional
|
||||
: json_decode($this->resource->additional, true)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
Route::group(['prefix' => 'api'], function ($router) {
|
||||
|
||||
Route::group(['namespace' => 'Webkul\API\Http\Controllers\Shop', 'middleware' => ['locale', 'currency']], function ($router) {
|
||||
Route::group(['namespace' => 'Webkul\API\Http\Controllers\Shop', 'middleware' => ['locale', 'theme', 'currency']], function ($router) {
|
||||
//Currency and Locale switcher
|
||||
Route::get('switch-currency', 'CoreController@switchCurrency');
|
||||
|
||||
|
|
@ -15,7 +15,7 @@ Route::group(['prefix' => 'api'], function ($router) {
|
|||
'resource' => 'Webkul\API\Http\Resources\Catalog\Category'
|
||||
]);
|
||||
|
||||
Route::get('descendants-categories', 'CategoryController@index');
|
||||
Route::get('descendant-categories', 'CategoryController@index');
|
||||
|
||||
Route::get('categories/{id}', 'ResourceController@get')->defaults('_config', [
|
||||
'repository' => 'Webkul\Category\Repositories\CategoryRepository',
|
||||
|
|
@ -52,6 +52,10 @@ Route::group(['prefix' => 'api'], function ($router) {
|
|||
|
||||
Route::get('products/{id}', 'ProductController@get');
|
||||
|
||||
Route::get('product-additional-information/{id}', 'ProductController@additionalInformation');
|
||||
|
||||
Route::get('product-configurable-config/{id}', 'ProductController@configurableConfig');
|
||||
|
||||
|
||||
//Product Review routes
|
||||
Route::get('reviews', 'ResourceController@index')->defaults('_config', [
|
||||
|
|
@ -64,6 +68,8 @@ Route::group(['prefix' => 'api'], function ($router) {
|
|||
'resource' => 'Webkul\API\Http\Resources\Catalog\ProductReview'
|
||||
]);
|
||||
|
||||
Route::post('reviews/{id}/create', 'ReviewController@store');
|
||||
|
||||
|
||||
//Channel routes
|
||||
Route::get('channels', 'ResourceController@index')->defaults('_config', [
|
||||
|
|
@ -89,6 +95,20 @@ Route::group(['prefix' => 'api'], function ($router) {
|
|||
]);
|
||||
|
||||
|
||||
//Country routes
|
||||
Route::get('countries', 'ResourceController@index')->defaults('_config', [
|
||||
'repository' => 'Webkul\Core\Repositories\CountryRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Core\Country'
|
||||
]);
|
||||
|
||||
Route::get('countries/{id}', 'ResourceController@get')->defaults('_config', [
|
||||
'repository' => 'Webkul\Core\Repositories\CountryRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Core\Country'
|
||||
]);
|
||||
|
||||
Route::get('country-states', 'CoreController@getCountryStateGroup');
|
||||
|
||||
|
||||
//Slider routes
|
||||
Route::get('sliders', 'ResourceController@index')->defaults('_config', [
|
||||
'repository' => 'Webkul\Core\Repositories\SliderRepository',
|
||||
|
|
@ -112,71 +132,130 @@ Route::group(['prefix' => 'api'], function ($router) {
|
|||
'resource' => 'Webkul\API\Http\Resources\Core\Currency'
|
||||
]);
|
||||
|
||||
Route::get('config', 'CoreController@getConfig');
|
||||
|
||||
|
||||
//Customer routes
|
||||
Route::get('customers', 'ResourceController@index')->defaults('_config', [
|
||||
'repository' => 'Webkul\Customer\Repositories\CustomerRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Customer\Customer'
|
||||
]);
|
||||
Route::post('customer/login', 'SessionController@create');
|
||||
|
||||
Route::get('customer/logout', 'SessionController@destroy');
|
||||
|
||||
Route::get('customer/get', 'SessionController@get');
|
||||
|
||||
Route::put('customer/profile', 'SessionController@update');
|
||||
|
||||
Route::post('customer/register', 'CustomerController@create');
|
||||
|
||||
Route::get('customers/{id}', 'ResourceController@get')->defaults('_config', [
|
||||
'repository' => 'Webkul\Customer\Repositories\CustomerRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Customer\Customer'
|
||||
'resource' => 'Webkul\API\Http\Resources\Customer\Customer',
|
||||
'authorization_required' => true
|
||||
]);
|
||||
|
||||
|
||||
//Customer Address routes
|
||||
Route::get('addresses', 'ResourceController@index')->defaults('_config', [
|
||||
'repository' => 'Webkul\Customer\Repositories\CustomerAddressRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Customer\CustomerAddress'
|
||||
'resource' => 'Webkul\API\Http\Resources\Customer\CustomerAddress',
|
||||
'authorization_required' => true
|
||||
]);
|
||||
|
||||
Route::get('addresses/{id}', 'ResourceController@get')->defaults('_config', [
|
||||
'repository' => 'Webkul\Customer\Repositories\CustomerAddressRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Customer\CustomerAddress'
|
||||
'resource' => 'Webkul\API\Http\Resources\Customer\CustomerAddress',
|
||||
'authorization_required' => true
|
||||
]);
|
||||
|
||||
Route::put('addresses/{id}', 'AddressController@update')->defaults('_config', [
|
||||
'authorization_required' => true
|
||||
]);
|
||||
|
||||
Route::post('addresses/create', 'AddressController@store')->defaults('_config', [
|
||||
'authorization_required' => true
|
||||
]);
|
||||
|
||||
|
||||
//Order routes
|
||||
Route::get('orders', 'ResourceController@index')->defaults('_config', [
|
||||
'repository' => 'Webkul\Sales\Repositories\OrderRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Sales\Order'
|
||||
'resource' => 'Webkul\API\Http\Resources\Sales\Order',
|
||||
'authorization_required' => true
|
||||
]);
|
||||
|
||||
Route::get('orders/{id}', 'ResourceController@get')->defaults('_config', [
|
||||
'repository' => 'Webkul\Sales\Repositories\OrderRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Sales\Order'
|
||||
'resource' => 'Webkul\API\Http\Resources\Sales\Order',
|
||||
'authorization_required' => true
|
||||
]);
|
||||
|
||||
|
||||
//Invoice routes
|
||||
Route::get('invoices', 'ResourceController@index')->defaults('_config', [
|
||||
'repository' => 'Webkul\Sales\Repositories\InvoiceRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Sales\Invoice'
|
||||
'resource' => 'Webkul\API\Http\Resources\Sales\Invoice',
|
||||
'authorization_required' => true
|
||||
]);
|
||||
|
||||
Route::get('invoices/{id}', 'ResourceController@get')->defaults('_config', [
|
||||
'repository' => 'Webkul\Sales\Repositories\InvoiceRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Sales\Invoice'
|
||||
'resource' => 'Webkul\API\Http\Resources\Sales\Invoice',
|
||||
'authorization_required' => true
|
||||
]);
|
||||
|
||||
|
||||
//Invoice routes
|
||||
Route::get('shipments', 'ResourceController@index')->defaults('_config', [
|
||||
'repository' => 'Webkul\Sales\Repositories\ShipmentRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Sales\Shipment'
|
||||
'resource' => 'Webkul\API\Http\Resources\Sales\Shipment',
|
||||
'authorization_required' => true
|
||||
]);
|
||||
|
||||
Route::get('shipments/{id}', 'ResourceController@get')->defaults('_config', [
|
||||
'repository' => 'Webkul\Sales\Repositories\ShipmentRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Sales\Shipment'
|
||||
'resource' => 'Webkul\API\Http\Resources\Sales\Shipment',
|
||||
'authorization_required' => true
|
||||
]);
|
||||
|
||||
|
||||
//Wishlist routes
|
||||
Route::get('wishlist', 'ResourceController@index')->defaults('_config', [
|
||||
'repository' => 'Webkul\Customer\Repositories\WishlistRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Customer\Wishlist'
|
||||
'resource' => 'Webkul\API\Http\Resources\Customer\Wishlist',
|
||||
'authorization_required' => true
|
||||
]);
|
||||
|
||||
Route::delete('wishlist/{id}', 'ResourceController@destroy')->defaults('_config', [
|
||||
'repository' => 'Webkul\Customer\Repositories\WishlistRepository',
|
||||
'resource' => 'Webkul\API\Http\Resources\Customer\Wishlist',
|
||||
'authorization_required' => true
|
||||
]);
|
||||
|
||||
Route::get('move-to-cart/{id}', 'WishlistController@moveToCart');
|
||||
|
||||
Route::get('wishlist/add/{id}', 'WishlistController@create');
|
||||
|
||||
|
||||
//Checkout routes
|
||||
Route::group(['prefix' => 'checkout'], function ($router) {
|
||||
Route::post('cart/add/{id}', 'CartController@store');
|
||||
|
||||
Route::get('cart', 'CartController@get');
|
||||
|
||||
Route::get('cart/empty', 'CartController@destroy');
|
||||
|
||||
Route::put('cart/update', 'CartController@update');
|
||||
|
||||
Route::get('cart/remove-item/{id}', 'CartController@destroyItem');
|
||||
|
||||
Route::get('cart/move-to-wishlist/{id}', 'CartController@moveToWishlist');
|
||||
|
||||
Route::post('save-address', 'CheckoutController@saveAddress');
|
||||
|
||||
Route::post('save-shipping', 'CheckoutController@saveShipping');
|
||||
|
||||
Route::post('save-payment', 'CheckoutController@savePayment');
|
||||
|
||||
Route::post('save-order', 'CheckoutController@saveOrder');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -3,6 +3,8 @@
|
|||
namespace Webkul\API\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Routing\Router;
|
||||
use Webkul\API\Http\Middleware\JwtMiddleware;
|
||||
|
||||
class APIServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
|
@ -11,7 +13,7 @@ class APIServiceProvider extends ServiceProvider
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
public function boot(Router $router)
|
||||
{
|
||||
$this->loadRoutesFrom(__DIR__.'/../Http/routes.php');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -468,6 +468,10 @@ class ProductRepository extends Repository
|
|||
->where('flat_variants.locale', $locale);
|
||||
});
|
||||
|
||||
if (isset($params['sort'])) {
|
||||
$qb->where('product_flat.name', 'like', '%' . urldecode($params['search']) . '%');
|
||||
}
|
||||
|
||||
if (isset($params['sort'])) {
|
||||
$attribute = $this->attribute->findOneByField('code', $params['sort']);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue