Merge remote-tracking branch 'upstream/master' into laravel-8-support

This commit is contained in:
devansh bawari 2021-02-26 18:43:15 +05:30
commit bf81d044cc
4 changed files with 39 additions and 22 deletions

View File

@ -157,4 +157,7 @@ Thank you to all our backers! 🙏
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. Support this project by becoming a sponsor. Your logo will show up here with a link to your website.
<a href="https://opencollective.com/bagisto/contribute/sponsor-7372/checkout" target="_blank"><img src="https://images.opencollective.com/static/images/become_sponsor.svg"></a> <a href="https://opencollective.com/bagisto/contribute/sponsor-7372/checkout" target="_blank">
<img src="https://images.opencollective.com/e-ventures1/7d61db2/logo.png" style="border-radius: 50%; width: auto; height:42px;">
<img src="https://images.opencollective.com/static/images/become_sponsor.svg">
</a>

View File

@ -31,7 +31,7 @@ class AddressController extends Controller
/** /**
* Controller instance * Controller instance
* *
* @param Webkul\Customer\Repositories\CustomerAddressRepository $customerAddressRepository * @param CustomerAddressRepository $customerAddressRepository
*/ */
public function __construct(CustomerAddressRepository $customerAddressRepository) public function __construct(CustomerAddressRepository $customerAddressRepository)
{ {
@ -49,12 +49,12 @@ class AddressController extends Controller
/** /**
* Get user address. * Get user address.
* *
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
*/ */
public function get() public function get()
{ {
$customer = auth($this->guard)->user(); $customer = auth($this->guard)->user();
$addresses = $customer->addresses()->get(); $addresses = $customer->addresses()->get();
return CustomerAddressResource::collection($addresses); return CustomerAddressResource::collection($addresses);
@ -63,13 +63,14 @@ class AddressController extends Controller
/** /**
* Store a newly created resource in storage. * Store a newly created resource in storage.
* *
* @return \Illuminate\Http\Response * @return \Illuminate\Http\JsonResponse
* @throws \Illuminate\Validation\ValidationException
*/ */
public function store() public function store()
{ {
$customer = auth($this->guard)->user(); $customer = auth($this->guard)->user();
if (request()->input('address1') && ! is_array(json_decode(request()->input('address1')))) { if (request()->input('address1') && ! is_array(request()->input('address1'))) {
return response()->json([ return response()->json([
'message' => 'address1 must be an array.', 'message' => 'address1 must be an array.',
]); ]);
@ -77,18 +78,20 @@ class AddressController extends Controller
if (request()->input('address1')) { if (request()->input('address1')) {
request()->merge([ request()->merge([
'address1' => implode(PHP_EOL, array_filter(json_decode(request()->input('address1')))), 'address1' => implode(PHP_EOL, array_filter(request()->input('address1'))),
'customer_id' => $customer->id, 'customer_id' => $customer->id,
]); ]);
} }
$this->validate(request(), [ $this->validate(request(), [
'address1' => 'string|required', 'address1' => 'string|required',
'country' => 'string|required', 'company' => 'string|nullable',
'state' => 'string|required', 'vat_id' => 'string|nullable',
'city' => 'string|required', 'country' => 'string|required',
'state' => 'string|nullable',
'city' => 'string|required',
'postcode' => 'required', 'postcode' => 'required',
'phone' => 'required', 'phone' => 'required',
]); ]);
$customerAddress = $this->customerAddressRepository->create(request()->all()); $customerAddress = $this->customerAddressRepository->create(request()->all());
@ -101,29 +104,37 @@ class AddressController extends Controller
/** /**
* Update the specified resource in storage. * Update the specified resource in storage.
* * @param int $id
* @return \Illuminate\Http\Response *
* @return \Illuminate\Http\JsonResponse
* @throws \Illuminate\Validation\ValidationException
*/ */
public function update() public function update(int $id)
{ {
$customer = auth($this->guard)->user(); if (request()->input('address1') && ! is_array(request()->input('address1'))) {
return response()->json([
'message' => 'address1 must be an array.',
]);
}
request()->merge(['address1' => implode(PHP_EOL, array_filter(request()->input('address1')))]); request()->merge(['address1' => implode(PHP_EOL, array_filter(request()->input('address1')))]);
$this->validate(request(), [ $this->validate(request(), [
'address1' => 'string|required', 'address1' => 'string|required',
'country' => 'string|required', 'company' => 'string|nullable',
'state' => 'string|required', 'vat_id' => 'string|nullable',
'city' => 'string|required', 'country' => 'string|required',
'state' => 'string|nullable',
'city' => 'string|required',
'postcode' => 'required', 'postcode' => 'required',
'phone' => 'required', 'phone' => 'required',
]); ]);
$this->customerAddressRepository->update(request()->all(), request()->input('id')); $customerAddress = $this->customerAddressRepository->update(request()->all(), $id);
return response()->json([ return response()->json([
'message' => 'Your address has been updated successfully.', 'message' => 'Your address has been updated successfully.',
'data' => new CustomerAddressResource($this->customerAddressRepository->find(request()->input('id'))), 'data' => new CustomerAddressResource($customerAddress),
]); ]);
} }
} }

View File

@ -19,6 +19,7 @@ class CustomerAddress extends JsonResource
'first_name' => $this->first_name, 'first_name' => $this->first_name,
'last_name' => $this->last_name, 'last_name' => $this->last_name,
'company_name' => $this->company_name, 'company_name' => $this->company_name,
'vat_id' => $this->vat_id,
'address1' => explode(PHP_EOL, $this->address1), 'address1' => explode(PHP_EOL, $this->address1),
'country' => $this->country, 'country' => $this->country,
'country_name' => core()->country_name($this->country), 'country_name' => core()->country_name($this->country),
@ -26,6 +27,7 @@ class CustomerAddress extends JsonResource
'city' => $this->city, 'city' => $this->city,
'postcode' => $this->postcode, 'postcode' => $this->postcode,
'phone' => $this->phone, 'phone' => $this->phone,
'is_default' => $this->default_address,
'created_at' => $this->created_at, 'created_at' => $this->created_at,
'updated_at' => $this->updated_at, 'updated_at' => $this->updated_at,
]; ];

View File

@ -72,6 +72,7 @@ abstract class Address extends Model implements AddressContract
protected $casts = [ protected $casts = [
'additional' => 'array', 'additional' => 'array',
'default_address' => 'boolean',
]; ];
/** /**