From a8f5ad9bdece12451a56e0297d97dc1c6c50a835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Andr=C3=A9s=20Puertas?= Date: Fri, 10 May 2019 16:46:31 +0100 Subject: [PATCH] feat: added properties and methods, removed empty string defaults, removed item shrinkWrap property --- .../orderData/item/component/component.php | 24 ++++++--- src/order/orderData/item/item.php | 51 +++++++++++++++++- src/order/orderData/orderData.php | 34 +++++++++++- .../orderData/shipment/address/address.php | 4 +- .../shipment/attachments/attachments.php | 37 ++++++++++++- src/order/orderData/shipment/shipment.php | 34 +++++++++++- src/order/orderData/stockItem/stockItem.php | 26 +++++++++ tests/order/orderTest.php | 54 ++++++++++++++++++- 8 files changed, 248 insertions(+), 16 deletions(-) diff --git a/src/order/orderData/item/component/component.php b/src/order/orderData/item/component/component.php index 5c134be..afd6f7c 100644 --- a/src/order/orderData/item/component/component.php +++ b/src/order/orderData/item/component/component.php @@ -21,17 +21,18 @@ public function init() { $this->__addProperty("type"); $this->__addProperty("code"); $this->__addProperty("path"); - $this->__addProperty("barcode", ""); + $this->__addProperty("barcode"); $this->__addProperty("fetch", false); $this->__addProperty("localFile", false); $this->__addProperty("preflight"); $this->__addProperty("preflightProfile"); $this->__addProperty("preflightProfileId"); - $this->__addProperty("paper", "", false); - $this->__addProperty("weight", "", false); - $this->__addProperty("pages", "", false); - $this->__addProperty("width", "", false); - $this->__addProperty("height", "", false); + $this->__addProperty("paper" ); + $this->__addProperty("weight" ); + $this->__addProperty("pages" ); + $this->__addProperty("width"); + $this->__addProperty("height"); + $this->__addProperty("duplicate"); $this->__addArray("attributes", null); $this->__addArray("extraData", null); } @@ -280,6 +281,17 @@ public function addAttribute($name, $value = null) { $this->attributes[$name] = $value; } + /** + * setDuplicate function. + * + * @access public + * @param integer $duplicate + * @return void + */ + public function setDuplicate($duplicate) { + $this->duplicate = $duplicate; + } + /** * setExtraData function. * diff --git a/src/order/orderData/item/item.php b/src/order/orderData/item/item.php index f062ec7..35817cd 100644 --- a/src/order/orderData/item/item.php +++ b/src/order/orderData/item/item.php @@ -22,11 +22,14 @@ public function init() { $this->__addProperty("shipmentIndex", 0, true); $this->__addProperty("sourceItemId", "", true); $this->__addProperty("sku"); + $this->__addProperty("sourceProductId"); $this->__addProperty("quantity", 1, true); $this->__addProperty("printQuantity"); - $this->__addProperty("shrinkWrap", false); - $this->__addProperty("barcode", "", false); + $this->__addProperty("barcode"); $this->__addProperty("dispatchAlert"); + $this->__addProperty("unitWeight"); + $this->__addProperty("unitCost"); + $this->__addProperty("unitPrice"); $this->__addArray("extraData",null); $this->__addProperty("colour"); @@ -171,6 +174,50 @@ public function setSKU($skuCode) { $this->sku = $skuCode; } + /** + * setSourceProductId function. + * + * @access public + * @param string $sourceProductId + * @return void + */ + public function setSourceProductId($sourceProductId) { + $this->sourceProductId = $sourceProductId; + } + + /** + * setUnitWeight function. + * + * @access public + * @param float $unitWeight + * @return void + */ + public function setUnitWeight($unitWeight) { + $this->unitWeight = $unitWeight; + } + + /** + * setUnitPrice function. + * + * @access public + * @param float $unitPrice + * @return void + */ + public function setUnitPrice($unitPrice) { + $this->unitPrice = $unitPrice; + } + + /** + * setUnitCost function. + * + * @access public + * @param float $unitCost + * @return void + */ + public function setUnitCost($unitCost) { + $this->unitCost = $unitCost; + } + /** * setExtraData function. * diff --git a/src/order/orderData/orderData.php b/src/order/orderData/orderData.php index 4b4ce4b..612ba91 100644 --- a/src/order/orderData/orderData.php +++ b/src/order/orderData/orderData.php @@ -40,13 +40,14 @@ public function init() { $this->__addProperty("email",""); $this->__addProperty("misCode"); $this->__addProperty("amount", 0, "numeric"); //check this validation - $this->__addProperty("currency", "", false); + $this->__addProperty("currency"); $this->__addProperty("deliveryDate"); //check whether required in SKU Orders $this->__addProperty("shipbyDate"); //check whether required in SKU Orders $this->__addProperty("customerName",""); $this->__addProperty("purchaseOrderNumber"); $this->__addProperty("consolidatedInvoice"); $this->__addProperty("tax"); + $this->__addProperty("instructions"); } @@ -80,6 +81,25 @@ public function newSKUItem($skuCode, $sourceItemId, $quantity = 1) { return $item; } + /** + * newSourceProductIdItem function. + * + * @access public + * @param string $sourceProductId + * @param mixed $sourceItemId + * @param integer $quantity + * @return OneFlowItem + */ + public function newSourceProductIdItem($sourceProductId, $sourceItemId, $quantity = 1) { + $item = new OneFlowItem(); + $item->setSourceItemId($sourceItemId); + $item->setQuantity($quantity); + $item->setSourceProductId($sourceProductId); + + $this->items[] = $item; + return $item; + } + /** * newStockItem function. * @@ -197,6 +217,18 @@ public function setEmail($email) { public function setExtraData($extraData) { $this->extraData = $extraData; } + + /** + * setInstructions function. + * + * @access public + * @param string $instructions + * @return void + */ + public function setInstructions($instructions) + { + $this->instructions = $instructions; + } } ?> diff --git a/src/order/orderData/shipment/address/address.php b/src/order/orderData/shipment/address/address.php index b836b82..bd0d422 100644 --- a/src/order/orderData/shipment/address/address.php +++ b/src/order/orderData/shipment/address/address.php @@ -22,7 +22,7 @@ public function init() { $this->__addProperty("address3", ""); $this->__addProperty("town", "", true); $this->__addProperty("state", ""); - $this->__addProperty("postcode", "", true); + $this->__addProperty("postcode", ""); $this->__addProperty("isoCountry", "", true); $this->__addProperty("country", ""); $this->__addProperty("phone"); @@ -30,4 +30,4 @@ public function init() { } } -?> \ No newline at end of file +?> diff --git a/src/order/orderData/shipment/attachments/attachments.php b/src/order/orderData/shipment/attachments/attachments.php index 1825a14..5cb8b13 100644 --- a/src/order/orderData/shipment/attachments/attachments.php +++ b/src/order/orderData/shipment/attachments/attachments.php @@ -16,6 +16,8 @@ class OneFlowAttachment extends OneFlowBase { public function init() { $this->__addProperty("path", "", true); $this->__addProperty("type", "", false); + $this->__addProperty("contentType"); + $this->__addProperty("fetch"); } /** @@ -28,6 +30,39 @@ public function init() { public function setPath($path) { $this->path = $path; } + + /** + * setType function. + * + * @access public + * @param string $type + * @return void + */ + public function setType($type) { + $this->type = $type; + } + + /** + * setContentType function. + * + * @access public + * @param string $contentType + * @return void + */ + public function setContentType($contentType) { + $this->contentType = $contentType; + } + + /** + * setFetch function. + * + * @access public + * @param boolean $fetch + * @return void + */ + public function setFetch($fetch) { + $this->fetch = $fetch; + } } -?> \ No newline at end of file +?> diff --git a/src/order/orderData/shipment/shipment.php b/src/order/orderData/shipment/shipment.php index 04035d3..5315f0e 100644 --- a/src/order/orderData/shipment/shipment.php +++ b/src/order/orderData/shipment/shipment.php @@ -30,6 +30,8 @@ public function init() { $this->__addProperty("cost"); $this->__addProperty("slaDays"); $this->__addProperty("dispatchAlert"); + $this->__addProperty("canShipEarly"); + $this->__addProperty("shipByDate"); } /** @@ -39,13 +41,17 @@ public function init() { * * @param string $path * @param null|string $type + * @param null|string $contentType + * @param null|boolean $fetch * * @return \OneFlowAttachment */ - public function newAttachment($path, $type = null) { + public function newAttachment($path, $type = null, $contentType = null, $fetch = null) { $attachment = new OneFlowAttachment(); $attachment->setPath($path); - if($type) $attachment->setValue("type", $type); + if($type) $attachment->setType($type); + if($contentType) $attachment->setContentType($contentType); + if($fetch !== null) $attachment->setFetch($fetch); $this->attachments[] = $attachment; return end($this->attachments); } @@ -183,6 +189,30 @@ public function setLabelName($labelName) { public function setSlaDays($slaDays) { $this->slaDays = $slaDays; } + + /** + * setCanShipEarly function. + * + * @access public + * @param boolean $canShipEarly + * @return void + */ + public function setCanShipEarly($canShipEarly) + { + $this->canShipEarly = $canShipEarly; + } + + /** + * setShipByDate function. + * + * @access public + * @param string $shipByDate Using the format YYYY-MM-DD + * @return void + */ + public function setShipByDate($shipByDate) + { + $this->shipByDate = $shipByDate; + } } ?> diff --git a/src/order/orderData/stockItem/stockItem.php b/src/order/orderData/stockItem/stockItem.php index 8973173..683f296 100644 --- a/src/order/orderData/stockItem/stockItem.php +++ b/src/order/orderData/stockItem/stockItem.php @@ -17,6 +17,8 @@ public function init() { $this->__addProperty("code"); $this->__addProperty("quantity", 1, false); $this->__addProperty("shipmentIndex"); + $this->__addProperty("name"); + $this->__addProperty("unitPrice"); } /** @@ -63,6 +65,30 @@ public function setShipment($shipment) { public function setShipmentIndex($shipmentIndex) { $this->shipmentIndex = $shipmentIndex; } + + /** + * setName function. + * + * @access public + * @param string $name + * @return void + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * setUnitPrice function. + * + * @access public + * @param number $unitPrice + * @return void + */ + public function setUnitPrice($unitPrice) + { + $this->unitPrice = $unitPrice; + } } ?> diff --git a/tests/order/orderTest.php b/tests/order/orderTest.php index f2fd205..3278d29 100644 --- a/tests/order/orderTest.php +++ b/tests/order/orderTest.php @@ -13,6 +13,7 @@ public function testCanBuildASingleItemOrder() $orderData->setSourceOrderId('uniqueSourceOrderId'); $orderData->setCustomerName('customerName'); $orderData->setEmail('customerEmail'); + $orderData->setInstructions('some instructions'); $orderData->setExtraData([ 'param1' => 'value1', 'param2' => 'value2' @@ -22,6 +23,9 @@ public function testCanBuildASingleItemOrder() $item->setPrintQuantity(1); $item->setBarcode('customItemBarcode'); $item->setDispatchAlert('my item dispatch alert'); + $item->setUnitCost(3.3); + $item->setUnitPrice(4.4); + $item->setUnitWeight(5.5); $item->setExtraData([ 'param3' => 'value3', 'param4' => 'value4' @@ -29,11 +33,13 @@ public function testCanBuildASingleItemOrder() $component = $item->newComponent('componentCode'); $component->setFetchUrl('http://site.com/file.pdf'); + $component->setLocalFile(false); $component->setBarcode('customComponentBarcode'); $component->setPreflight(true); $component->setPreflightProfile('custom'); $component->setPreflightProfileId('preflightProfileId'); $component->setBarcode('customComponentBarcode'); + $component->setDuplicate(5); $component->addAttribute('fooString', 'bar'); $component->addAttribute('fooNumber', 123); $component->setExtraData([ @@ -41,7 +47,17 @@ public function testCanBuildASingleItemOrder() 'param6' => 'value6' ]); + $sourceProductItem = $orderData->newSourceProductIdItem('isbn', 'itemId2', 2); + + $textComponent = $sourceProductItem->addTextComponent(); + $textComponent->addAttribute('custom', 'value'); + + $coverComponent = $sourceProductItem->addCoverComponent(); + $coverComponent->addAttribute('additional', 'value'); + $stockItem = $orderData->newStockItem('stockCode', 100); + $stockItem->setName('my name'); + $stockItem->setUnitPrice(2.2); $shipment = $orderData->newShipment(); $shipment->setShipTo( @@ -73,10 +89,18 @@ public function testCanBuildASingleItemOrder() ); $shipment->setCarrier('carrierCode', 'carrierService'); $shipment->setCarrierByAlias('carrierAlias'); - $shipment->newAttachment('http://site.com/attachment.pdf', 'insert'); + $shipment->newAttachment( + 'http://site.com/attachment.pdf', + 'insert', + 'application/pdf', + false + ); $shipment->setDispatchAlert('my shipment dispatch alert'); $shipment->setLabelName('labelName'); $shipment->setSlaDays(5); + $shipment->setCanShipEarly(false); + $shipment->setShipByDate('2019-04-01'); + $item->setShipment($shipment); $stockItem->setShipment($shipment); @@ -99,11 +123,12 @@ public function testCanBuildASingleItemOrder() $this->assertEquals('uniqueSourceOrderId', $result->orderData->sourceOrderId); $this->assertEquals('customerName', $result->orderData->customerName); $this->assertEquals('customerEmail', $result->orderData->email); + $this->assertEquals('some instructions', $result->orderData->instructions); $this->assertEquals('value1', $result->orderData->extraData->param1); $this->assertEquals('value2', $result->orderData->extraData->param2); // Items - $this->assertEquals(1, count($result->orderData->items)); + $this->assertEquals(2, count($result->orderData->items)); $outputItem = $result->orderData->items[0]; $this->assertEquals('skuCode', $outputItem->sku); $this->assertEquals('itemId', $outputItem->sourceItemId); @@ -111,6 +136,9 @@ public function testCanBuildASingleItemOrder() $this->assertEquals(5, $outputItem->quantity); $this->assertEquals(1, $outputItem->printQuantity); $this->assertEquals(0, $outputItem->shipmentIndex); + $this->assertEquals(3.3, $outputItem->unitCost); + $this->assertEquals(4.4, $outputItem->unitPrice); + $this->assertEquals(5.5, $outputItem->unitWeight); $this->assertEquals('my item dispatch alert', $outputItem->dispatchAlert); $this->assertObjectHasAttribute('extraData', $outputItem); $this->assertEquals('value3', $outputItem->extraData->param3); @@ -123,6 +151,7 @@ public function testCanBuildASingleItemOrder() $this->assertEquals('customComponentBarcode', $outputComponent->barcode); $this->assertEquals(true, $outputComponent->fetch); $this->assertEquals(false, $outputComponent->localFile); + $this->assertEquals(5, $outputComponent->duplicate); $this->assertObjectHasAttribute('attributes', $outputComponent); $this->assertEquals('bar', $outputComponent->attributes->fooString); $this->assertEquals(123, $outputComponent->attributes->fooNumber); @@ -133,10 +162,27 @@ public function testCanBuildASingleItemOrder() $this->assertEquals('value5', $outputComponent->extraData->param5); $this->assertEquals('value6', $outputComponent->extraData->param6); + // Source Product Item + $outputSourceProductItem = $result->orderData->items[1]; + $this->assertEmpty($outputSourceProductItem->sku); + $this->assertEquals('isbn', $outputSourceProductItem->sourceProductId); + $this->assertEquals('itemId2', $outputSourceProductItem->sourceItemId); + $this->assertEquals('2', $outputSourceProductItem->quantity); + + $this->assertEquals(2, count($outputSourceProductItem->components)); + $outputTextComponent = $outputSourceProductItem->components[0]; + $outputCoverComponent = $outputSourceProductItem->components[1]; + $this->assertEquals('text', $outputTextComponent->code); + $this->assertObjectHasAttribute('custom', $outputTextComponent->attributes); + $this->assertEquals('cover', $outputCoverComponent->code); + $this->assertObjectHasAttribute('additional', $outputCoverComponent->attributes); + // Stock items $this->assertEquals(1, count($result->orderData->stockItems)); $outputStockItem = $result->orderData->stockItems[0]; $this->assertEquals('stockCode', $outputStockItem->code); + $this->assertEquals('my name', $outputStockItem->name); + $this->assertEquals(2.2, $outputStockItem->unitPrice); $this->assertEquals(100, $outputStockItem->quantity); $this->assertEquals(0, $outputStockItem->shipmentIndex); @@ -147,6 +193,8 @@ public function testCanBuildASingleItemOrder() $this->assertEquals(0, $outputShipment->shipmentIndex); $this->assertEquals('my shipment dispatch alert', $outputShipment->dispatchAlert); $this->assertEquals('labelName', $outputShipment->labelName); + $this->assertEquals(false, $outputShipment->canShipEarly); + $this->assertEquals('2019-04-01', $outputShipment->shipByDate); $this->assertObjectHasAttribute('shipTo', $outputShipment); $this->assertEquals('name', $outputShipment->shipTo->name); @@ -185,6 +233,8 @@ public function testCanBuildASingleItemOrder() $outputAttachment = $outputShipment->attachments[0]; $this->assertEquals('http://site.com/attachment.pdf', $outputAttachment->path); $this->assertEquals('insert', $outputAttachment->type); + $this->assertEquals('application/pdf', $outputAttachment->contentType); + $this->assertEquals(false, $outputAttachment->fetch); } }