Skip to content

Commit

Permalink
Merge pull request #2 from kg-bot/customer_addresses
Browse files Browse the repository at this point in the history
Customer addresses
  • Loading branch information
kg-bot committed Jan 27, 2021
2 parents 176de41 + dec453a commit ee7fd8f
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 61 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*"
},
Expand Down
21 changes: 21 additions & 0 deletions src/Builders/CustomerAddressBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace KgBot\Magento\Builders;


use KgBot\Magento\Exceptions\MagentoMethodNotImplementedException;
use KgBot\Magento\Models\CustomerAddress;

class CustomerAddressBuilder extends Builder
{
protected $entity = 'customers/addresses';
protected $model = CustomerAddress::class;

public function get( $filters = [] ) {
throw new MagentoMethodNotImplementedException( 'This method is not available on this resource' );
}

public function create( $data ) {
throw new MagentoMethodNotImplementedException( 'This method is not available on this resource' );
}
}
112 changes: 54 additions & 58 deletions src/Magento.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
<?php
/**
* Created by PhpStorm.
* User: nts
* Date: 31.3.18.
* Time: 15.12
*/

namespace KgBot\Magento;

use KgBot\Magento\Builders\CustomerAddressBuilder;
use KgBot\Magento\Builders\CustomerBuilder;
use KgBot\Magento\Builders\CustomerGroupBuilder;
use KgBot\Magento\Builders\OrderBuilder;
Expand All @@ -16,63 +11,64 @@

class Magento
{
/**
* @var $request Request
*/
protected $request;
/**
* @var $request Request
*/
protected $request;

/**
* 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 );
}
/**
* 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 );
}
}
32 changes: 30 additions & 2 deletions src/Models/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
} );
}
}
18 changes: 18 additions & 0 deletions src/Models/CustomerAddress.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* Created by PhpStorm.
* User: nts
* Date: 19.4.18.
* Time: 01.30
*/

namespace KgBot\Magento\Models;


use KgBot\Magento\Utils\Model;

class CustomerAddress extends Model
{
protected $entity = 'customers/addresses';
protected $primaryKey = 'id';
}

0 comments on commit ee7fd8f

Please sign in to comment.