diff --git a/packages/Webkul/Checkout/src/Cart.php b/packages/Webkul/Checkout/src/Cart.php index 84cfe4534..b426d37d2 100755 --- a/packages/Webkul/Checkout/src/Cart.php +++ b/packages/Webkul/Checkout/src/Cart.php @@ -11,6 +11,7 @@ use Webkul\Product\Repositories\ProductRepository; use Webkul\Tax\Repositories\TaxCategoryRepository; use Webkul\Checkout\Models\CartPayment; use Webkul\Customer\Repositories\WishlistRepository; +use Webkul\Customer\Repositories\CustomerAddressRepository; /** * Facades handler for all the methods to be implemented in Cart. @@ -70,6 +71,13 @@ class Cart { */ protected $wishlist; + /** + * CustomerAddressRepository model + * + * @var mixed + */ + protected $customerAddress; + /** * Suppress the session flash messages */ @@ -78,12 +86,13 @@ class Cart { /** * Create a new controller instance. * - * @param Webkul\Checkout\Repositories\CartRepository $cart - * @param Webkul\Checkout\Repositories\CartItemRepository $cartItem - * @param Webkul\Checkout\Repositories\CartAddressRepository $cartAddress - * @param Webkul\Customer\Repositories\CustomerRepository $customer - * @param Webkul\Product\Repositories\ProductRepository $product - * @param Webkul\Product\Repositories\TaxCategoryRepository $taxCategory + * @param Webkul\Checkout\Repositories\CartRepository $cart + * @param Webkul\Checkout\Repositories\CartItemRepository $cartItem + * @param Webkul\Checkout\Repositories\CartAddressRepository $cartAddress + * @param Webkul\Customer\Repositories\CustomerRepository $customer + * @param Webkul\Product\Repositories\ProductRepository $product + * @param Webkul\Product\Repositories\TaxCategoryRepository $taxCategory + * @param Webkul\Product\Repositories\CustomerAddressRepository $customerAddress * @return void */ public function __construct( @@ -93,7 +102,8 @@ class Cart { CustomerRepository $customer, ProductRepository $product, TaxCategoryRepository $taxCategory, - WishlistRepository $wishlist + WishlistRepository $wishlist, + CustomerAddressRepository $customerAddress ) { $this->customer = $customer; @@ -110,6 +120,8 @@ class Cart { $this->wishlist = $wishlist; + $this->customerAddress = $customerAddress; + $this->suppressFlash = false; } @@ -617,6 +629,40 @@ class Cart { $shippingAddress = $data['shipping']; $billingAddress['cart_id'] = $shippingAddress['cart_id'] = $cart->id; + if (isset($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; + $billingAddress['email'] = auth()->guard('customer')->user()->email; + $billingAddress['address1'] = $address['address1']; + $billingAddress['address2'] = $address['address2']; + $billingAddress['country'] = $address['country']; + $billingAddress['state'] = $address['state']; + $billingAddress['city'] = $address['city']; + $billingAddress['postcode'] = $address['postcode']; + $billingAddress['phone'] = $address['phone']; + } + + if (isset($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; + $shippingAddress['email'] = auth()->guard('customer')->user()->email; + $shippingAddress['address1'] = $address['address1']; + $shippingAddress['address2'] = $address['address2']; + $shippingAddress['country'] = $address['country']; + $shippingAddress['state'] = $address['state']; + $shippingAddress['city'] = $address['city']; + $shippingAddress['postcode'] = $address['postcode']; + $shippingAddress['phone'] = $address['phone']; + } + + // if (auth()->guard('customer')->check()) { + // if ($data['billing']['use_for_shipping'] == true) { + // $shippingAddress = $billingAddress; + // } + // } + if ($billingAddressModel = $cart->billing_address) { $this->cartAddress->update($billingAddress, $billingAddressModel->id); @@ -814,7 +860,7 @@ class Cart { } } } - + return true; } } diff --git a/packages/Webkul/Checkout/src/Http/Requests/CustomerAddressForm.php b/packages/Webkul/Checkout/src/Http/Requests/CustomerAddressForm.php index ce619e8d6..0ead62731 100755 --- a/packages/Webkul/Checkout/src/Http/Requests/CustomerAddressForm.php +++ b/packages/Webkul/Checkout/src/Http/Requests/CustomerAddressForm.php @@ -26,30 +26,42 @@ class CustomerAddressForm extends FormRequest */ public function rules() { - $this->rules = [ - 'billing.first_name' => ['required'], - 'billing.last_name' => ['required'], - 'billing.email' => ['required'], - 'billing.address1' => ['required'], - 'billing.city' => ['required'], - 'billing.state' => ['required'], - 'billing.postcode' => ['required'], - 'billing.phone' => ['required'], - 'billing.country' => ['required'] - ]; + if (isset($this->get('billing')['address_id'])) { + $this->rules = [ + 'billing.address_id' => ['required'], + ]; + } else { + $this->rules = [ + 'billing.first_name' => ['required'], + 'billing.last_name' => ['required'], + 'billing.email' => ['required'], + 'billing.address1' => ['required'], + 'billing.city' => ['required'], + 'billing.state' => ['required'], + 'billing.postcode' => ['required'], + 'billing.phone' => ['required'], + 'billing.country' => ['required'] + ]; + } if (isset($this->get('billing')['use_for_shipping']) && !$this->get('billing')['use_for_shipping']) { - $this->rules = array_merge($this->rules, [ - 'shipping.first_name' => ['required'], - 'shipping.last_name' => ['required'], - 'shipping.email' => ['required'], - 'shipping.address1' => ['required'], - 'shipping.city' => ['required'], - 'shipping.state' => ['required'], - 'shipping.postcode' => ['required'], - 'shipping.phone' => ['required'], - 'shipping.country' => ['required'] - ]); + if (isset($this->get('shipping')['address_id'])) { + $this->rules = array_merge($this->rules, [ + 'shipping.address_id' => ['required'], + ]); + } else { + $this->rules = array_merge($this->rules, [ + 'shipping.first_name' => ['required'], + 'shipping.last_name' => ['required'], + 'shipping.email' => ['required'], + 'shipping.address1' => ['required'], + 'shipping.city' => ['required'], + 'shipping.state' => ['required'], + 'shipping.postcode' => ['required'], + 'shipping.phone' => ['required'], + 'shipping.country' => ['required'] + ]); + } } return $this->rules; diff --git a/packages/Webkul/Shop/src/Resources/lang/en/app.php b/packages/Webkul/Shop/src/Resources/lang/en/app.php index 2d89c9907..ee8f5c9c8 100755 --- a/packages/Webkul/Shop/src/Resources/lang/en/app.php +++ b/packages/Webkul/Shop/src/Resources/lang/en/app.php @@ -9,7 +9,7 @@ return [ 'wishlist' => 'Wishlist', 'orders' => 'Orders', ], - + 'common' => [ 'error' => 'Something went wrong, please try again later.' ], @@ -421,7 +421,8 @@ return [ 'billing-address' => 'Billing Address', 'shipping-address' => 'Shipping Address', 'contact' => 'Contact', - 'place-order' => 'Place Order' + 'place-order' => 'Place Order', + 'new-address' => 'Add New 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 cf1198d82..86d9fec57 100755 --- a/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/checkout/onepage.blade.php @@ -117,17 +117,6 @@ var paymentHtml = ''; var reviewHtml = ''; var summaryHtml = Vue.compile(` $cart])->render(); ?>`); - var customerAddress = null; - @auth('customer') - @if (auth('customer')->user()->default_address) - customerAddress = @json(auth('customer')->user()->default_address); - @else - customerAddress = {}; - @endif - customerAddress.email = "{{ auth('customer')->user()->email }}"; - customerAddress.first_name = "{{ auth('customer')->user()->first_name }}"; - customerAddress.last_name = "{{ auth('customer')->user()->last_name }}"; - @endauth Vue.component('checkout', { @@ -142,7 +131,7 @@ address: { billing: { - use_for_shipping: true + use_for_shipping: true, }, shipping: {}, @@ -154,16 +143,13 @@ disable_button: false, + new_shipping_address: false, + + new_billing_address: false, + countryStates: @json(core()->groupedStatesByCountries()) }), - created() { - if (customerAddress) { - this.address.billing = customerAddress; - this.address.use_for_shipping = true; - } - }, - methods: { navigateToStep (step) { if (step <= this.completedStep) { @@ -175,7 +161,7 @@ haveStates(addressType) { if (this.countryStates[this.address[addressType].country] && this.countryStates[this.address[addressType].country].length) return true; - + return false; }, @@ -300,6 +286,14 @@ paymentMethodSelected (paymentMethod) { this.selected_payment_method = paymentMethod; + }, + + newBillingAddress() { + this.new_billing_address = true; + }, + + newShippingAddress() { + this.new_shipping_address = true; } } }) 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 4934a0b5f..550e4739e 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,300 +1,697 @@