diff --git a/src/Entity/PackageAssociated.php b/src/Entity/PackageAssociated.php new file mode 100644 index 0000000..cd91b05 --- /dev/null +++ b/src/Entity/PackageAssociated.php @@ -0,0 +1,100 @@ +PackageNumber)) { + $this->setPackageNumber($attributes->PackageNumber); + } + if (isset($attributes->ProductAmount)) { + $this->setProductAmount($attributes->ProductAmount); + } + } + } + + + /** + * @param null|DOMDocument $document + * + * @return DOMElement + */ + public function toNode(DOMDocument $document = null) + { + if (null === $document) { + $document = new DOMDocument(); + } + + $node = $document->createElement('PackageAssociated'); + + if ($this->getPackageNumber() !== null) { + $node->appendChild($document->createElement('PackageNumber', $this->getPackageNumber())); + } + if ($this->getProductAmount() !== null) { + $node->appendChild($document->createElement('ProductAmount', $this->getProductAmount())); + } + + return $node; + } + + /** + * @param $packageNumber + * + * @return $this + */ + public function setPackageNumber($packageNumber) + { + $this->packageNumber = $packageNumber; + + return $this; + } + + /** + * @return string + */ + public function getPackageNumber() + { + return $this->packageNumber; + } + + /** + * @param string $ProductAmount + * + * @return $this + */ + public function setProductAmount($ProductAmount) + { + $this->productAmount = $ProductAmount; + + return $this; + } + + /** + * @return string + */ + public function getProductAmount() + { + return $this->productAmount; + } +} diff --git a/src/Entity/PackingListInfo.php b/src/Entity/PackingListInfo.php new file mode 100644 index 0000000..35833bd --- /dev/null +++ b/src/Entity/PackingListInfo.php @@ -0,0 +1,78 @@ +PackageAssociateds)) { + foreach ($attributes->PackageAssociateds as $PackageAssociated) { + $this->addPackageAssociated(new PackageAssociated($PackageAssociated)); + } + } + } + } + + /** + * @param null|DOMDocument $document + * + * @return DOMElement + */ + public function toNode(DOMDocument $document = null) + { + if (null === $document) { + $document = new DOMDocument(); + } + + $node = $document->createElement('PackingListInfo'); + + if ($this->getPackageAssociateds() !== null) { + foreach ($this->PackageAssociateds as $PackageAssociated) { + $node->appendChild($PackageAssociated->toNode($document)); + } + } + + return $node; + } + + /** + * @param PackageAssociated $PackageAssociated + * + * @return $this + */ + public function addPackageAssociated(PackageAssociated $PackageAssociated) + { + $this->PackageAssociateds[] = $PackageAssociated; + + if (count($this->PackageAssociateds) > 20) { + throw new \Exception('Maximum 20 package allowed'); + } + + return $this; + } + + /** + * @return PackageAssociated + */ + public function getPackageAssociateds() + { + return $this->PackageAssociateds; + } + +} diff --git a/src/Entity/Product.php b/src/Entity/Product.php index 1962ac2..f6669bb 100644 --- a/src/Entity/Product.php +++ b/src/Entity/Product.php @@ -46,6 +46,11 @@ class Product implements NodeInterface */ private $unit; + /** + * @var PackingListInfo + */ + private $PackingListInfo; + /** * @param null|object $attributes */ @@ -64,6 +69,9 @@ public function __construct($attributes = null) if (isset($attributes->OriginCountryCode)) { $this->setOriginCountryCode($attributes->OriginCountryCode); } + if (isset($attributes->PackingListInfo)) { + $this->setOriginCountryCode($attributes->PackingListInfo); + } } } @@ -97,6 +105,9 @@ public function toNode(DOMDocument $document = null) if ($this->getOriginCountryCode() !== null) { $node->appendChild($document->createElement('OriginCountryCode', $this->getOriginCountryCode())); } + if ($this->getPackingListInfo() !== null) { + $node->appendChild($this->getPackingListInfo()->toNode($document)); + } return $node; } @@ -252,4 +263,24 @@ public function getOriginCountryCode() { return $this->originCountryCode; } + + /** + * @param PackingListInfo $PackingListInfo + * + * @return $this + */ + public function setPackingListInfo(PackingListInfo $PackingListInfo) + { + $this->PackingListInfo = $PackingListInfo; + + return $this; + } + + /** + * @return PackingListInfo + */ + public function getPackingListInfo() + { + return $this->PackingListInfo; + } }