From 6e9706457a919ec2120fbd372e883d144ab1867c Mon Sep 17 00:00:00 2001 From: Stefan Ninic Date: Wed, 27 Jan 2021 11:41:42 +0100 Subject: [PATCH 1/3] Customer addresses --- src/Builders/CustomerAddressBuilder.php | 21 +++++ src/Magento.php | 112 ++++++++++++------------ src/Models/Customer.php | 32 ++++++- src/Models/CustomerAddress.php | 18 ++++ 4 files changed, 123 insertions(+), 60 deletions(-) create mode 100644 src/Builders/CustomerAddressBuilder.php create mode 100644 src/Models/CustomerAddress.php diff --git a/src/Builders/CustomerAddressBuilder.php b/src/Builders/CustomerAddressBuilder.php new file mode 100644 index 0000000..32d663e --- /dev/null +++ b/src/Builders/CustomerAddressBuilder.php @@ -0,0 +1,21 @@ +initRequest( $token, $options, $headers ); - } + /** + * Rackbeat constructor. + * + * @param null $token API token + * @param array $options Custom Guzzle options + * @param array $headers Custom Guzzle headers + */ + public function __construct( $token = null, $options = [], $headers = [] ) { + $this->initRequest( $token, $options, $headers ); + } - /** - * @param $token - * @param array $options - * @param array $headers - */ - private function initRequest( $token, $options = [], $headers = [] ) - { - $this->request = new Request( $token, $options, $headers ); - } + /** + * @param $token + * @param array $options + * @param array $headers + */ + private function initRequest( $token, $options = [], $headers = [] ): void { + $this->request = new Request( $token, $options, $headers ); + } - /** - * @return \KgBot\Magento\Builders\OrderBuilder - */ - public function orders() - { - return new OrderBuilder( $this->request ); - } + /** + * @return OrderBuilder + */ + public function orders(): OrderBuilder { + return new OrderBuilder( $this->request ); + } - /** - * @return \KgBot\Magento\Builders\CustomerBuilder - */ - public function customers() - { - return new CustomerBuilder( $this->request ); - } + /** + * @return CustomerBuilder + */ + public function customers(): CustomerBuilder { + return new CustomerBuilder( $this->request ); + } - /** - * @return \KgBot\Magento\Builders\ProductBuilder - */ - public function products() - { - return new ProductBuilder( $this->request ); - } + /** + * @return CustomerAddressBuilder + */ + public function customer_addresses(): CustomerAddressBuilder { + return new CustomerAddressBuilder( $this->request ); + } - /** - * @return \KgBot\Magento\Builders\CustomerGroupBuilder - */ - public function customer_groups() - { + /** + * @return ProductBuilder + */ + public function products(): ProductBuilder { + return new ProductBuilder( $this->request ); + } - return new CustomerGroupBuilder( $this->request ); - } + /** + * @return CustomerGroupBuilder + */ + public function customer_groups(): CustomerGroupBuilder { + + return new CustomerGroupBuilder( $this->request ); + } } \ No newline at end of file diff --git a/src/Models/Customer.php b/src/Models/Customer.php index 6e9d711..326a688 100644 --- a/src/Models/Customer.php +++ b/src/Models/Customer.php @@ -13,6 +13,34 @@ class Customer extends Model { - protected $entity = 'customers'; - protected $primaryKey = 'id'; + protected $entity = 'customers'; + protected $primaryKey = 'id'; + + public function getBillingAddress() { + return $this->request->handleWithExceptions( function () { + + $address = $this->request->client->get( "{$this->entity}/{$this->{$this->primaryKey}}/billingAddress" ); + $responseData = json_decode( (string) $address->getBody() ); + + if ( ! empty( $responseData ) ) { + return new CustomerAddress( $this->request, $responseData ); + } + + return null; + } ); + } + + public function getShippingAddress() { + return $this->request->handleWithExceptions( function () { + + $address = $this->request->client->get( "{$this->entity}/{$this->{$this->primaryKey}}/shippingAddress" ); + $responseData = json_decode( (string) $address->getBody() ); + + if ( ! empty( $responseData ) ) { + return new CustomerAddress( $this->request, $responseData ); + } + + return null; + } ); + } } diff --git a/src/Models/CustomerAddress.php b/src/Models/CustomerAddress.php new file mode 100644 index 0000000..eb7f308 --- /dev/null +++ b/src/Models/CustomerAddress.php @@ -0,0 +1,18 @@ + Date: Wed, 27 Jan 2021 12:28:43 +0100 Subject: [PATCH 2/3] Require Laravel versions after security fix --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index dce1a41..21d985d 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ ], "require": { "php": ">=7.1", - "laravel/framework": "^5.5|^6|^7", + "laravel/framework": "^5.5|>=6.20.12|>=7.30.3", "ext-json": "*", "guzzlehttp/guzzle": "*" }, From dec453a788b77482d0ef3d3dac3a7489a9e84f8a Mon Sep 17 00:00:00 2001 From: Stefan Ninic Date: Wed, 27 Jan 2021 12:36:52 +0100 Subject: [PATCH 3/3] Require Laravel versions after security fix --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 21d985d..adf9f7c 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ ], "require": { "php": ">=7.1", - "laravel/framework": "^5.5|>=6.20.12|>=7.30.3", + "laravel/framework": "^5.5|^6.20.12|^7.30.3", "ext-json": "*", "guzzlehttp/guzzle": "*" },