diff --git a/src/DataType/Supplier.php b/src/DataType/Supplier.php index 43ef0bb..db675e1 100644 --- a/src/DataType/Supplier.php +++ b/src/DataType/Supplier.php @@ -25,6 +25,7 @@ */ class Supplier extends DataType { + const OFFICE_ADDRESS_LABEL = 'Office'; /** * @param Warehouse $warehouse @@ -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; } diff --git a/src/Service/Suppliers.php b/src/Service/Suppliers.php index eaae25e..67e36df 100644 --- a/src/Service/Suppliers.php +++ b/src/Service/Suppliers.php @@ -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; diff --git a/tests/SuppliersTest.php b/tests/SuppliersTest.php index 2758fcd..2eb3b77 100644 --- a/tests/SuppliersTest.php +++ b/tests/SuppliersTest.php @@ -1,6 +1,7 @@ name = 'Default Supplier API'; - $supplier->setOfficeAddress([ - 'label' => 'Address Name', - 'email' => 'office@supplier.com', - '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' => 'office@supplier.com', +// 'country_code' => 'US', +// 'zip' => '90210' +// ]); $suppliers = new Suppliers(); $response = $suppliers->store($supplier);