sarga/packages/Webkul/Shop/src/Http/Controllers/OnepageController.php

412 lines
11 KiB
PHP
Raw Normal View History

2018-09-13 11:10:45 +00:00
<?php
namespace Webkul\Shop\Http\Controllers;
2018-09-25 05:22:22 +00:00
use Illuminate\Support\Facades\Event;
2018-09-28 13:28:54 +00:00
use Webkul\Checkout\Facades\Cart;
use Webkul\Checkout\Http\Requests\CustomerAddressForm;
2019-10-18 13:13:38 +00:00
use Webkul\Customer\Repositories\CustomerRepository;
2022-02-01 11:14:16 +00:00
use Webkul\Payment\Facades\Payment;
use Webkul\Sales\Repositories\OrderRepository;
use Webkul\Shipping\Facades\Shipping;
use Webkul\Shop\Http\Controllers\Controller;
2018-09-13 11:10:45 +00:00
class OnepageController extends Controller
2018-09-13 11:10:45 +00:00
{
2018-09-19 06:58:15 +00:00
/**
* Create a new controller instance.
*
2020-03-05 13:37:08 +00:00
* @param \Webkul\Attribute\Repositories\OrderRepository $orderRepository
* @param \Webkul\Customer\Repositories\CustomerRepository $customerRepository
2018-09-19 06:58:15 +00:00
* @return void
*/
public function __construct(
protected OrderRepository $orderRepository,
protected CustomerRepository $customerRepository
)
{
2020-02-06 11:48:51 +00:00
parent::__construct();
2018-09-13 11:10:45 +00:00
}
/**
* Display a listing of the resource.
*
2019-10-15 13:35:46 +00:00
* @return \Illuminate\View\View
2022-02-01 11:14:16 +00:00
*/
2018-09-13 11:10:45 +00:00
public function index()
{
Event::dispatch('checkout.load.index');
if (
! auth()->guard('customer')->check()
&& ! core()->getConfigData('catalog.products.guest-checkout.allow-guest-checkout')
) {
2020-01-17 13:42:47 +00:00
return redirect()->route('customer.session.index');
}
if (
auth()->guard('customer')->check()
&& auth()->guard('customer')->user()->is_suspended
) {
session()->flash('warning', trans('shop::app.checkout.cart.suspended-account-message'));
return redirect()->route('shop.checkout.cart.index');
}
2020-03-02 08:08:51 +00:00
if (Cart::hasError()) {
2018-09-26 04:21:14 +00:00
return redirect()->route('shop.checkout.cart.index');
2020-03-02 08:08:51 +00:00
}
2018-09-26 04:21:14 +00:00
2019-06-28 14:18:52 +00:00
$cart = Cart::getCart();
2022-07-23 11:47:10 +00:00
2022-07-23 12:43:37 +00:00
if ($cart->applied_cart_rule_ids != '') {
2022-07-19 09:44:42 +00:00
session()->flash('success', trans('shop::app.checkout.cart.rule-applied'));
}
if (
(
! auth()->guard('customer')->check()
&& $cart->hasDownloadableItems()
)
|| (
! auth()->guard('customer')->check()
&& ! $cart->hasGuestCheckoutItems()
)
) {
2019-06-28 14:18:52 +00:00
return redirect()->route('customer.session.index');
2020-01-17 13:42:47 +00:00
}
2019-06-28 14:18:52 +00:00
2021-02-10 13:43:00 +00:00
$minimumOrderAmount = (float) core()->getConfigData('sales.orderSettings.minimum-order.minimum_order_amount') ?? 0;
2021-02-05 11:09:46 +00:00
if (! $cart->checkMinimumOrder()) {
session()->flash('warning', trans('shop::app.checkout.cart.minimum-order-message', ['amount' => core()->currency($minimumOrderAmount)]));
return redirect()->back();
}
Cart::collectTotals();
2019-06-28 14:18:52 +00:00
return view($this->_config['view'], compact('cart'));
2018-09-13 11:10:45 +00:00
}
2019-05-30 13:02:01 +00:00
/**
2022-02-01 11:14:16 +00:00
* Return order short summary.
2019-05-30 13:02:01 +00:00
*
2020-03-05 13:37:08 +00:00
* @return \Illuminate\Http\Response
2022-02-01 11:14:16 +00:00
*/
2019-05-30 13:02:01 +00:00
public function summary()
{
$cart = Cart::getCart();
return response()->json([
2020-03-04 06:32:53 +00:00
'html' => view('shop::checkout.total.summary', compact('cart'))->render(),
2020-02-27 08:03:03 +00:00
]);
2019-05-30 13:02:01 +00:00
}
2018-09-20 10:01:51 +00:00
/**
* Saves customer address.
*
2020-03-05 13:37:08 +00:00
* @param \Webkul\Checkout\Http\Requests\CustomerAddressForm $request
2018-09-20 10:01:51 +00:00
* @return \Illuminate\Http\Response
2022-02-01 11:14:16 +00:00
*/
2018-09-25 05:22:22 +00:00
public function saveAddress(CustomerAddressForm $request)
2018-09-20 10:01:51 +00:00
{
2022-02-01 11:14:16 +00:00
$data = $request->all();
2019-03-12 06:29:00 +00:00
if (
! auth()->guard('customer')->check()
&& ! Cart::getCart()->hasGuestCheckoutItems()
) {
2020-02-20 07:00:00 +00:00
return response()->json(['redirect_url' => route('customer.session.index')], 403);
}
2019-03-12 06:29:00 +00:00
$data['billing']['address1'] = implode(PHP_EOL, array_filter($data['billing']['address1']));
$data['shipping']['address1'] = implode(PHP_EOL, array_filter($data['shipping']['address1']));
if (
Cart::hasError()
|| ! Cart::saveCustomerAddress($data)
) {
2019-06-28 14:18:52 +00:00
return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403);
2022-02-01 11:14:16 +00:00
}
2019-06-28 14:18:52 +00:00
2022-02-01 11:14:16 +00:00
$cart = Cart::getCart();
2022-02-01 11:14:16 +00:00
Cart::collectTotals();
if ($cart->haveStockableItems()) {
if (! $rates = Shipping::collectRates()) {
return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403);
2019-06-28 14:18:52 +00:00
}
2022-02-01 11:14:16 +00:00
return response()->json($rates);
2019-06-28 14:18:52 +00:00
}
2022-02-01 11:14:16 +00:00
return response()->json(Payment::getSupportedPaymentMethods());
2018-09-20 10:01:51 +00:00
}
/**
* Saves shipping method.
*
* @return \Illuminate\Http\Response
2022-02-01 11:14:16 +00:00
*/
2018-09-20 10:01:51 +00:00
public function saveShipping()
{
2018-09-26 10:19:18 +00:00
$shippingMethod = request()->get('shipping_method');
if (
Cart::hasError()
|| ! $shippingMethod
|| ! Cart::saveShippingMethod($shippingMethod)
) {
return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403);
2020-02-20 07:05:51 +00:00
}
2018-09-26 10:19:18 +00:00
Cart::collectTotals();
return response()->json(Payment::getSupportedPaymentMethods());
2018-09-20 10:01:51 +00:00
}
/**
* Saves payment method.
*
2020-03-05 13:37:08 +00:00
* @return \Illuminate\Http\Response
2022-02-01 11:14:16 +00:00
*/
2018-09-25 05:22:22 +00:00
public function savePayment()
2018-09-20 10:01:51 +00:00
{
2018-09-26 10:19:18 +00:00
$payment = request()->get('payment');
if (
Cart::hasError()
|| ! $payment
|| ! Cart::savePaymentMethod($payment)
) {
return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403);
2020-02-20 07:05:51 +00:00
}
Cart::collectTotals();
2019-06-28 14:18:52 +00:00
2018-09-26 10:19:18 +00:00
$cart = Cart::getCart();
return response()->json([
Cart rule inside promotions, various improvements and fixes. (#964) * Some syntax issue fixes * Adding discount things inside promotions in admin * routes updated for creating discount rules * fixed customer profile redirect parameter issue * added cart and catalog rule routes to admin section * migrations for discount almost to be finished, final revision left * migrations for discounts complete * catalog rule form underway * catalog rule * Made some dynamic form fields in catalog rule create form * made some changes for custom validations used in ProductForm request class * working on prepopulating the values fields in conditions * need another revisit on discount rules tables and then prepare for actions * removed discounts table * catalog rule form changed to muliti attribute set for single condition * new icons added for promotion and customer note. new action for customer added to take notes on the customers * catalog and cart rule designs stable, now moving towards validations on client side and backend * catalog rules migrations added * catalog rule models added with contracts and proxies * fixed customer group bug in customer registration controller * fixed customer registration bug due to last fix * fixed product card image not found issue * catalog rule translations added * Added migrations for cart rules and catalog rule products their contracts and remaining necessary files related to them. * making cart attributes for cart rules * Added more fields for cart rules * working on conditions for cart rule form * minor changes in migrations related to price rules * currency and locale switcher now only available for a channel on storefront when more than on locale and currency are assigned to that channel * part of conditions on the cart rule form added * daily sync * cart rate migrations updated * Added select and multi select attributes options fetching with ajax on catalog rule form * changed some migrations and data being populated at runtime inside catalog rule form * catalog rule create complete, migrations changes, translations added * catalog rule edit form complete * catalog rule form complete, now moving towards catalog rule products * added delete functionality for catalog rules * added cart rule preferences for coupon codes * cart rule submission problem due to repository issue * Cart rule form and migrations complete * Models and Repositories updated for cart rule usage * base sync with master * designing process to get suitable discount rules * cart rule form completed * added helpers in cart and discount to apply rules on cart at checkout or not * cart rule coupon implementation in progress for discount coupon in shop checkout pages * cart rules working * added coupon box on checkout screen * removed the conditions empty bug * Nearing to completion of coupon based rules * made some changes in cart rule coupon application on checkout related to new designs * some bug fixes * calculation for automatic cart rules complete * non couponable cart rules implemented, now moving on to binding them on frontend * some conditions improvements in couponable cart rules * some bug fixes * removed some bugs from summary blade for cart rule * added the table for cart rule cart for managing rules with cart and removed various bug fixes * some bug fixes * Removed bugs and added coupon based cart rule removal functionality * some bug fixes * cart rule labels refactoring in midway * Cart rule labels bug fixed * removed margin classes from shop to UI * Refactoring cart rule on front end * added checks * Discount rule implemented. * cart rule bug fixes * provision to remove the couponable and non couponable rule had been added * Cart rule frontend work done * altered some frontend variables on onepage checkout * Altered cart rules to some extent
2019-06-10 07:49:05 +00:00
'jump_to_section' => 'review',
2020-03-04 06:32:53 +00:00
'html' => view('shop::checkout.onepage.review', compact('cart'))->render(),
Cart rule inside promotions, various improvements and fixes. (#964) * Some syntax issue fixes * Adding discount things inside promotions in admin * routes updated for creating discount rules * fixed customer profile redirect parameter issue * added cart and catalog rule routes to admin section * migrations for discount almost to be finished, final revision left * migrations for discounts complete * catalog rule form underway * catalog rule * Made some dynamic form fields in catalog rule create form * made some changes for custom validations used in ProductForm request class * working on prepopulating the values fields in conditions * need another revisit on discount rules tables and then prepare for actions * removed discounts table * catalog rule form changed to muliti attribute set for single condition * new icons added for promotion and customer note. new action for customer added to take notes on the customers * catalog and cart rule designs stable, now moving towards validations on client side and backend * catalog rules migrations added * catalog rule models added with contracts and proxies * fixed customer group bug in customer registration controller * fixed customer registration bug due to last fix * fixed product card image not found issue * catalog rule translations added * Added migrations for cart rules and catalog rule products their contracts and remaining necessary files related to them. * making cart attributes for cart rules * Added more fields for cart rules * working on conditions for cart rule form * minor changes in migrations related to price rules * currency and locale switcher now only available for a channel on storefront when more than on locale and currency are assigned to that channel * part of conditions on the cart rule form added * daily sync * cart rate migrations updated * Added select and multi select attributes options fetching with ajax on catalog rule form * changed some migrations and data being populated at runtime inside catalog rule form * catalog rule create complete, migrations changes, translations added * catalog rule edit form complete * catalog rule form complete, now moving towards catalog rule products * added delete functionality for catalog rules * added cart rule preferences for coupon codes * cart rule submission problem due to repository issue * Cart rule form and migrations complete * Models and Repositories updated for cart rule usage * base sync with master * designing process to get suitable discount rules * cart rule form completed * added helpers in cart and discount to apply rules on cart at checkout or not * cart rule coupon implementation in progress for discount coupon in shop checkout pages * cart rules working * added coupon box on checkout screen * removed the conditions empty bug * Nearing to completion of coupon based rules * made some changes in cart rule coupon application on checkout related to new designs * some bug fixes * calculation for automatic cart rules complete * non couponable cart rules implemented, now moving on to binding them on frontend * some conditions improvements in couponable cart rules * some bug fixes * removed some bugs from summary blade for cart rule * added the table for cart rule cart for managing rules with cart and removed various bug fixes * some bug fixes * Removed bugs and added coupon based cart rule removal functionality * some bug fixes * cart rule labels refactoring in midway * Cart rule labels bug fixed * removed margin classes from shop to UI * Refactoring cart rule on front end * added checks * Discount rule implemented. * cart rule bug fixes * provision to remove the couponable and non couponable rule had been added * Cart rule frontend work done * altered some frontend variables on onepage checkout * Altered cart rules to some extent
2019-06-10 07:49:05 +00:00
]);
2018-09-20 10:01:51 +00:00
}
2018-10-04 06:42:06 +00:00
/**
* Saves order.
*
* @return \Illuminate\Http\Response
2022-02-01 11:14:16 +00:00
*/
2018-10-04 06:42:06 +00:00
public function saveOrder()
{
2020-02-20 07:05:51 +00:00
if (Cart::hasError()) {
2018-10-05 11:59:43 +00:00
return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403);
2020-02-20 07:05:51 +00:00
}
2018-10-05 11:59:43 +00:00
2018-10-04 06:42:06 +00:00
Cart::collectTotals();
$this->validateOrder();
2018-11-16 10:11:08 +00:00
$cart = Cart::getCart();
2019-01-15 11:54:41 +00:00
if ($redirectUrl = Payment::getRedirectUrl($cart)) {
2018-11-16 10:11:08 +00:00
return response()->json([
2020-02-20 07:05:51 +00:00
'success' => true,
2020-03-04 06:32:53 +00:00
'redirect_url' => $redirectUrl,
Cart rule inside promotions, various improvements and fixes. (#964) * Some syntax issue fixes * Adding discount things inside promotions in admin * routes updated for creating discount rules * fixed customer profile redirect parameter issue * added cart and catalog rule routes to admin section * migrations for discount almost to be finished, final revision left * migrations for discounts complete * catalog rule form underway * catalog rule * Made some dynamic form fields in catalog rule create form * made some changes for custom validations used in ProductForm request class * working on prepopulating the values fields in conditions * need another revisit on discount rules tables and then prepare for actions * removed discounts table * catalog rule form changed to muliti attribute set for single condition * new icons added for promotion and customer note. new action for customer added to take notes on the customers * catalog and cart rule designs stable, now moving towards validations on client side and backend * catalog rules migrations added * catalog rule models added with contracts and proxies * fixed customer group bug in customer registration controller * fixed customer registration bug due to last fix * fixed product card image not found issue * catalog rule translations added * Added migrations for cart rules and catalog rule products their contracts and remaining necessary files related to them. * making cart attributes for cart rules * Added more fields for cart rules * working on conditions for cart rule form * minor changes in migrations related to price rules * currency and locale switcher now only available for a channel on storefront when more than on locale and currency are assigned to that channel * part of conditions on the cart rule form added * daily sync * cart rate migrations updated * Added select and multi select attributes options fetching with ajax on catalog rule form * changed some migrations and data being populated at runtime inside catalog rule form * catalog rule create complete, migrations changes, translations added * catalog rule edit form complete * catalog rule form complete, now moving towards catalog rule products * added delete functionality for catalog rules * added cart rule preferences for coupon codes * cart rule submission problem due to repository issue * Cart rule form and migrations complete * Models and Repositories updated for cart rule usage * base sync with master * designing process to get suitable discount rules * cart rule form completed * added helpers in cart and discount to apply rules on cart at checkout or not * cart rule coupon implementation in progress for discount coupon in shop checkout pages * cart rules working * added coupon box on checkout screen * removed the conditions empty bug * Nearing to completion of coupon based rules * made some changes in cart rule coupon application on checkout related to new designs * some bug fixes * calculation for automatic cart rules complete * non couponable cart rules implemented, now moving on to binding them on frontend * some conditions improvements in couponable cart rules * some bug fixes * removed some bugs from summary blade for cart rule * added the table for cart rule cart for managing rules with cart and removed various bug fixes * some bug fixes * Removed bugs and added coupon based cart rule removal functionality * some bug fixes * cart rule labels refactoring in midway * Cart rule labels bug fixed * removed margin classes from shop to UI * Refactoring cart rule on front end * added checks * Discount rule implemented. * cart rule bug fixes * provision to remove the couponable and non couponable rule had been added * Cart rule frontend work done * altered some frontend variables on onepage checkout * Altered cart rules to some extent
2019-06-10 07:49:05 +00:00
]);
2018-11-16 10:11:08 +00:00
}
2018-10-05 06:18:58 +00:00
$order = $this->orderRepository->create(Cart::prepareDataForOrder());
Cart::deActivateCart();
2018-10-04 06:42:06 +00:00
2021-09-09 14:00:01 +00:00
Cart::activateCartIfSessionHasDeactivatedCartId();
2018-10-04 06:42:06 +00:00
session()->flash('order', $order);
return response()->json([
Cart rule inside promotions, various improvements and fixes. (#964) * Some syntax issue fixes * Adding discount things inside promotions in admin * routes updated for creating discount rules * fixed customer profile redirect parameter issue * added cart and catalog rule routes to admin section * migrations for discount almost to be finished, final revision left * migrations for discounts complete * catalog rule form underway * catalog rule * Made some dynamic form fields in catalog rule create form * made some changes for custom validations used in ProductForm request class * working on prepopulating the values fields in conditions * need another revisit on discount rules tables and then prepare for actions * removed discounts table * catalog rule form changed to muliti attribute set for single condition * new icons added for promotion and customer note. new action for customer added to take notes on the customers * catalog and cart rule designs stable, now moving towards validations on client side and backend * catalog rules migrations added * catalog rule models added with contracts and proxies * fixed customer group bug in customer registration controller * fixed customer registration bug due to last fix * fixed product card image not found issue * catalog rule translations added * Added migrations for cart rules and catalog rule products their contracts and remaining necessary files related to them. * making cart attributes for cart rules * Added more fields for cart rules * working on conditions for cart rule form * minor changes in migrations related to price rules * currency and locale switcher now only available for a channel on storefront when more than on locale and currency are assigned to that channel * part of conditions on the cart rule form added * daily sync * cart rate migrations updated * Added select and multi select attributes options fetching with ajax on catalog rule form * changed some migrations and data being populated at runtime inside catalog rule form * catalog rule create complete, migrations changes, translations added * catalog rule edit form complete * catalog rule form complete, now moving towards catalog rule products * added delete functionality for catalog rules * added cart rule preferences for coupon codes * cart rule submission problem due to repository issue * Cart rule form and migrations complete * Models and Repositories updated for cart rule usage * base sync with master * designing process to get suitable discount rules * cart rule form completed * added helpers in cart and discount to apply rules on cart at checkout or not * cart rule coupon implementation in progress for discount coupon in shop checkout pages * cart rules working * added coupon box on checkout screen * removed the conditions empty bug * Nearing to completion of coupon based rules * made some changes in cart rule coupon application on checkout related to new designs * some bug fixes * calculation for automatic cart rules complete * non couponable cart rules implemented, now moving on to binding them on frontend * some conditions improvements in couponable cart rules * some bug fixes * removed some bugs from summary blade for cart rule * added the table for cart rule cart for managing rules with cart and removed various bug fixes * some bug fixes * Removed bugs and added coupon based cart rule removal functionality * some bug fixes * cart rule labels refactoring in midway * Cart rule labels bug fixed * removed margin classes from shop to UI * Refactoring cart rule on front end * added checks * Discount rule implemented. * cart rule bug fixes * provision to remove the couponable and non couponable rule had been added * Cart rule frontend work done * altered some frontend variables on onepage checkout * Altered cart rules to some extent
2019-06-10 07:49:05 +00:00
'success' => true,
]);
2018-10-04 06:42:06 +00:00
}
/**
2022-02-01 11:14:16 +00:00
* Order success page.
2018-10-04 06:42:06 +00:00
*
* @return \Illuminate\Http\Response
2022-02-01 11:14:16 +00:00
*/
2018-10-04 06:42:06 +00:00
public function success()
{
2020-02-20 07:05:51 +00:00
if (! $order = session('order')) {
2018-10-04 06:42:06 +00:00
return redirect()->route('shop.checkout.cart.index');
2020-02-20 07:05:51 +00:00
}
2018-10-04 06:42:06 +00:00
return view($this->_config['view'], compact('order'));
}
/**
2022-02-01 11:14:16 +00:00
* Validate order before creation.
2018-10-04 06:42:06 +00:00
*
2020-03-05 13:37:08 +00:00
* @return void|\Exception
2018-10-04 06:42:06 +00:00
*/
public function validateOrder()
{
2018-10-05 06:18:58 +00:00
$cart = Cart::getCart();
2021-02-08 10:17:33 +00:00
$minimumOrderAmount = core()->getConfigData('sales.orderSettings.minimum-order.minimum_order_amount') ?? 0;
if (
auth()->guard('customer')->check()
&& auth()->guard('customer')->user()->is_suspended
) {
throw new \Exception(trans('shop::app.checkout.cart.suspended-account-message'));
}
if (
auth()->guard('customer')->user()
&& ! auth()->guard('customer')->user()->status
) {
throw new \Exception(trans('shop::app.checkout.cart.inactive-account-message'));
}
2020-11-16 14:56:49 +00:00
if (! $cart->checkMinimumOrder()) {
throw new \Exception(trans('shop::app.checkout.cart.minimum-order-message', ['amount' => core()->currency($minimumOrderAmount)]));
}
2020-02-20 07:05:51 +00:00
if ($cart->haveStockableItems() && ! $cart->shipping_address) {
throw new \Exception(trans('shop::app.checkout.cart.check-shipping-address'));
2020-02-20 07:05:51 +00:00
}
2018-10-05 06:18:58 +00:00
2020-02-20 07:05:51 +00:00
if (! $cart->billing_address) {
throw new \Exception(trans('shop::app.checkout.cart.check-billing-address'));
2020-02-20 07:05:51 +00:00
}
2018-10-05 06:18:58 +00:00
if (
$cart->haveStockableItems()
&& ! $cart->selected_shipping_rate
) {
throw new \Exception(trans('shop::app.checkout.cart.specify-shipping-method'));
2020-02-20 07:05:51 +00:00
}
2018-10-05 06:18:58 +00:00
2020-02-20 07:05:51 +00:00
if (! $cart->payment) {
throw new \Exception(trans('shop::app.checkout.cart.specify-payment-method'));
2020-02-20 07:05:51 +00:00
}
2019-12-21 10:30:22 +00:00
}
/**
2022-02-01 11:14:16 +00:00
* Check customer is exist or not.
2019-12-21 10:30:22 +00:00
*
2020-03-05 13:37:08 +00:00
* @return \Illuminate\Http\Response
2019-12-21 10:30:22 +00:00
*/
public function checkExistCustomer()
{
2022-02-01 11:14:16 +00:00
$customer = $this->customerRepository->findOneWhere([
2020-03-04 06:32:53 +00:00
'email' => request()->email,
2022-02-01 11:14:16 +00:00
]);
2019-12-21 10:30:22 +00:00
2022-02-01 11:14:16 +00:00
if (! is_null($customer)) {
return 'true';
}
2019-12-21 10:30:22 +00:00
2022-02-01 11:14:16 +00:00
return 'false';
2019-12-21 10:30:22 +00:00
}
/**
2022-02-01 11:14:16 +00:00
* Login for checkout.
2019-12-21 10:30:22 +00:00
*
2020-03-05 13:37:08 +00:00
* @return \Illuminate\Http\Response
2019-12-21 10:30:22 +00:00
*/
public function loginForCheckout()
{
$this->validate(request(), [
2022-02-01 11:14:16 +00:00
'email' => 'required|email',
2019-12-21 10:30:22 +00:00
]);
2020-02-20 07:05:51 +00:00
if (! auth()->guard('customer')->attempt(request(['email', 'password']))) {
2019-12-21 10:30:22 +00:00
return response()->json(['error' => trans('shop::app.customer.login-form.invalid-creds')]);
2020-02-20 07:05:51 +00:00
}
2019-12-21 10:30:22 +00:00
Cart::mergeCart();
return response()->json(['success' => 'Login successfully']);
2018-10-04 06:42:06 +00:00
}
/**
2022-02-01 11:14:16 +00:00
* To apply couponable rule requested.
*
2020-03-05 13:37:08 +00:00
* @return \Illuminate\Http\Response
*/
public function applyCoupon()
{
$this->validate(request(), [
2020-03-04 06:32:53 +00:00
'code' => 'string|required',
]);
$code = request()->input('code');
$result = $this->coupon->apply($code);
if ($result) {
Cart::collectTotals();
return response()->json([
'success' => true,
'message' => trans('shop::app.checkout.total.coupon-applied'),
2020-03-04 06:32:53 +00:00
'result' => $result,
2022-02-11 12:34:38 +00:00
]);
}
2022-02-01 11:14:16 +00:00
return response()->json([
'success' => false,
'message' => trans('shop::app.checkout.total.cannot-apply-coupon'),
'result' => null,
], 422);
}
/**
2022-02-01 11:14:16 +00:00
* Initiates the removal of couponable cart rule.
*
2020-03-05 13:37:08 +00:00
* @return array
*/
public function removeCoupon()
{
$result = $this->coupon->remove();
if ($result) {
Cart::collectTotals();
return response()->json([
2020-02-27 08:03:03 +00:00
'success' => true,
'message' => trans('admin::app.promotion.status.coupon-removed'),
'data' => [
2020-03-04 06:32:53 +00:00
'grand_total' => core()->currency(Cart::getCart()->grand_total),
],
2022-02-11 12:34:38 +00:00
]);
}
2022-02-01 11:14:16 +00:00
return response()->json([
'success' => false,
'message' => trans('admin::app.promotion.status.coupon-remove-failed'),
'data' => null,
], 422);
}
2020-11-27 05:40:04 +00:00
/**
* 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([
2022-02-01 11:14:16 +00:00
'status' => ! $status ? false : true,
2020-11-27 05:40:04 +00:00
'message' => ! $status ? trans('shop::app.checkout.cart.minimum-order-message', ['amount' => core()->currency($minimumOrderAmount)]) : 'Success',
]);
}
2022-02-01 11:14:16 +00:00
}