Skip to content

Commit

Permalink
Defaulting label to Office for supplier address.
Browse files Browse the repository at this point in the history
  • Loading branch information
brightantwiboasiako committed Apr 1, 2021
1 parent e6a016a commit f462983
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 24 deletions.
33 changes: 16 additions & 17 deletions src/DataType/Supplier.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/
class Supplier extends DataType
{
const OFFICE_ADDRESS_LABEL = 'Office';

/**
* @param Warehouse $warehouse
Expand All @@ -36,27 +37,25 @@ public function addWarehouse(Warehouse $warehouse )
return $this;
}


/**
* Sets the office address
*
* @param array $address
*/
public function setOfficeAddress(array $address){
$this->address = $address;
}


/**
* @param string $field
* @param string $value
* @param $address
* @return $this
*/
public function addOfficeAddressField(string $field, string $value){
if(!isset($this->address)){
$this->address = [];
public function addOfficeAddress($address){
if(is_array($address)){
$this->address = array_merge([
'label' => self::OFFICE_ADDRESS_LABEL
], $address);
}else if($address instanceof Address){
if(!isset($address->label) && isset($address->name)){
$address->label = $address->name;
}else if(!isset($address->label)){
$address->label = $address->name = self::OFFICE_ADDRESS_LABEL;
}
$this->address = $address;
}else{
$this->address = $address;
}
$this->address[$field] = $value;
return $this;
}

Expand Down
4 changes: 3 additions & 1 deletion src/Service/Suppliers.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ public function store(Supplier $supplier )
$supplier,
$this->authorizedRequest( $this->endpoint, $supplier->toJson(), Sdk::METHOD_POST )
);

$supplierId = $response->getData()['id'];
// If warehouse is provided, we create the warehouse for the supplier
if(isset($supplier->warehouse)){
$this->createWarehouse($supplier->id, $supplier->warehouse);
$this->createWarehouse($supplierId, $supplier->warehouse);
}

return $response;
Expand Down
28 changes: 22 additions & 6 deletions tests/SuppliersTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use PHPUnit\Framework\TestCase;
use Skuio\Sdk\DataType\Address;
use Skuio\Sdk\DataType\Supplier;
use Skuio\Sdk\Service\Suppliers;
use Skuio\Sdk\Sdk;
Expand Down Expand Up @@ -34,12 +35,27 @@ public function testCreateSupplier(){
$supplier = new Supplier();
$supplier->name = 'Default Supplier API';

$supplier->setOfficeAddress([
'label' => 'Address Name',
'email' => '[email protected]',
'country_code' => 'US',
'province_code' => '90210'
]);
// Add address with Address object
$address = new Address();
// $address->name = 'Office Address';
$address->address1 = '123 High St.';
$address->address2 = 'Unit 4483';
$address->address3 = 'Left Lane';
$address->country_code = 'US';
$address->zip = '90210';
$address->city = 'Los Angeles';
$address->province = 'California';
$address->province_code = 'CA';
$supplier->addOfficeAddress($address);


// Add address with array
// $supplier->addOfficeAddress([
// 'label' => 'Address Name',
// 'email' => '[email protected]',
// 'country_code' => 'US',
// 'zip' => '90210'
// ]);

$suppliers = new Suppliers();
$response = $suppliers->store($supplier);
Expand Down

0 comments on commit f462983

Please sign in to comment.