Customer address issues fixed

This commit is contained in:
jitendra 2018-10-30 18:16:40 +05:30
parent ef462c8793
commit e7ece582f1
3 changed files with 8 additions and 8 deletions

View File

@ -136,12 +136,12 @@ class AddressController extends Controller
* @return Mixed | @return response
*/
public function makeDefault($id) {
$default = $this->customer->defaultAddress;
$result = $this->address->find($default->id)->update(['default_address' => 0]);
if($this->address->find($id)->update(['default_address' => 1])) {
if($default = $this->customer->default_address) {
$this->address->find($default->id)->update(['default_address' => 0]);
}
if($address = $this->address->find($id)) {
$address->update(['default_address' => 1]);
} else {
session()->flash('success', 'Default Cannot Be Address Changed');
}

View File

@ -58,7 +58,7 @@ class Customer extends Authenticatable
/**
* Get default customer address that owns the customer.
*/
public function defaultAddress()
public function default_address()
{
return $this->hasOne(CustomerAddress::class, 'customer_id')->where('default_address', 1);
}

View File

@ -119,8 +119,8 @@
var summaryHtml = Vue.compile(`<?php echo view('shop::checkout.total.summary', ['cart' => $cart])->render(); ?>`);
var customerAddress = null;
@auth('customer')
@if(auth('customer')->user()->address)
customerAddress = @json(auth('customer')->user()->address);
@if(auth('customer')->user()->default_address)
customerAddress = @json(auth('customer')->user()->default_address);
@else
customerAddress = {};
@endif