From 36cb09bc58e44f72ed472db859a3d4555f7ecc1b Mon Sep 17 00:00:00 2001 From: rahul shukla Date: Fri, 15 Feb 2019 20:10:47 +0530 Subject: [PATCH] address while checkout & reduces code --- packages/Webkul/Checkout/src/Cart.php | 18 +- .../Shop/src/Resources/assets/sass/app.scss | 18 + .../Webkul/Shop/src/Resources/lang/en/app.php | 3 +- .../views/checkout/onepage.blade.php | 40 +- .../checkout/onepage/customer-info.blade.php | 989 ++++++------------ 5 files changed, 417 insertions(+), 651 deletions(-) diff --git a/packages/Webkul/Checkout/src/Cart.php b/packages/Webkul/Checkout/src/Cart.php index e11c3ecc5..c12df3a5f 100755 --- a/packages/Webkul/Checkout/src/Cart.php +++ b/packages/Webkul/Checkout/src/Cart.php @@ -629,7 +629,7 @@ class Cart { $shippingAddress = $data['shipping']; $billingAddress['cart_id'] = $shippingAddress['cart_id'] = $cart->id; - if (isset($data['billing']['address_id'])) { + if (isset($data['billing']['address_id']) && $data['billing']['address_id']) { $address = $this->customerAddress->findOneWhere(['id'=> $data['billing']['address_id']])->toArray(); $billingAddress['first_name'] = auth()->guard('customer')->user()->first_name; $billingAddress['last_name'] = auth()->guard('customer')->user()->last_name; @@ -643,7 +643,7 @@ class Cart { $billingAddress['phone'] = $address['phone']; } - if (isset($data['shipping']['address_id'])) { + if (isset($data['shipping']['address_id']) && $data['shipping']['address_id']) { $address = $this->customerAddress->findOneWhere(['id'=> $data['shipping']['address_id']])->toArray(); $shippingAddress['first_name'] = auth()->guard('customer')->user()->first_name; $shippingAddress['last_name'] = auth()->guard('customer')->user()->last_name; @@ -657,11 +657,15 @@ class Cart { $shippingAddress['phone'] = $address['phone']; } - // if (auth()->guard('customer')->check()) { - // if ($data['billing']['use_for_shipping'] == true) { - // $shippingAddress = $billingAddress; - // } - // } + if (isset($data['billing']['save_as_address']) && $data['billing']['save_as_address']) { + $billingAddress['customer_id'] = auth()->guard('customer')->user()->id; + $this->customerAddress->create($billingAddress); + } + + if (isset($data['shipping']['save_as_address']) && $data['shipping']['save_as_address']) { + $shippingAddress['customer_id'] = auth()->guard('customer')->user()->id; + $this->customerAddress->create($shippingAddress); + } if ($billingAddressModel = $cart->billing_address) { $this->cartAddress->update($billingAddress, $billingAddressModel->id); diff --git a/packages/Webkul/Shop/src/Resources/assets/sass/app.scss b/packages/Webkul/Shop/src/Resources/assets/sass/app.scss index b8c522a9b..3b059f034 100755 --- a/packages/Webkul/Shop/src/Resources/assets/sass/app.scss +++ b/packages/Webkul/Shop/src/Resources/assets/sass/app.scss @@ -2493,6 +2493,24 @@ section.cart { } } } + + .address-holder { + justify-content: space-between; + + .address-card-1 { + margin-right: 0px !important; + width: 253px !important; + + .details { + margin-left: 30px; + + .checkmark { + left: -30px; + top: 12px; + } + } + } + } // complete page end here } } diff --git a/packages/Webkul/Shop/src/Resources/lang/en/app.php b/packages/Webkul/Shop/src/Resources/lang/en/app.php index ee8f5c9c8..9ab227503 100755 --- a/packages/Webkul/Shop/src/Resources/lang/en/app.php +++ b/packages/Webkul/Shop/src/Resources/lang/en/app.php @@ -422,7 +422,8 @@ return [ 'shipping-address' => 'Shipping Address', 'contact' => 'Contact', 'place-order' => 'Place Order', - 'new-address' => 'Add New Address' + 'new-address' => 'Add New Address', + 'save_as_address' => 'Save as Address' ], 'total' => [ diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php index 86d9fec57..d4acc9104 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php @@ -117,6 +117,16 @@ var paymentHtml = ''; var reviewHtml = ''; var summaryHtml = Vue.compile(` $cart])->render(); ?>`); + var customerAddress = null; + + @auth('customer') + @if(auth('customer')->user()->addresses) + customerAddress = @json(auth('customer')->user()->addresses); + customerAddress.email = "{{ auth('customer')->user()->email }}"; + customerAddress.first_name = "{{ auth('customer')->user()->first_name }}"; + customerAddress.last_name = "{{ auth('customer')->user()->last_name }}"; + @endif + @endauth Vue.component('checkout', { @@ -147,9 +157,37 @@ new_billing_address: false, - countryStates: @json(core()->groupedStatesByCountries()) + allAddress: {}, + + countryStates: @json(core()->groupedStatesByCountries()), + + country: @json(core()->countries()) }), + created() { + if(!customerAddress) { + this.new_shipping_address = true; + this.new_billing_address = true; + } else { + if (customerAddress.length < 1) { + this.new_shipping_address = true; + this.new_billing_address = true; + } else { + this.allAddress = customerAddress; + + for (var country in this.country) { + for (var code in this.allAddress) { + if (this.allAddress[code].country) { + if (this.allAddress[code].country == this.country[country].code) { + this.allAddress[code]['country'] = this.country[country].name; + } + } + } + } + } + } + }, + methods: { navigateToStep (step) { if (step <= this.completedStep) { diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/onepage/customer-info.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/onepage/customer-info.blade.php index b9fc8113f..4b344de8d 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/onepage/customer-info.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/onepage/customer-info.blade.php @@ -1,697 +1,402 @@
- guard('customer')->check()) { - $addresses = auth()->guard('customer')->user()->addresses; +
+
+

{{ __('shop::app.checkout.onepage.billing-address') }}

- if(isset($addresses) && count($addresses)) { - $enableMultiAddress = true; - } - } - ?> + + {{ __('shop::app.checkout.onepage.new-address') }} + +
+
+
+
- @if ($enableMultiAddress) -
-
-

{{ __('shop::app.checkout.onepage.billing-address') }}

+ - - {{ __('shop::app.checkout.onepage.new-address') }} - -
-
- @foreach ($addresses as $address) -
-
- - - - {{ auth()->guard('customer')->user()->name }} - {{ $address->name }}
- {{ $address->address1 }}, {{ $address->address2 ? $address->address2 . ',' : '' }}
- {{ $address->city }}
- {{ $address->state }}
- {{ country()->name($address->country) }} {{ $address->postcode }}

- {{ __('shop::app.customer.account.address.index.contact') }} : {{ $address->phone }} -
-
- @endforeach - -
- - @{{ errors.first('address-form.billing[address_id]') }} - + @{{ allAddress.first_name }} @{{ allAddress.last_name }} + @{{ addresses.name }}
+ @{{ addresses.address1 }}, @{{ addresses.address2 }}
+ @{{ addresses.city }}
+ @{{ addresses.state }}
+ @{{ addresses.country }}

+ {{ __('shop::app.customer.account.address.index.contact') }} : @{{ addresses.phone }}
-
-
- - - - {{ __('shop::app.checkout.onepage.use_for_shipping') }} +
+ + @{{ errors.first('address-form.billing[address_id]') }} -
- -
- -
-

{{ __('shop::app.checkout.onepage.billing-address') }}

- - @guest('customer') - - {{ __('shop::app.checkout.onepage.sign-in') }} - - @endguest -
- -
- - - - - - @{{ errors.first('address-form.billing[first_name]') }} - -
- -
- - - - - - @{{ errors.first('address-form.billing[last_name]') }} - -
- -
- - - - - - @{{ errors.first('address-form.billing[email]') }} - -
- -
- - - - - - @{{ errors.first('address-form.billing[address1]') }} - -
- -
- - - -
- -
- - - - - - @{{ errors.first('address-form.billing[city]') }} - -
- -
- - - - - - - - - @{{ errors.first('address-form.billing[state]') }} - -
- -
- - - - - - @{{ errors.first('address-form.billing[postcode]') }} - -
- -
- - - - - - @{{ errors.first('address-form.billing[country]') }} - -
- -
- - - - - - @{{ errors.first('address-form.billing[phone]') }} - -
- -
- - +
+ + {{ __('shop::app.checkout.onepage.use_for_shipping') }} - + -
+
-
-
-

{{ __('shop::app.checkout.onepage.shipping-address') }}

+
- - {{ __('shop::app.checkout.onepage.new-address') }} + -
- @foreach ($addresses as $address) -
-
+ @endguest +
- +
+ + + + + + @{{ errors.first('address-form.billing[first_name]') }} + +
+ +
+ + + + + + @{{ errors.first('address-form.billing[last_name]') }} + +
+ +
+ + + + + + @{{ errors.first('address-form.billing[email]') }} + +
+ +
+ + + + + + @{{ errors.first('address-form.billing[address1]') }} + +
+ +
+ + + +
+ +
+ + + + + + @{{ errors.first('address-form.billing[city]') }} + +
+ +
+ + + + + + + + @{{ errors.first('address-form.billing[state]') }} + +
+ +
+ + + + + + @{{ errors.first('address-form.billing[postcode]') }} + +
+ +
+ + + -
- - @{{ errors.first('address-form.shipping[address_id]') }} - -
- -
+ + @{{ errors.first('address-form.billing[country]') }} +
-
+
+ -
-

{{ __('shop::app.checkout.onepage.shipping-address') }}

-
+ -
- - - - - - @{{ errors.first('address-form.shipping[first_name]') }} - -
- -
- - - - - - @{{ errors.first('address-form.shipping[last_name]') }} - -
- -
- - - - - - @{{ errors.first('address-form.shipping[email]') }} - -
- -
- - - - - - @{{ errors.first('address-form.shipping[address1]') }} - -
- -
- - - -
- -
- - - - - - @{{ errors.first('address-form.shipping[city]') }} - -
- -
- - - - - - - - - @{{ errors.first('address-form.shipping[state]') }} - -
- -
- - - - - - @{{ errors.first('address-form.shipping[postcode]') }} - -
- -
- - - - - - @{{ errors.first('address-form.shipping[country]') }} - -
- -
- - - - - - @{{ errors.first('address-form.shipping[phone]') }} - -
+ + @{{ errors.first('address-form.billing[phone]') }} +
- @else -
-
-

{{ __('shop::app.checkout.onepage.billing-address') }}

+
+ + + + {{ __('shop::app.checkout.onepage.use_for_shipping') }} + - @guest('customer') - - {{ __('shop::app.checkout.onepage.sign-in') }} - - @endguest -
- -
- - - - - - @{{ errors.first('address-form.billing[first_name]') }} - -
- -
- - - - - - @{{ errors.first('address-form.billing[last_name]') }} - -
- -
- - - - - - @{{ errors.first('address-form.billing[email]') }} - -
- -
- - - - - - @{{ errors.first('address-form.billing[address1]') }} - -
- -
- - - -
- -
- - - - - - @{{ errors.first('address-form.billing[city]') }} - -
- -
- - - - - - - - - @{{ errors.first('address-form.billing[state]') }} - -
- -
- - - - - - @{{ errors.first('address-form.billing[postcode]') }} - -
- -
- - - - - - @{{ errors.first('address-form.billing[country]') }} - -
- -
- - - - - - @{{ errors.first('address-form.billing[phone]') }} - -
+
+ @auth('customer')
- - - {{ __('shop::app.checkout.onepage.use_for_shipping') }} + + + {{ __('shop::app.checkout.onepage.save_as_address') }} -
+ @endauth + +
+ +
+
+

{{ __('shop::app.checkout.onepage.shipping-address') }}

+ + + {{ __('shop::app.checkout.onepage.new-address') }} + +
+
+ +
+
+ + + + @{{ allAddress.first_name }} @{{ allAddress.last_name }} + @{{ addresses.name }}
+ @{{ addresses.address1 }}, @{{ addresses.address2 }}
+ @{{ addresses.city }}
+ @{{ addresses.state }}
+ @{{ addresses.country }}

+ {{ __('shop::app.customer.account.address.index.contact') }} : @{{ addresses.phone }} + +
+
+ +
+ + @{{ errors.first('address-form.shipping[address_id]') }} + +
+ +
+
+ +
+ +
+

{{ __('shop::app.checkout.onepage.shipping-address') }}

-
+
+ -
-

{{ __('shop::app.checkout.onepage.shipping-address') }}

-
+ -
- + + @{{ errors.first('address-form.shipping[first_name]') }} + +
- +
+ - - @{{ errors.first('address-form.shipping[first_name]') }} - -
+ -
- + + @{{ errors.first('address-form.shipping[last_name]') }} + +
- +
+ - - @{{ errors.first('address-form.shipping[last_name]') }} - -
+ -
- + + @{{ errors.first('address-form.shipping[email]') }} + +
- +
+ - - @{{ errors.first('address-form.shipping[email]') }} - -
+ -
- + + @{{ errors.first('address-form.shipping[address1]') }} + +
- +
+ - - @{{ errors.first('address-form.shipping[address1]') }} - -
+ +
+
+ + + + + + @{{ errors.first('address-form.shipping[city]') }} + +
+ +
+ + + + + + + + + @{{ errors.first('address-form.shipping[state]') }} + +
+ +
+ + + + + + @{{ errors.first('address-form.shipping[postcode]') }} + +
+ +
+ + + + + + @{{ errors.first('address-form.shipping[country]') }} + +
+ +
+ + + + + + @{{ errors.first('address-form.shipping[phone]') }} + +
+ + @auth('customer')
- - - -
- -
- - - - - - @{{ errors.first('address-form.shipping[city]') }} + + + + {{ __('shop::app.checkout.onepage.save_as_address') }}
+ @endauth -
- - - - - - - - - @{{ errors.first('address-form.shipping[state]') }} - -
- -
- - - - - - @{{ errors.first('address-form.shipping[postcode]') }} - -
- -
- - - - - - @{{ errors.first('address-form.shipping[country]') }} - -
- -
- - - - - - @{{ errors.first('address-form.shipping[phone]') }} - -
-
- @endif +