| @@ -21,9 +21,9 @@ | ||
| 21 | 21 | use CanSearch; |
| 22 | 22 | |
| 23 | 23 | protected $table = 'fct_customer_addresses'; |
| 24 | 24 | |
| 25 | - protected $appends = ['formatted_address', 'company_name']; | |
| 25 | + protected $appends = ['formatted_address', 'company_name', 'vat_number', 'legal_registration_id']; | |
| 26 | 26 | |
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * The attributes that are mass assignable. |
| @@ -45,9 +45,8 @@ | ||
| 45 | 45 | 'country', |
| 46 | 46 | 'phone', |
| 47 | 47 | 'email', |
| 48 | 48 | 'meta', |
| 49 | - 'company_name', | |
| 50 | 49 | ]; |
| 51 | 50 | |
| 52 | 51 | |
| 53 | 52 | public function setMetaAttribute($value) |
| @@ -52,10 +51,10 @@ | ||
| 52 | 51 | |
| 53 | 52 | public function setMetaAttribute($value) |
| 54 | 53 | { |
| 55 | 54 | if ($value) { |
| 56 | - $decoded = \json_encode($value, true); | |
| 57 | - if (!($decoded)) { | |
| 55 | + $decoded = \json_encode($value); | |
| 56 | + if (!$decoded) { | |
| 58 | 57 | $decoded = '[]'; |
| 59 | 58 | } |
| 60 | 59 | } else { |
| 61 | 60 | $decoded = '[]'; |
| @@ -74,26 +73,58 @@ | ||
| 74 | 73 | } |
| 75 | 74 | |
| 76 | 75 | public function setCompanyNameAttribute($value) |
| 77 | 76 | { |
| 78 | - if (!$value) { | |
| 79 | - return; | |
| 77 | + $meta = is_array($this->meta) ? $this->meta : []; | |
| 78 | + | |
| 79 | + if ($value) { | |
| 80 | + Arr::set($meta, 'other_data.company_name', $value); | |
| 81 | + } else { | |
| 82 | + unset($meta['other_data']['company_name']); | |
| 80 | 83 | } |
| 81 | 84 | |
| 82 | - $meta = $this->meta; | |
| 85 | + $this->attributes['meta'] = json_encode($meta); | |
| 86 | + } | |
| 83 | 87 | |
| 84 | - if (!is_array($meta)) { | |
| 85 | - $meta = []; | |
| 88 | + public function getCompanyNameAttribute() | |
| 89 | + { | |
| 90 | + return Arr::get($this->meta, 'other_data.company_name', ''); | |
| 91 | + } | |
| 92 | + | |
| 93 | + public function setLegalRegistrationIdAttribute($value) | |
| 94 | + { | |
| 95 | + $meta = is_array($this->meta) ? $this->meta : []; | |
| 96 | + | |
| 97 | + if ($value) { | |
| 98 | + Arr::set($meta, 'other_data.legal_registration_id', $value); | |
| 99 | + } else { | |
| 100 | + unset($meta['other_data']['legal_registration_id']); | |
| 86 | 101 | } |
| 87 | 102 | |
| 88 | - Arr::set($meta, 'other_data.company_name', $value); | |
| 103 | + $this->attributes['meta'] = json_encode($meta); | |
| 104 | + } | |
| 89 | 105 | |
| 106 | + public function getLegalRegistrationIdAttribute() | |
| 107 | + { | |
| 108 | + return Arr::get($this->meta, 'other_data.legal_registration_id', ''); | |
| 109 | + } | |
| 110 | + | |
| 111 | + public function setVatNumberAttribute($value) | |
| 112 | + { | |
| 113 | + $meta = is_array($this->meta) ? $this->meta : []; | |
| 114 | + | |
| 115 | + if ($value) { | |
| 116 | + Arr::set($meta, 'other_data.vat_number', $value); | |
| 117 | + } else { | |
| 118 | + unset($meta['other_data']['vat_number']); | |
| 119 | + } | |
| 120 | + | |
| 90 | 121 | $this->attributes['meta'] = json_encode($meta); |
| 91 | 122 | } |
| 92 | 123 | |
| 93 | - public function getCompanyNameAttribute() | |
| 124 | + public function getVatNumberAttribute() | |
| 94 | 125 | { |
| 95 | - return Arr::get($this->meta, 'other_data.company_name', ''); | |
| 126 | + return Arr::get($this->meta, 'other_data.vat_number', ''); | |
| 96 | 127 | } |
| 97 | 128 | |
| 98 | 129 | public function scopeOfActive($query) |
| 99 | 130 | { |
| @@ -124,8 +155,10 @@ | ||
| 124 | 155 | 'first_name' => $this->first_name, |
| 125 | 156 | 'last_name' => $this->last_name, |
| 126 | 157 | 'full_name' => $this->full_name, |
| 127 | 158 | 'company_name' => $this->company_name, |
| 159 | + 'vat_number' => $this->vat_number, | |
| 160 | + 'legal_registration_id' => $this->legal_registration_id, | |
| 128 | 161 | 'label' => $this->label, |
| 129 | 162 | 'phone' => $this->phone |
| 130 | 163 | ]; |
| 131 | 164 | |
| @@ -158,8 +191,10 @@ | ||
| 158 | 191 | '' . $prefix . 'phone' => $this->phone, |
| 159 | 192 | '' . $prefix . 'postcode' => $this->postcode, |
| 160 | 193 | '' . $prefix . 'country' => $this->country, |
| 161 | 194 | '' . $prefix . 'company_name' => $this->company_name, |
| 195 | + '' . $prefix . 'vat_number' => $this->vat_number, | |
| 196 | + '' . $prefix . 'legal_registration_id' => $this->legal_registration_id, | |
| 162 | 197 | ]; |
| 163 | 198 | |
| 164 | 199 | // if ($prefix === 'billing_') { |
| 165 | 200 | // unset($data['billing_full_name']); |