API Package Removed
This commit is contained in:
parent
41771be240
commit
11dbe23d12
|
|
@ -272,7 +272,6 @@ return [
|
|||
Webkul\Paypal\Providers\PaypalServiceProvider::class,
|
||||
Webkul\Sales\Providers\SalesServiceProvider::class,
|
||||
Webkul\Tax\Providers\TaxServiceProvider::class,
|
||||
Webkul\API\Providers\APIServiceProvider::class,
|
||||
Webkul\CatalogRule\Providers\CatalogRuleServiceProvider::class,
|
||||
Webkul\CartRule\Providers\CartRuleServiceProvider::class,
|
||||
Webkul\Rule\Providers\RuleServiceProvider::class,
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ return [
|
|||
*/
|
||||
|
||||
\Webkul\Admin\Providers\ModuleServiceProvider::class,
|
||||
\Webkul\API\Providers\ModuleServiceProvider::class,
|
||||
\Webkul\Attribute\Providers\ModuleServiceProvider::class,
|
||||
\Webkul\BookingProduct\Providers\ModuleServiceProvider::class,
|
||||
\Webkul\CartRule\Providers\ModuleServiceProvider::class,
|
||||
|
|
|
|||
|
|
@ -1,140 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers\Shop;
|
||||
|
||||
use Webkul\Customer\Repositories\CustomerAddressRepository;
|
||||
use Webkul\API\Http\Resources\Customer\CustomerAddress as CustomerAddressResource;
|
||||
|
||||
class AddressController extends Controller
|
||||
{
|
||||
/**
|
||||
* Contains current guard
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guard;
|
||||
|
||||
/**
|
||||
* Contains route related configuration
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_config;
|
||||
|
||||
/**
|
||||
* CustomerAddressRepository object
|
||||
*
|
||||
* @var \Webkul\Customer\Repositories\CustomerAddressRepository
|
||||
*/
|
||||
protected $customerAddressRepository;
|
||||
|
||||
/**
|
||||
* Controller instance
|
||||
*
|
||||
* @param 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user address.
|
||||
*
|
||||
* @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
$customer = auth($this->guard)->user();
|
||||
|
||||
$addresses = $customer->addresses()->get();
|
||||
|
||||
return CustomerAddressResource::collection($addresses);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function store()
|
||||
{
|
||||
$customer = auth($this->guard)->user();
|
||||
|
||||
if (request()->input('address1') && ! is_array(request()->input('address1'))) {
|
||||
return response()->json([
|
||||
'message' => 'address1 must be an array.',
|
||||
]);
|
||||
}
|
||||
|
||||
if (request()->input('address1')) {
|
||||
request()->merge([
|
||||
'address1' => implode(PHP_EOL, array_filter(request()->input('address1'))),
|
||||
'customer_id' => $customer->id,
|
||||
]);
|
||||
}
|
||||
|
||||
$this->validate(request(), [
|
||||
'address1' => 'string|required',
|
||||
'company' => 'string|nullable',
|
||||
'vat_id' => 'string|nullable',
|
||||
'country' => 'string|required',
|
||||
'state' => 'string|nullable',
|
||||
'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.
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function update(int $id)
|
||||
{
|
||||
if (request()->input('address1') && ! is_array(request()->input('address1'))) {
|
||||
return response()->json([
|
||||
'message' => 'address1 must be an array.',
|
||||
]);
|
||||
}
|
||||
|
||||
request()->merge(['address1' => implode(PHP_EOL, array_filter(request()->input('address1')))]);
|
||||
|
||||
$this->validate(request(), [
|
||||
'address1' => 'string|required',
|
||||
'company' => 'string|nullable',
|
||||
'vat_id' => 'string|nullable',
|
||||
'country' => 'string|required',
|
||||
'state' => 'string|nullable',
|
||||
'city' => 'string|required',
|
||||
'postcode' => 'required',
|
||||
'phone' => 'required',
|
||||
]);
|
||||
|
||||
$customerAddress = $this->customerAddressRepository->update(request()->all(), $id);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Your address has been updated successfully.',
|
||||
'data' => new CustomerAddressResource($customerAddress),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,304 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers\Shop;
|
||||
|
||||
use Cart;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Webkul\Checkout\Repositories\CartRepository;
|
||||
use Webkul\Checkout\Repositories\CartItemRepository;
|
||||
use Webkul\Customer\Repositories\WishlistRepository;
|
||||
use Webkul\API\Http\Resources\Checkout\Cart as CartResource;
|
||||
|
||||
class CartController extends Controller
|
||||
{
|
||||
/**
|
||||
* Contains current guard
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guard;
|
||||
|
||||
/**
|
||||
* CartRepository object
|
||||
*
|
||||
* @var \Webkul\Checkout\Repositories\CartRepository
|
||||
*/
|
||||
protected $cartRepository;
|
||||
|
||||
/**
|
||||
* CartItemRepository object
|
||||
*
|
||||
* @var \Webkul\Checkout\Repositories\CartItemRepository
|
||||
*/
|
||||
protected $cartItemRepository;
|
||||
|
||||
/**
|
||||
* WishlistRepository object
|
||||
*
|
||||
* @var \Webkul\Checkout\Repositories\WishlistRepository
|
||||
*/
|
||||
protected $wishlistRepository;
|
||||
|
||||
/**
|
||||
* Controller instance
|
||||
*
|
||||
* @param \Webkul\Checkout\Repositories\CartRepository $cartRepository
|
||||
* @param \Webkul\Checkout\Repositories\CartItemRepository $cartItemRepository
|
||||
* @param \Webkul\Checkout\Repositories\WishlistRepository $wishlistRepository
|
||||
*/
|
||||
public function __construct(
|
||||
CartRepository $cartRepository,
|
||||
CartItemRepository $cartItemRepository,
|
||||
WishlistRepository $wishlistRepository
|
||||
) {
|
||||
$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->wishlistRepository = $wishlistRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get customer cart.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
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\JsonResponse
|
||||
*/
|
||||
public function store($id): ?JsonResponse
|
||||
{
|
||||
if (request()->get('is_buy_now')) {
|
||||
Event::dispatch('shop.item.buy-now', $id);
|
||||
}
|
||||
|
||||
Event::dispatch('checkout.cart.item.add.before', $id);
|
||||
|
||||
try {
|
||||
$result = Cart::addProduct($id, request()->except('_token'));
|
||||
|
||||
if (is_array($result) && isset($result['warning'])) {
|
||||
return response()->json([
|
||||
'error' => $result['warning'],
|
||||
], 400);
|
||||
}
|
||||
|
||||
if ($customer = auth($this->guard)->user()) {
|
||||
$this->wishlistRepository->deleteWhere(['product_id' => $id, 'customer_id' => $customer->id]);
|
||||
}
|
||||
|
||||
Event::dispatch('checkout.cart.item.add.after', $result);
|
||||
|
||||
Cart::collectTotals();
|
||||
|
||||
$cart = Cart::getCart();
|
||||
|
||||
return response()->json([
|
||||
'message' => __('shop::app.checkout.cart.item.success'),
|
||||
'data' => $cart ? new CartResource($cart) : null,
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
Log::error('API CartController: ' . $e->getMessage(),
|
||||
['product_id' => $id, 'cart_id' => cart()->getCart() ?? 0]);
|
||||
|
||||
return response()->json([
|
||||
'error' => [
|
||||
'message' => $e->getMessage(),
|
||||
'code' => $e->getCode()
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function update(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'qty' => 'required|array',
|
||||
]);
|
||||
|
||||
$requestedQuantity = $request->get('qty');
|
||||
|
||||
foreach ($requestedQuantity as $qty) {
|
||||
if ($qty <= 0) {
|
||||
return response()->json([
|
||||
'message' => trans('shop::app.checkout.cart.quantity.illegal'),
|
||||
], Response::HTTP_UNAUTHORIZED);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($requestedQuantity as $itemId => $qty) {
|
||||
$item = $this->cartItemRepository->findOneByField('id', $itemId);
|
||||
|
||||
Event::dispatch('checkout.cart.item.update.before', $itemId);
|
||||
|
||||
Cart::updateItems(['qty' => $requestedQuantity]);
|
||||
|
||||
Event::dispatch('checkout.cart.item.update.after', $item);
|
||||
}
|
||||
|
||||
Cart::collectTotals();
|
||||
|
||||
$cart = Cart::getCart();
|
||||
|
||||
return response()->json([
|
||||
'message' => __('shop::app.checkout.cart.quantity.success'),
|
||||
'data' => $cart ? new CartResource($cart) : null,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function destroy()
|
||||
{
|
||||
Event::dispatch('checkout.cart.delete.before');
|
||||
|
||||
Cart::deActivateCart();
|
||||
|
||||
Event::dispatch('checkout.cart.delete.after');
|
||||
|
||||
$cart = Cart::getCart();
|
||||
|
||||
return response()->json([
|
||||
'message' => __('shop::app.checkout.cart.item.success-remove'),
|
||||
'data' => $cart ? new CartResource($cart) : null,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function destroyItem($id)
|
||||
{
|
||||
Event::dispatch('checkout.cart.item.delete.before', $id);
|
||||
|
||||
Cart::removeItem($id);
|
||||
|
||||
Event::dispatch('checkout.cart.item.delete.after', $id);
|
||||
|
||||
Cart::collectTotals();
|
||||
|
||||
$cart = Cart::getCart();
|
||||
|
||||
return response()->json([
|
||||
'message' => __('shop::app.checkout.cart.item.success-remove'),
|
||||
'data' => $cart ? new CartResource($cart) : null,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to move a already added product to wishlist will run only on customer authentication.
|
||||
*
|
||||
* @param \Webkul\Checkout\Repositories\CartItemRepository $id
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function moveToWishlist($id)
|
||||
{
|
||||
Event::dispatch('checkout.cart.item.move-to-wishlist.before', $id);
|
||||
|
||||
Cart::moveToWishlist($id);
|
||||
|
||||
Event::dispatch('checkout.cart.item.move-to-wishlist.after', $id);
|
||||
|
||||
Cart::collectTotals();
|
||||
|
||||
$cart = Cart::getCart();
|
||||
|
||||
return response()->json([
|
||||
'message' => __('shop::app.checkout.cart.move-to-wishlist-success'),
|
||||
'data' => $cart ? new CartResource($cart) : null,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply coupon code.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function applyCoupon()
|
||||
{
|
||||
$couponCode = request()->get('code');
|
||||
|
||||
try {
|
||||
if (strlen($couponCode)) {
|
||||
Cart::setCouponCode($couponCode)->collectTotals();
|
||||
|
||||
if (Cart::getCart()->coupon_code == $couponCode) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => trans('shop::app.checkout.total.success-coupon'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => trans('shop::app.checkout.total.invalid-coupon'),
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
report($e);
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => trans('shop::app.checkout.total.coupon-apply-issue'),
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove coupon code.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function removeCoupon()
|
||||
{
|
||||
Cart::removeCouponCode()->collectTotals();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => trans('shop::app.checkout.total.remove-coupon'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers\Shop;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Webkul\Category\Repositories\CategoryRepository;
|
||||
use Webkul\API\Http\Resources\Catalog\Category as CategoryResource;
|
||||
|
||||
class CategoryController extends Controller
|
||||
{
|
||||
/**
|
||||
* CategoryRepository object
|
||||
*
|
||||
* @var \Webkul\Category\Repositories\CategoryRepository
|
||||
*/
|
||||
protected $categoryRepository;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @param Webkul\Category\Repositories\CategoryRepository $categoryRepository
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(CategoryRepository $categoryRepository)
|
||||
{
|
||||
$this->categoryRepository = $categoryRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return CategoryResource::collection(
|
||||
$this->categoryRepository->getVisibleCategoryTree(request()->input('parent_id'))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,227 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers\Shop;
|
||||
|
||||
use Cart;
|
||||
use Exception;
|
||||
use Illuminate\Support\Str;
|
||||
use Webkul\Payment\Facades\Payment;
|
||||
use Webkul\Shipping\Facades\Shipping;
|
||||
use Webkul\Sales\Repositories\OrderRepository;
|
||||
use Webkul\Checkout\Repositories\CartRepository;
|
||||
use Webkul\Shop\Http\Controllers\OnepageController;
|
||||
use Webkul\Checkout\Repositories\CartItemRepository;
|
||||
use Webkul\Checkout\Http\Requests\CustomerAddressForm;
|
||||
use Webkul\API\Http\Resources\Sales\Order as OrderResource;
|
||||
use Webkul\API\Http\Resources\Checkout\Cart as CartResource;
|
||||
use Webkul\API\Http\Resources\Checkout\CartShippingRate as CartShippingRateResource;
|
||||
|
||||
class CheckoutController extends Controller
|
||||
{
|
||||
/**
|
||||
* Contains current guard
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guard;
|
||||
|
||||
/**
|
||||
* CartRepository object
|
||||
*
|
||||
* @var \Webkul\Checkout\Repositories\CartRepository
|
||||
*/
|
||||
protected $cartRepository;
|
||||
|
||||
/**
|
||||
* CartItemRepository object
|
||||
*
|
||||
* @var \Webkul\Checkout\Repositories\CartItemRepository
|
||||
*/
|
||||
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()),
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for minimum order.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function checkMinimumOrder()
|
||||
{
|
||||
$minimumOrderAmount = (float) core()->getConfigData('sales.orderSettings.minimum-order.minimum_order_amount') ?? 0;
|
||||
|
||||
$status = Cart::checkMinimumOrder();
|
||||
|
||||
return response()->json([
|
||||
'status' => ! $status ? false : true,
|
||||
'message' => ! $status ? trans('shop::app.checkout.cart.minimum-order-message', ['amount' => core()->currency($minimumOrderAmount)]) : 'Success',
|
||||
'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
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function validateOrder(): void
|
||||
{
|
||||
app(OnepageController::class)->validateOrder();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers\Shop;
|
||||
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
}
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers\Shop;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
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.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function switchCurrency()
|
||||
{
|
||||
return response()->json([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function switchLocale()
|
||||
{
|
||||
return response()->json([]);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,117 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers\Shop;
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Webkul\Customer\Http\Requests\CustomerRegistrationRequest;
|
||||
use Webkul\Customer\Repositories\CustomerGroupRepository;
|
||||
use Webkul\Customer\Repositories\CustomerRepository;
|
||||
|
||||
class CustomerController extends Controller
|
||||
{
|
||||
/**
|
||||
* Contains current guard
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guard;
|
||||
|
||||
/**
|
||||
* Contains route related configuration
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_config;
|
||||
|
||||
/**
|
||||
* Repository object
|
||||
*
|
||||
* @var \Webkul\Customer\Repositories\CustomerRepository
|
||||
*/
|
||||
protected $customerRepository;
|
||||
|
||||
/**
|
||||
* Repository object
|
||||
*
|
||||
* @var \Webkul\Customer\Repositories\CustomerGroupRepository
|
||||
*/
|
||||
protected $customerGroupRepository;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @param \Webkul\Customer\Repositories\CustomerRepository $customerRepository
|
||||
* @param \Webkul\Customer\Repositories\CustomerGroupRepository $customerGroupRepository
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
CustomerRepository $customerRepository,
|
||||
CustomerGroupRepository $customerGroupRepository
|
||||
) {
|
||||
$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->customerRepository = $customerRepository;
|
||||
|
||||
$this->customerGroupRepository = $customerGroupRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to store user's sign up form data to DB.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create(CustomerRegistrationRequest $request)
|
||||
{
|
||||
$request->validated();
|
||||
|
||||
$data = [
|
||||
'first_name' => $request->get('first_name'),
|
||||
'last_name' => $request->get('last_name'),
|
||||
'email' => $request->get('email'),
|
||||
'password' => $request->get('password'),
|
||||
'password' => bcrypt($request->get('password')),
|
||||
'channel_id' => core()->getCurrentChannel()->id,
|
||||
'is_verified' => 1,
|
||||
'customer_group_id' => $this->customerGroupRepository->findOneWhere(['code' => 'general'])->id
|
||||
];
|
||||
|
||||
Event::dispatch('customer.registration.before');
|
||||
|
||||
$customer = $this->customerRepository->create($data);
|
||||
|
||||
Event::dispatch('customer.registration.after', $customer);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Your account has been created successfully.',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a current user data.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
if (Auth::user($this->guard)->id === (int) $id) {
|
||||
return new $this->_config['resource'](
|
||||
$this->customerRepository->findOrFail($id)
|
||||
);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Invalid Request.',
|
||||
], 403);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers\Shop;
|
||||
|
||||
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
use Webkul\Customer\Http\Requests\CustomerForgotPasswordRequest;
|
||||
|
||||
class ForgotPasswordController extends Controller
|
||||
{
|
||||
use SendsPasswordResetEmails;
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(CustomerForgotPasswordRequest $request)
|
||||
{
|
||||
$request->validated();
|
||||
|
||||
$response = $this->broker()->sendResetLink($request->only(['email']));
|
||||
|
||||
return $response == Password::RESET_LINK_SENT
|
||||
? response()->json([
|
||||
'message' => trans($response),
|
||||
])
|
||||
: response()->json([
|
||||
'error' => trans($response),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the broker to be used during password reset.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Auth\PasswordBroker
|
||||
*/
|
||||
public function broker()
|
||||
{
|
||||
return Password::broker('customers');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,106 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers\Shop;
|
||||
|
||||
class InvoiceController extends Controller
|
||||
{
|
||||
/**
|
||||
* Contains current guard.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guard;
|
||||
|
||||
/**
|
||||
* Contains route related configuration.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_config;
|
||||
|
||||
/**
|
||||
* Repository object.
|
||||
*
|
||||
* @var \Webkul\Core\Eloquent\Repository
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$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);
|
||||
}
|
||||
|
||||
if ($this->_config) {
|
||||
$this->repository = app($this->_config['repository']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a listing of the invoices.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$query = $this->repository->scopeQuery(function($query) {
|
||||
$query = $query->leftJoin('orders', 'invoices.order_id', '=', 'orders.id')->select('invoices.*', 'orders.customer_id');
|
||||
|
||||
if (isset($this->_config['authorization_required']) && $this->_config['authorization_required']) {
|
||||
$query = $query->where('customer_id', auth()->user()->id);
|
||||
}
|
||||
|
||||
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;
|
||||
});
|
||||
|
||||
if (is_null(request()->input('pagination')) || request()->input('pagination')) {
|
||||
$results = $query->paginate(request()->input('limit') ?? 10);
|
||||
} else {
|
||||
$results = $query->get();
|
||||
}
|
||||
|
||||
return $this->_config['resource']::collection($results);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an individual invoice.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
if (isset($this->_config['authorization_required']) && $this->_config['authorization_required']) {
|
||||
$query = $this->repository->leftJoin('orders', 'invoices.order_id', '=', 'orders.id')
|
||||
->select('invoices.*', 'orders.customer_id')
|
||||
->where('customer_id', auth()->user()->id)
|
||||
->findOrFail($id);
|
||||
} else {
|
||||
$query = $this->repository->findOrFail($id);
|
||||
}
|
||||
|
||||
return new $this->_config['resource']($query);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers\Shop;
|
||||
|
||||
class OrderController extends Controller
|
||||
{
|
||||
/**
|
||||
* Contains current guard.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guard;
|
||||
|
||||
/**
|
||||
* Contains route related configuration.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_config;
|
||||
|
||||
/**
|
||||
* Repository instance.
|
||||
*
|
||||
* @var \Webkul\Core\Eloquent\Repository
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$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);
|
||||
}
|
||||
|
||||
if ($this->_config) {
|
||||
$this->repository = app($this->_config['repository']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel customer's order.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function cancel($id)
|
||||
{
|
||||
$order = auth()->guard($this->guard)->user()->all_orders()->find($id);
|
||||
|
||||
if ($order && $this->repository->cancel($order)) {
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'message' => __('admin::app.response.cancel-success', [
|
||||
'name' => 'Order'
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => __('shop::app.common.error'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers\Shop;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Webkul\Product\Repositories\ProductRepository;
|
||||
use Webkul\API\Http\Resources\Catalog\Product as ProductResource;
|
||||
|
||||
class ProductController extends Controller
|
||||
{
|
||||
/**
|
||||
* ProductRepository object
|
||||
*
|
||||
* @var \Webkul\Product\Repositories\ProductRepository
|
||||
*/
|
||||
protected $productRepository;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @param \Webkul\Product\Repositories\ProductRepository $productRepository
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(ProductRepository $productRepository)
|
||||
{
|
||||
$this->productRepository = $productRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return ProductResource::collection($this->productRepository->getAll(request()->input('category_id')));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a individual resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
return new ProductResource(
|
||||
$this->productRepository->findOrFail($id)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns product's additional information.
|
||||
*
|
||||
* @param int $id
|
||||
* @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.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function configurableConfig($id)
|
||||
{
|
||||
return response()->json([
|
||||
'data' => app('Webkul\Product\Helpers\ConfigurableOption')->getConfigurationConfig($this->productRepository->findOrFail($id)),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,118 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers\Shop;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ResourceController extends Controller
|
||||
{
|
||||
/**
|
||||
* Contains current guard
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guard;
|
||||
|
||||
/**
|
||||
* Contains route related configuration
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_config;
|
||||
|
||||
/**
|
||||
* Repository object
|
||||
*
|
||||
* @var \Webkul\Core\Eloquent\Repository
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$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);
|
||||
}
|
||||
|
||||
if ($this->_config) {
|
||||
$this->repository = app($this->_config['repository']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$query = $this->repository->scopeQuery(function($query) {
|
||||
if (isset($this->_config['authorization_required']) && $this->_config['authorization_required']) {
|
||||
$query = $query->where('customer_id', auth()->user()->id );
|
||||
}
|
||||
|
||||
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;
|
||||
});
|
||||
|
||||
if (is_null(request()->input('pagination')) || request()->input('pagination')) {
|
||||
$results = $query->paginate(request()->input('limit') ?? 10);
|
||||
} else {
|
||||
$results = $query->get();
|
||||
}
|
||||
|
||||
return $this->_config['resource']::collection($results);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a individual resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
$query = isset($this->_config['authorization_required']) && $this->_config['authorization_required'] ?
|
||||
$this->repository->where('customer_id', auth()->user()->id)->findOrFail($id) :
|
||||
$this->repository->findOrFail($id);
|
||||
|
||||
return new $this->_config['resource']($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete's a individual resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$wishlistProduct = $this->repository->findOrFail($id);
|
||||
|
||||
$this->repository->delete($id);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Item removed successfully.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
<?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;
|
||||
|
||||
class ReviewController extends Controller
|
||||
{
|
||||
/**
|
||||
* Contains current guard.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guard;
|
||||
|
||||
/**
|
||||
* ProductReviewRepository $reviewRepository
|
||||
*
|
||||
* @var \Webkul\Product\Repositories\ProductReviewRepository
|
||||
*/
|
||||
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
|
||||
* @param int $id
|
||||
* @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',
|
||||
]);
|
||||
|
||||
$productReview = $this->reviewRepository->create([
|
||||
'customer_id' => $customer ? $customer->id : null,
|
||||
'name' => $customer ? $customer->name : $request->get('name'),
|
||||
'status' => 'pending',
|
||||
'product_id' => $id,
|
||||
'comment' => $request->comment,
|
||||
'rating' => $request->rating,
|
||||
'title' => $request->title
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Your review submitted successfully.',
|
||||
'data' => new ProductReviewResource($productReview),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,133 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers\Shop;
|
||||
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Webkul\API\Http\Resources\Customer\Customer as CustomerResource;
|
||||
use Webkul\Customer\Http\Requests\CustomerLoginRequest;
|
||||
use Webkul\Customer\Repositories\CustomerRepository;
|
||||
|
||||
class SessionController extends Controller
|
||||
{
|
||||
/**
|
||||
* Contains current guard
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
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 \Illuminate\Http\Response
|
||||
*/
|
||||
public function create(CustomerLoginRequest $request)
|
||||
{
|
||||
$request->validated();
|
||||
|
||||
$jwtToken = null;
|
||||
|
||||
if (! $jwtToken = auth()->guard($this->guard)->attempt($request->only(['email', 'password']))) {
|
||||
return response()->json([
|
||||
'error' => 'Invalid Email or Password',
|
||||
], 401);
|
||||
}
|
||||
|
||||
Event::dispatch('customer.after.login', $request->get('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()->only('first_name', 'last_name', 'gender', 'date_of_birth', 'email', 'password');
|
||||
|
||||
if (! isset($data['password']) || ! $data['password']) {
|
||||
unset($data['password']);
|
||||
} else {
|
||||
$data['password'] = bcrypt($data['password']);
|
||||
}
|
||||
|
||||
$updatedCustomer = $this->customerRepository->update($data, $customer->id);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Your account has been updated successfully.',
|
||||
'data' => new CustomerResource($updatedCustomer),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,106 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Controllers\Shop;
|
||||
|
||||
class TransactionController extends Controller
|
||||
{
|
||||
/**
|
||||
* Contains current guard.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guard;
|
||||
|
||||
/**
|
||||
* Contains route related configuration.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_config;
|
||||
|
||||
/**
|
||||
* Repository object.
|
||||
*
|
||||
* @var \Webkul\Core\Eloquent\Repository
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$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);
|
||||
}
|
||||
|
||||
if ($this->_config) {
|
||||
$this->repository = app($this->_config['repository']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a listing of the Order Transactions.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$query = $this->repository->scopeQuery(function($query) {
|
||||
$query = $query->leftJoin('orders', 'order_transactions.order_id', '=', 'orders.id')->select('order_transactions.*', 'orders.customer_id');
|
||||
|
||||
if (isset($this->_config['authorization_required']) && $this->_config['authorization_required']) {
|
||||
$query = $query->where('customer_id', auth()->user()->id);
|
||||
}
|
||||
|
||||
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;
|
||||
});
|
||||
|
||||
if (is_null(request()->input('pagination')) || request()->input('pagination')) {
|
||||
$results = $query->paginate(request()->input('limit') ?? 10);
|
||||
} else {
|
||||
$results = $query->get();
|
||||
}
|
||||
|
||||
return $this->_config['resource']::collection($results);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an individual invoice.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
if (isset($this->_config['authorization_required']) && $this->_config['authorization_required']) {
|
||||
$query = $this->repository->leftJoin('orders', 'order_transactions.order_id', '=', 'orders.id')
|
||||
->select('order_transactions.*', 'orders.customer_id')
|
||||
->where('customer_id', auth()->user()->id)
|
||||
->findOrFail($id);
|
||||
} else {
|
||||
$query = $this->repository->findOrFail($id);
|
||||
}
|
||||
|
||||
return new $this->_config['resource']($query);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,121 +0,0 @@
|
|||
<?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 Webkul\API\Http\Resources\Checkout\Cart as CartResource;
|
||||
use Cart;
|
||||
|
||||
class WishlistController extends Controller
|
||||
{
|
||||
/**
|
||||
* WishlistRepository object
|
||||
*
|
||||
* @var \Webkul\Customer\Repositories\WishlistRepository
|
||||
*/
|
||||
protected $wishlistRepository;
|
||||
|
||||
/**
|
||||
* ProductRepository object
|
||||
*
|
||||
* @var \Webkul\Customer\Repositories\ProductRepository
|
||||
*/
|
||||
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 int $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 int $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) {
|
||||
Cart::collectTotals();
|
||||
|
||||
$cart = Cart::getCart();
|
||||
|
||||
return response()->json([
|
||||
'data' => $cart ? new CartResource($cart) : null,
|
||||
'message' => trans('shop::app.wishlist.moved'),
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'data' => -1,
|
||||
'error' => trans('shop::app.wishlist.option-missing'),
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Catalog;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class Attribute extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'code' => $this->code,
|
||||
'type' => $this->type,
|
||||
'name' => $this->name,
|
||||
'swatch_type' => $this->swatch_type,
|
||||
'options' => AttributeOption::collection($this->options),
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Catalog;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class AttributeFamily extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'code' => $this->code,
|
||||
'name' => $this->name,
|
||||
'status' => $this->status,
|
||||
'groups' => AttributeGroup::collection($this->attribute_groups),
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Catalog;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class AttributeGroup extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'code' => $this->code,
|
||||
'name' => $this->name,
|
||||
'swatch_type' => $this->swatch_type,
|
||||
'attributes' => Attribute::collection($this->custom_attributes)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Catalog;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class AttributeOption extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'admin_name' => $this->admin_name,
|
||||
'label' => $this->label,
|
||||
'swatch_value' => $this->swatch_value,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Catalog;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class Category extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'code' => $this->code,
|
||||
'name' => $this->name,
|
||||
'slug' => $this->slug,
|
||||
'display_mode' => $this->display_mode,
|
||||
'description' => $this->description,
|
||||
'meta_title' => $this->meta_title,
|
||||
'meta_description' => $this->meta_description,
|
||||
'meta_keywords' => $this->meta_keywords,
|
||||
'status' => $this->status,
|
||||
'image_url' => $this->image_url,
|
||||
'category_icon_path' => $this->category_icon_path
|
||||
? Storage::url($this->category_icon_path)
|
||||
: null,
|
||||
'additional' => is_array($this->resource->additional)
|
||||
? $this->resource->additional
|
||||
: json_decode($this->resource->additional, true),
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,293 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Catalog;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Webkul\Product\Facades\ProductImage as ProductImageFacade;
|
||||
|
||||
class Product extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Create a new resource instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($resource)
|
||||
{
|
||||
$this->productReviewHelper = app('Webkul\Product\Helpers\Review');
|
||||
|
||||
$this->wishlistHelper = app('Webkul\Customer\Helpers\Wishlist');
|
||||
|
||||
parent::__construct($resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
/* assign product */
|
||||
$product = $this->product ? $this->product : $this;
|
||||
|
||||
/* get type instance */
|
||||
$productTypeInstance = $product->getTypeInstance();
|
||||
|
||||
/* generating resource */
|
||||
return [
|
||||
/* product's information */
|
||||
'id' => $product->id,
|
||||
'sku' => $product->sku,
|
||||
'type' => $product->type,
|
||||
'name' => $product->name,
|
||||
'url_key' => $product->url_key,
|
||||
'price' => $productTypeInstance->getMinimalPrice(),
|
||||
'formated_price' => core()->currency($productTypeInstance->getMinimalPrice()),
|
||||
'short_description' => $product->short_description,
|
||||
'description' => $product->description,
|
||||
'images' => ProductImage::collection($product->images),
|
||||
'videos' => ProductVideo::collection($product->videos),
|
||||
'base_image' => ProductImageFacade::getProductBaseImage($product),
|
||||
'created_at' => $product->created_at,
|
||||
'updated_at' => $product->updated_at,
|
||||
|
||||
/* product's reviews */
|
||||
'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)) : [],
|
||||
],
|
||||
|
||||
/* product's checks */
|
||||
'in_stock' => $product->haveSufficientQuantity(1),
|
||||
'is_saved' => false,
|
||||
'is_wishlisted' => $this->wishlistHelper->getWishlistProduct($product) ? true : false,
|
||||
'is_item_in_cart' => \Cart::hasProduct($product),
|
||||
'show_quantity_changer' => $this->when(
|
||||
$product->type !== 'grouped',
|
||||
$product->getTypeInstance()->showQuantityBox()
|
||||
),
|
||||
|
||||
/* product's extra information */
|
||||
$this->merge($this->allProductExtraInfo()),
|
||||
|
||||
/* special price cases */
|
||||
$this->merge($this->specialPriceInfo()),
|
||||
|
||||
/* super attributes */
|
||||
$this->mergeWhen($productTypeInstance->isComposite(), [
|
||||
'super_attributes' => Attribute::collection($product->super_attributes),
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get special price information.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function specialPriceInfo()
|
||||
{
|
||||
$product = $this->product ? $this->product : $this;
|
||||
|
||||
$productTypeInstance = $product->getTypeInstance();
|
||||
|
||||
return [
|
||||
'special_price' => $this->when(
|
||||
$productTypeInstance->haveSpecialPrice(),
|
||||
$productTypeInstance->getSpecialPrice()
|
||||
),
|
||||
'formated_special_price' => $this->when(
|
||||
$productTypeInstance->haveSpecialPrice(),
|
||||
core()->currency($productTypeInstance->getSpecialPrice())
|
||||
),
|
||||
'regular_price' => $this->when(
|
||||
$productTypeInstance->haveSpecialPrice(),
|
||||
data_get($productTypeInstance->getProductPrices(), 'regular_price.price')
|
||||
),
|
||||
'formated_regular_price' => $this->when(
|
||||
$productTypeInstance->haveSpecialPrice(),
|
||||
data_get($productTypeInstance->getProductPrices(), 'regular_price.formated_price')
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all product's extra information.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function allProductExtraInfo()
|
||||
{
|
||||
$product = $this->product ? $this->product : $this;
|
||||
|
||||
$productTypeInstance = $product->getTypeInstance();
|
||||
|
||||
return [
|
||||
/* grouped product */
|
||||
$this->mergeWhen(
|
||||
$productTypeInstance instanceof \Webkul\Product\Type\Grouped,
|
||||
$product->type == 'grouped'
|
||||
? $this->getGroupedProductInfo($product)
|
||||
: null
|
||||
),
|
||||
|
||||
/* bundle product */
|
||||
$this->mergeWhen(
|
||||
$productTypeInstance instanceof \Webkul\Product\Type\Bundle,
|
||||
$product->type == 'bundle'
|
||||
? $this->getBundleProductInfo($product)
|
||||
: null
|
||||
),
|
||||
|
||||
/* configurable product */
|
||||
$this->mergeWhen(
|
||||
$productTypeInstance instanceof \Webkul\Product\Type\Configurable,
|
||||
$product->type == 'configurable'
|
||||
? $this->getConfigurableProductInfo($product)
|
||||
: null
|
||||
),
|
||||
|
||||
/* downloadable product */
|
||||
$this->mergeWhen(
|
||||
$productTypeInstance instanceof \Webkul\Product\Type\Downloadable,
|
||||
$product->type == 'downloadable'
|
||||
? $this->getDownloadableProductInfo($product)
|
||||
: null
|
||||
),
|
||||
|
||||
/* booking product */
|
||||
$this->mergeWhen(
|
||||
$product->type == 'booking',
|
||||
$product->type == 'booking'
|
||||
? $this->getBookingProductInfo($product)
|
||||
: null
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get grouped product's extra information.
|
||||
*
|
||||
* @param \Webkul\Product\Models\Product
|
||||
* @return array
|
||||
*/
|
||||
private function getGroupedProductInfo($product)
|
||||
{
|
||||
return [
|
||||
'grouped_products' => $product->grouped_products->map(function($groupedProduct) {
|
||||
$associatedProduct = $groupedProduct->associated_product;
|
||||
|
||||
$data = $associatedProduct->toArray();
|
||||
|
||||
return array_merge($data, [
|
||||
'qty' => $groupedProduct->qty,
|
||||
'isSaleable' => $associatedProduct->getTypeInstance()->isSaleable(),
|
||||
'formated_price' => $associatedProduct->getTypeInstance()->getPriceHtml(),
|
||||
'show_quantity_changer' => $associatedProduct->getTypeInstance()->showQuantityBox(),
|
||||
]);
|
||||
})
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get bundle product's extra information.
|
||||
*
|
||||
* @param \Webkul\Product\Models\Product
|
||||
* @return array
|
||||
*/
|
||||
private function getBundleProductInfo($product)
|
||||
{
|
||||
return [
|
||||
'currency_options' => core()->getAccountJsSymbols(),
|
||||
'bundle_options' => app('Webkul\Product\Helpers\BundleOption')->getBundleConfig($product)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get configurable product's extra information.
|
||||
*
|
||||
* @param \Webkul\Product\Models\Product
|
||||
* @return array
|
||||
*/
|
||||
private function getConfigurableProductInfo($product)
|
||||
{
|
||||
return [
|
||||
'variants' => $product->variants
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get downloadable product's extra information.
|
||||
*
|
||||
* @param \Webkul\Product\Models\Product
|
||||
* @return array
|
||||
*/
|
||||
private function getDownloadableProductInfo($product)
|
||||
{
|
||||
return [
|
||||
'downloadable_links' => $product->downloadable_links->map(function ($downloadableLink) {
|
||||
$data = $downloadableLink->toArray();
|
||||
|
||||
if (isset($data['sample_file'])) {
|
||||
$data['price'] = core()->currency($downloadableLink->price);
|
||||
$data['sample_download_url'] = route('shop.downloadable.download_sample', ['type' => 'link', 'id' => $downloadableLink['id']]);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}),
|
||||
|
||||
'downloadable_samples' => $product->downloadable_samples->map(function ($downloadableSample) {
|
||||
$sample = $downloadableSample->toArray();
|
||||
$data = $sample;
|
||||
$data['download_url'] = route('shop.downloadable.download_sample', ['type' => 'sample', 'id' => $sample['id']]);
|
||||
return $data;
|
||||
})
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get booking product's extra information.
|
||||
*
|
||||
* @param \Webkul\Product\Models\Product
|
||||
* @return array
|
||||
*/
|
||||
private function getBookingProductInfo($product)
|
||||
{
|
||||
$bookingProduct = app('\Webkul\BookingProduct\Repositories\BookingProductRepository')->findOneByField('product_id', $product->id);
|
||||
|
||||
$data['slot_index_route'] = route('booking_product.slots.index', $bookingProduct->id);
|
||||
|
||||
if ($bookingProduct->type == 'appointment') {
|
||||
$bookingSlotHelper = app('\Webkul\BookingProduct\Helpers\AppointmentSlot');
|
||||
|
||||
$data['today_slots_html'] = $bookingSlotHelper->getTodaySlotsHtml($bookingProduct);
|
||||
$data['week_slot_durations'] = $bookingSlotHelper->getWeekSlotDurations($bookingProduct);
|
||||
$data['appointment_slot'] = $bookingProduct->appointment_slot;
|
||||
}
|
||||
|
||||
if ($bookingProduct->type == 'event') {
|
||||
$bookingSlotHelper = app('\Webkul\BookingProduct\Helpers\EventTicket');
|
||||
|
||||
$data['tickets'] = $bookingSlotHelper->getTickets($bookingProduct);
|
||||
$data['event_date'] = $bookingSlotHelper->getEventDate($bookingProduct);
|
||||
}
|
||||
|
||||
if ($bookingProduct->type == 'rental') {
|
||||
$data['renting_type'] = $bookingProduct->rental_slot->renting_type;
|
||||
}
|
||||
|
||||
if ($bookingProduct->type == 'table') {
|
||||
$bookingSlotHelper = app('\Webkul\BookingProduct\Helpers\TableSlot');
|
||||
|
||||
$data['today_slots_html'] = $bookingSlotHelper->getTodaySlotsHtml($bookingProduct);
|
||||
$data['week_slot_durations'] = $bookingSlotHelper->getWeekSlotDurations($bookingProduct);
|
||||
$data['table_slot'] = $bookingProduct->table_slot;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Catalog;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ProductImage extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'path' => $this->path,
|
||||
'url' => $this->url,
|
||||
'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)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Catalog;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Webkul\API\Http\Resources\Customer\Customer as CustomerResource;
|
||||
|
||||
class ProductReview extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'rating' => number_format($this->rating, 1, '.', ''),
|
||||
'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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Catalog;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ProductVideo extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'type' => $this->type,
|
||||
'url' => $this->url
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,100 +0,0 @@
|
|||
<?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;
|
||||
use Webkul\Tax\Helpers\Tax;
|
||||
|
||||
class Cart extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request): array
|
||||
{
|
||||
$taxes = Tax::getTaxRatesWithAmount($this, false);
|
||||
$baseTaxes = Tax::getTaxRatesWithAmount($this, true);
|
||||
|
||||
$formatedTaxes = $this->formatTaxAmounts($taxes, false);
|
||||
$formatedBaseTaxes = $this->formatTaxAmounts($baseTaxes, true);
|
||||
|
||||
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_amount,
|
||||
'formated_discount' => core()->formatPrice($this->discount_amount, $this->cart_currency_code),
|
||||
'base_discount' => $this->base_discount_amount,
|
||||
'formated_base_discount' => core()->formatBasePrice($this->base_discount_amount),
|
||||
'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,
|
||||
'taxes' => json_encode($taxes, JSON_FORCE_OBJECT),
|
||||
'formated_taxes' => json_encode($formatedTaxes, JSON_FORCE_OBJECT),
|
||||
'base_taxes' => json_encode($baseTaxes, JSON_FORCE_OBJECT),
|
||||
'formated_base_taxes' => json_encode($formatedBaseTaxes, JSON_FORCE_OBJECT),
|
||||
'formated_discounted_sub_total' => core()->formatPrice($this->sub_total - $this->discount_amount, $this->cart_currency_code),
|
||||
'formated_base_discounted_sub_total' => core()->formatPrice($this->base_sub_total - $this->base_discount_amount, $this->cart_currency_code),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $taxes
|
||||
* @param bool $isBase
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function formatTaxAmounts(array $taxes, bool $isBase = false): array
|
||||
{
|
||||
$result = [];
|
||||
|
||||
foreach ($taxes as $taxRate => $taxAmount) {
|
||||
if ($isBase === true) {
|
||||
$result[$taxRate] = core()->formatBasePrice($taxAmount);
|
||||
} else {
|
||||
$result[$taxRate] = core()->formatPrice($taxAmount, $this->cart_currency_code);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
<?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' => core()->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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
<?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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
<?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
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
<?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
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Core;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Webkul\API\Http\Resources\Core\Locale as LocaleResource;
|
||||
use Webkul\API\Http\Resources\Core\Currency as CurrencyResource;
|
||||
use Webkul\API\Http\Resources\Catalog\Category as CategoryResource;
|
||||
|
||||
class Channel extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'code' => $this->code,
|
||||
'name' => $this->name,
|
||||
'description' => $this->description,
|
||||
'timezone' => $this->timezone,
|
||||
'theme' => $this->theme,
|
||||
'home_page_content' => $this->home_page_content,
|
||||
'footer_content' => $this->footer_content,
|
||||
'hostname' => $this->hostname,
|
||||
'logo' => $this->logo,
|
||||
'logo_url' => $this->logo_url,
|
||||
'favicon' => $this->favicon,
|
||||
'favicon_url' => $this->favicon_url,
|
||||
'default_locale' => $this->when($this->default_locale_id, new LocaleResource($this->default_locale)),
|
||||
'base_currency' => $this->when($this->default_currency_id, new CurrencyResource($this->default_currency)),
|
||||
'root_category_id' => $this->root_category_id,
|
||||
'root_category' => $this->when($this->root_category_id, new CategoryResource($this->root_category)),
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
<?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
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Core;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class Currency extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'code' => $this->code,
|
||||
'name' => $this->name,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Core;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class Locale extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'code' => $this->code,
|
||||
'name' => $this->name,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Core;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class Slider extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'image_url' => $this->image_url,
|
||||
'content' => $this->content
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Customer;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class Customer extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'email' => $this->email,
|
||||
'first_name' => $this->first_name,
|
||||
'last_name' => $this->last_name,
|
||||
'name' => $this->name,
|
||||
'gender' => $this->gender,
|
||||
'date_of_birth' => $this->date_of_birth,
|
||||
'phone' => $this->phone,
|
||||
'status' => $this->status,
|
||||
'group' => $this->when($this->customer_group_id, new CustomerGroup($this->group)),
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Customer;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class CustomerAddress extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'first_name' => $this->first_name,
|
||||
'last_name' => $this->last_name,
|
||||
'company_name' => $this->company_name,
|
||||
'vat_id' => $this->vat_id,
|
||||
'address1' => explode(PHP_EOL, $this->address1),
|
||||
'country' => $this->country,
|
||||
'country_name' => core()->country_name($this->country),
|
||||
'state' => $this->state,
|
||||
'city' => $this->city,
|
||||
'postcode' => $this->postcode,
|
||||
'phone' => $this->phone,
|
||||
'is_default' => $this->default_address,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Customer;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class CustomerGroup extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Customer;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Webkul\API\Http\Resources\Catalog\Product as ProductResource;
|
||||
|
||||
class Wishlist extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'product' => new ProductResource($this->product),
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Inventory;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class InventorySource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'code' => $this->code,
|
||||
'name' => $this->name,
|
||||
'description' => $this->description,
|
||||
'contact_name' => $this->contact_name,
|
||||
'contact_email' => $this->contact_email,
|
||||
'contact_number' => $this->contact_number,
|
||||
'contact_fax' => $this->contact_fax,
|
||||
'country' => $this->country,
|
||||
'state' => $this->state,
|
||||
'city' => $this->city,
|
||||
'street' => $this->street,
|
||||
'postcode' => $this->postcode,
|
||||
'priority' => $this->priority,
|
||||
'latitude' => $this->latitude,
|
||||
'longitude' => $this->collongitudeongitudeuntry,
|
||||
'status' => $this->status,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Sales;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class Invoice extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'state' => $this->state,
|
||||
'email_sent' => $this->email_sent,
|
||||
'total_qty' => $this->total_qty,
|
||||
'base_currency_code' => $this->base_currency_code,
|
||||
'channel_currency_code' => $this->channel_currency_code,
|
||||
'order_currency_code' => $this->order_currency_code,
|
||||
'sub_total' => $this->sub_total,
|
||||
'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
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Sales;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class InvoiceItem extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
// '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),
|
||||
'child' => new self($this->child),
|
||||
'children' => Self::collection($this->children)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,111 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Sales;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Webkul\API\Http\Resources\Core\Channel as ChannelResource;
|
||||
use Webkul\API\Http\Resources\Customer\Customer as CustomerResource;
|
||||
|
||||
class Order extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'increment_id' => $this->increment_id,
|
||||
'status' => $this->status,
|
||||
'status_label' => $this->status_label,
|
||||
'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,
|
||||
'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,
|
||||
'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,
|
||||
'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),
|
||||
'items' => OrderItem::collection($this->items),
|
||||
'invoices' => Invoice::collection($this->invoices),
|
||||
'shipments' => Shipment::collection($this->shipments),
|
||||
'updated_at' => $this->updated_at,
|
||||
'created_at' => $this->created_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Sales;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class OrderAddress extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'email' => $this->email,
|
||||
'first_name' => $this->first_name,
|
||||
'last_name' => $this->last_name,
|
||||
'address1' => explode(PHP_EOL, $this->address1),
|
||||
'country' => $this->country,
|
||||
'country_name' => core()->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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,87 +0,0 @@
|
|||
<?php
|
||||
|
||||
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
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'sku' => $this->sku,
|
||||
'type' => $this->type,
|
||||
'name' => $this->name,
|
||||
'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),
|
||||
'downloadable_links' => $this->downloadable_link_purchased,
|
||||
'additional' => is_array($this->resource->additional)
|
||||
? $this->resource->additional
|
||||
: json_decode($this->resource->additional, true),
|
||||
'child' => new self($this->child),
|
||||
'children' => Self::collection($this->children)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Sales;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class OrderTransaction extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'transaction_id' => $this->transaction_id,
|
||||
'status' => $this->status,
|
||||
'type' => $this->type,
|
||||
'payment_method' => $this->payment_method,
|
||||
'data' => $this->data,
|
||||
'updated_at' => $this->updated_at,
|
||||
'created_at' => $this->created_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Sales;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Webkul\API\Http\Resources\Customer\Customer as CustomerResource;
|
||||
use Webkul\API\Http\Resources\Inventory\InventorySource as InventorySourceResource;
|
||||
|
||||
class Shipment extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'status' => $this->status,
|
||||
'total_qty' => $this->total_qty,
|
||||
'total_weight' => $this->total_weight,
|
||||
'carrier_code' => $this->carrier_code,
|
||||
'carrier_title' => $this->carrier_title,
|
||||
'track_number' => $this->track_number,
|
||||
'email_sent' => $this->email_sent,
|
||||
'customer' => $this->when($this->customer_id, new CustomerResource($this->customer)),
|
||||
'inventory_source' => $this->when($this->inventory_source_id, new InventorySourceResource($this->inventory_source)),
|
||||
'items' => ShipmentItem::collection($this->items),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Http\Resources\Sales;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ShipmentItem extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'description' => $this->description,
|
||||
'sku' => $this->sku,
|
||||
'qty' => $this->qty,
|
||||
'weight' => $this->weight,
|
||||
'price' => $this->price,
|
||||
'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)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,348 +0,0 @@
|
|||
<?php
|
||||
|
||||
// Controllers
|
||||
use Webkul\API\Http\Controllers\Shop\AddressController;
|
||||
use Webkul\API\Http\Controllers\Shop\CartController;
|
||||
use Webkul\API\Http\Controllers\Shop\CategoryController;
|
||||
use Webkul\API\Http\Controllers\Shop\CheckoutController;
|
||||
use Webkul\API\Http\Controllers\Shop\CoreController;
|
||||
use Webkul\API\Http\Controllers\Shop\CustomerController;
|
||||
use Webkul\API\Http\Controllers\Shop\ForgotPasswordController;
|
||||
use Webkul\API\Http\Controllers\Shop\InvoiceController;
|
||||
use Webkul\API\Http\Controllers\Shop\OrderController;
|
||||
use Webkul\API\Http\Controllers\Shop\ProductController;
|
||||
use Webkul\API\Http\Controllers\Shop\ResourceController;
|
||||
use Webkul\API\Http\Controllers\Shop\ReviewController;
|
||||
use Webkul\API\Http\Controllers\Shop\SessionController;
|
||||
use Webkul\API\Http\Controllers\Shop\TransactionController;
|
||||
use Webkul\API\Http\Controllers\Shop\WishlistController;
|
||||
|
||||
// Resources
|
||||
use Webkul\API\Http\Resources\Catalog\Attribute;
|
||||
use Webkul\API\Http\Resources\Catalog\AttributeFamily;
|
||||
use Webkul\API\Http\Resources\Catalog\Category;
|
||||
use Webkul\API\Http\Resources\Catalog\ProductReview;
|
||||
use Webkul\API\Http\Resources\Core\Channel;
|
||||
use Webkul\API\Http\Resources\Core\Country;
|
||||
use Webkul\API\Http\Resources\Core\Currency;
|
||||
use Webkul\API\Http\Resources\Core\Locale;
|
||||
use Webkul\API\Http\Resources\Core\Slider;
|
||||
use Webkul\API\Http\Resources\Customer\Customer;
|
||||
use Webkul\API\Http\Resources\Customer\CustomerAddress;
|
||||
use Webkul\API\Http\Resources\Customer\Wishlist;
|
||||
use Webkul\API\Http\Resources\Sales\Invoice;
|
||||
use Webkul\API\Http\Resources\Sales\Order;
|
||||
use Webkul\API\Http\Resources\Sales\OrderTransaction;
|
||||
use Webkul\API\Http\Resources\Sales\Shipment;
|
||||
|
||||
// Repositories
|
||||
use Webkul\Attribute\Repositories\AttributeRepository;
|
||||
use Webkul\Attribute\Repositories\AttributeFamilyRepository;
|
||||
use Webkul\Category\Repositories\CategoryRepository;
|
||||
use Webkul\Core\Repositories\ChannelRepository;
|
||||
use Webkul\Core\Repositories\CountryRepository;
|
||||
use Webkul\Core\Repositories\CurrencyRepository;
|
||||
use Webkul\Core\Repositories\LocaleRepository;
|
||||
use Webkul\Core\Repositories\SliderRepository;
|
||||
use Webkul\Customer\Repositories\CustomerRepository;
|
||||
use Webkul\Customer\Repositories\CustomerAddressRepository;
|
||||
use Webkul\Customer\Repositories\WishlistRepository;
|
||||
use Webkul\Product\Repositories\ProductReviewRepository;
|
||||
use Webkul\Sales\Repositories\InvoiceRepository;
|
||||
use Webkul\Sales\Repositories\OrderRepository;
|
||||
use Webkul\Sales\Repositories\OrderTransactionRepository;
|
||||
use Webkul\Sales\Repositories\ShipmentRepository;
|
||||
|
||||
Route::group(['prefix' => 'api'], function ($router) {
|
||||
|
||||
Route::group(['middleware' => ['locale', 'theme', 'currency']], function ($router) {
|
||||
//Currency and Locale switcher
|
||||
Route::get('switch-currency', [CoreController::class, 'switchCurrency']);
|
||||
|
||||
Route::get('switch-locale', [CoreController::class, 'switchLocale']);
|
||||
|
||||
|
||||
//Category routes
|
||||
Route::get('categories', [ResourceController::class, 'index'])->defaults('_config', [
|
||||
'repository' => CategoryRepository::class,
|
||||
'resource' => Category::class,
|
||||
]);
|
||||
|
||||
Route::get('descendant-categories', [CategoryController::class, 'index']);
|
||||
|
||||
Route::get('categories/{id}', [ResourceController::class, 'get'])->defaults('_config', [
|
||||
'repository' => CategoryRepository::class,
|
||||
'resource' => Category::class,
|
||||
]);
|
||||
|
||||
|
||||
//Attribute routes
|
||||
Route::get('attributes', [ResourceController::class, 'index'])->defaults('_config', [
|
||||
'repository' => AttributeRepository::class,
|
||||
'resource' => Attribute::class,
|
||||
]);
|
||||
|
||||
Route::get('attributes/{id}', [ResourceController::class, 'get'])->defaults('_config', [
|
||||
'repository' => AttributeRepository::class,
|
||||
'resource' => Attribute::class,
|
||||
]);
|
||||
|
||||
|
||||
//AttributeFamily routes
|
||||
Route::get('families', [ResourceController::class, 'index'])->defaults('_config', [
|
||||
'repository' => AttributeFamilyRepository::class,
|
||||
'resource' => AttributeFamily::class,
|
||||
]);
|
||||
|
||||
Route::get('families/{id}', [ResourceController::class, 'get'])->defaults('_config', [
|
||||
'repository' => AttributeFamilyRepository::class,
|
||||
'resource' => AttributeFamily::class,
|
||||
]);
|
||||
|
||||
|
||||
//Product routes
|
||||
Route::get('products', [ProductController::class, 'index']);
|
||||
|
||||
Route::get('products/{id}', [ProductController::class, 'get']);
|
||||
|
||||
Route::get('product-additional-information/{id}', [ProductController::class, 'additionalInformation']);
|
||||
|
||||
Route::get('product-configurable-config/{id}', [ProductController::class, 'configurableConfig']);
|
||||
|
||||
|
||||
//Product Review routes
|
||||
Route::get('reviews', [ResourceController::class, 'index'])->defaults('_config', [
|
||||
'repository' => ProductReviewRepository::class,
|
||||
'resource' => ProductReview::class,
|
||||
]);
|
||||
|
||||
Route::get('reviews/{id}', [ResourceController::class, 'get'])->defaults('_config', [
|
||||
'repository' => ProductReviewRepository::class,
|
||||
'resource' => ProductReview::class,
|
||||
]);
|
||||
|
||||
Route::post('reviews/{id}/create', [ReviewController::class, 'store']);
|
||||
|
||||
Route::delete('reviews/{id}', [ResourceController::class, 'destroy'])->defaults('_config', [
|
||||
'repository' => ProductReviewRepository::class,
|
||||
'resource' => ProductReview::class,
|
||||
'authorization_required' => true
|
||||
]);
|
||||
|
||||
|
||||
//Channel routes
|
||||
Route::get('channels', [ResourceController::class, 'index'])->defaults('_config', [
|
||||
'repository' => ChannelRepository::class,
|
||||
'resource' => Channel::class,
|
||||
]);
|
||||
|
||||
Route::get('channels/{id}', [ResourceController::class, 'get'])->defaults('_config', [
|
||||
'repository' => ChannelRepository::class,
|
||||
'resource' => Channel::class,
|
||||
]);
|
||||
|
||||
|
||||
//Locale routes
|
||||
Route::get('locales', [ResourceController::class, 'index'])->defaults('_config', [
|
||||
'repository' => LocaleRepository::class,
|
||||
'resource' => Locale::class,
|
||||
]);
|
||||
|
||||
Route::get('locales/{id}', [ResourceController::class, 'get'])->defaults('_config', [
|
||||
'repository' => LocaleRepository::class,
|
||||
'resource' => Locale::class,
|
||||
]);
|
||||
|
||||
|
||||
//Country routes
|
||||
Route::get('countries', [ResourceController::class, 'index'])->defaults('_config', [
|
||||
'repository' => CountryRepository::class,
|
||||
'resource' => Country::class,
|
||||
]);
|
||||
|
||||
Route::get('countries/{id}', [ResourceController::class, 'get'])->defaults('_config', [
|
||||
'repository' => CountryRepository::class,
|
||||
'resource' => Country::class,
|
||||
]);
|
||||
|
||||
Route::get('country-states', [CoreController::class, 'getCountryStateGroup']);
|
||||
|
||||
|
||||
//Slider routes
|
||||
Route::get('sliders', [ResourceController::class, 'index'])->defaults('_config', [
|
||||
'repository' => SliderRepository::class,
|
||||
'resource' => Slider::class,
|
||||
]);
|
||||
|
||||
Route::get('sliders/{id}', [ResourceController::class, 'get'])->defaults('_config', [
|
||||
'repository' => SliderRepository::class,
|
||||
'resource' => Slider::class,
|
||||
]);
|
||||
|
||||
|
||||
//Currency routes
|
||||
Route::get('currencies', [ResourceController::class, 'index'])->defaults('_config', [
|
||||
'repository' => CurrencyRepository::class,
|
||||
'resource' => Currency::class,
|
||||
]);
|
||||
|
||||
Route::get('currencies/{id}', [ResourceController::class, 'get'])->defaults('_config', [
|
||||
'repository' => CurrencyRepository::class,
|
||||
'resource' => Currency::class,
|
||||
]);
|
||||
|
||||
Route::get('config', [CoreController::class, 'getConfig']);
|
||||
|
||||
|
||||
//Customer routes
|
||||
Route::post('customer/login', [SessionController::class, 'create']);
|
||||
|
||||
Route::post('customer/forgot-password', [ForgotPasswordController::class, 'store']);
|
||||
|
||||
Route::get('customer/logout', [SessionController::class, 'destroy']);
|
||||
|
||||
Route::get('customer/get', [SessionController::class, 'get']);
|
||||
|
||||
Route::put('customer/profile', [SessionController::class, 'update']);
|
||||
|
||||
Route::post('customer/register', [CustomerController::class, 'create']);
|
||||
|
||||
Route::get('customers/{id}', [CustomerController::class, 'get'])->defaults('_config', [
|
||||
'repository' => CustomerRepository::class,
|
||||
'resource' => Customer::class,
|
||||
'authorization_required' => true
|
||||
]);
|
||||
|
||||
|
||||
//Customer Address routes
|
||||
Route::get('addresses', [AddressController::class, 'get'])->defaults('_config', [
|
||||
'authorization_required' => true
|
||||
]);
|
||||
|
||||
Route::get('addresses/{id}', [ResourceController::class, 'get'])->defaults('_config', [
|
||||
'repository' => CustomerAddressRepository::class,
|
||||
'resource' => CustomerAddress::class,
|
||||
'authorization_required' => true
|
||||
]);
|
||||
|
||||
Route::delete('addresses/{id}', [ResourceController::class, 'destroy'])->defaults('_config', [
|
||||
'repository' => CustomerAddressRepository::class,
|
||||
'resource' => CustomerAddress::class,
|
||||
'authorization_required' => true
|
||||
]);
|
||||
|
||||
Route::put('addresses/{id}', [AddressController::class, 'update'])->defaults('_config', [
|
||||
'authorization_required' => true
|
||||
]);
|
||||
|
||||
Route::post('addresses/create', [AddressController::class, 'store'])->defaults('_config', [
|
||||
'authorization_required' => true
|
||||
]);
|
||||
|
||||
|
||||
//Order routes
|
||||
Route::get('orders', [ResourceController::class, 'index'])->defaults('_config', [
|
||||
'repository' => OrderRepository::class,
|
||||
'resource' => Order::class,
|
||||
'authorization_required' => true
|
||||
]);
|
||||
|
||||
Route::get('orders/{id}', [ResourceController::class, 'get'])->defaults('_config', [
|
||||
'repository' => OrderRepository::class,
|
||||
'resource' => Order::class,
|
||||
'authorization_required' => true
|
||||
]);
|
||||
|
||||
Route::post('orders/{id}/cancel', [OrderController::class, 'cancel'])->defaults('_config', [
|
||||
'repository' => OrderRepository::class,
|
||||
'resource' => Order::class,
|
||||
'authorization_required' => true
|
||||
]);
|
||||
|
||||
//Invoice routes
|
||||
Route::get('invoices', [InvoiceController::class, 'index'])->defaults('_config', [
|
||||
'repository' => InvoiceRepository::class,
|
||||
'resource' => Invoice::class,
|
||||
'authorization_required' => true
|
||||
]);
|
||||
|
||||
Route::get('invoices/{id}', [InvoiceController::class, 'get'])->defaults('_config', [
|
||||
'repository' => InvoiceRepository::class,
|
||||
'resource' => Invoice::class,
|
||||
'authorization_required' => true
|
||||
]);
|
||||
|
||||
|
||||
//Shipment routes
|
||||
Route::get('shipments', [ResourceController::class, 'index'])->defaults('_config', [
|
||||
'repository' => ShipmentRepository::class,
|
||||
'resource' => Shipment::class,
|
||||
'authorization_required' => true
|
||||
]);
|
||||
|
||||
Route::get('shipments/{id}', [ResourceController::class, 'get'])->defaults('_config', [
|
||||
'repository' => ShipmentRepository::class,
|
||||
'resource' => Shipment::class,
|
||||
'authorization_required' => true
|
||||
]);
|
||||
|
||||
//Transaction routes
|
||||
Route::get('transactions', [TransactionController::class, 'index'])->defaults('_config', [
|
||||
'repository' => OrderTransactionRepository::class,
|
||||
'resource' => OrderTransaction::class,
|
||||
'authorization_required' => true
|
||||
]);
|
||||
|
||||
Route::get('transactions/{id}', [TransactionController::class, 'get'])->defaults('_config', [
|
||||
'repository' => OrderTransactionRepository::class,
|
||||
'resource' => OrderTransaction::class,
|
||||
'authorization_required' => true
|
||||
]);
|
||||
|
||||
//Wishlist routes
|
||||
Route::get('wishlist', [ResourceController::class, 'index'])->defaults('_config', [
|
||||
'repository' => WishlistRepository::class,
|
||||
'resource' => Wishlist::class,
|
||||
'authorization_required' => true
|
||||
]);
|
||||
|
||||
Route::delete('wishlist/{id}', [ResourceController::class, 'destroy'])->defaults('_config', [
|
||||
'repository' => WishlistRepository::class,
|
||||
'resource' => Wishlist::class,
|
||||
'authorization_required' => true
|
||||
]);
|
||||
|
||||
Route::get('move-to-cart/{id}', [WishlistController::class, 'moveToCart']);
|
||||
|
||||
Route::get('wishlist/add/{id}', [WishlistController::class, 'create']);
|
||||
|
||||
//Checkout routes
|
||||
Route::group(['prefix' => 'checkout'], function ($router) {
|
||||
Route::post('cart/add/{id}', [CartController::class, 'store']);
|
||||
|
||||
Route::get('cart', [CartController::class, 'get']);
|
||||
|
||||
Route::get('cart/empty', [CartController::class, 'destroy']);
|
||||
|
||||
Route::put('cart/update', [CartController::class, 'update']);
|
||||
|
||||
Route::get('cart/remove-item/{id}', [CartController::class, 'destroyItem']);
|
||||
|
||||
Route::post('cart/coupon', [CartController::class, 'applyCoupon']);
|
||||
|
||||
Route::delete('cart/coupon', [CartController::class, 'removeCoupon']);
|
||||
|
||||
Route::get('cart/move-to-wishlist/{id}', [CartController::class, 'moveToWishlist']);
|
||||
|
||||
Route::post('save-address', [CheckoutController::class, 'saveAddress']);
|
||||
|
||||
Route::post('save-shipping', [CheckoutController::class, 'saveShipping']);
|
||||
|
||||
Route::post('save-payment', [CheckoutController::class, 'savePayment']);
|
||||
|
||||
Route::post('check-minimum-order', [CheckoutController::class, 'checkMinimumOrder']);
|
||||
|
||||
Route::post('save-order', [CheckoutController::class, 'saveOrder']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class APIServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->loadRoutesFrom(__DIR__.'/../Http/routes.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\API\Providers;
|
||||
|
||||
use Webkul\Core\Providers\CoreModuleServiceProvider;
|
||||
|
||||
class ModuleServiceProvider extends CoreModuleServiceProvider
|
||||
{
|
||||
protected $models = [
|
||||
];
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
{
|
||||
"name": "bagisto/laravel-api",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Prashant Singh",
|
||||
"email": "prashant.singh852@webkul.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"bagisto/laravel-user": "dev-master",
|
||||
"bagisto/laravel-core": "dev-master",
|
||||
"bagisto/laravel-product": "dev-master",
|
||||
"bagisto/laravel-shop": "dev-master",
|
||||
"bagisto/laravel-category": "dev-master",
|
||||
"bagisto/laravel-tax": "dev-master",
|
||||
"bagisto/laravel-inventory": "dev-master",
|
||||
"bagisto/laravel-checkout": "dev-master"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Webkul\\API\\": "/"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Webkul\\API\\Providers\\APIServiceProvider"
|
||||
],
|
||||
"aliases": {}
|
||||
}
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
}
|
||||
|
|
@ -13,7 +13,6 @@ return [
|
|||
*/
|
||||
|
||||
\Webkul\Admin\Providers\ModuleServiceProvider::class,
|
||||
\Webkul\API\Providers\ModuleServiceProvider::class,
|
||||
\Webkul\Attribute\Providers\ModuleServiceProvider::class,
|
||||
\Webkul\BookingProduct\Providers\ModuleServiceProvider::class,
|
||||
\Webkul\CartRule\Providers\ModuleServiceProvider::class,
|
||||
|
|
|
|||
Loading…
Reference in New Issue