Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions src/Entity/PackageAssociated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php

namespace Ups\Entity;

use DOMDocument;
use DOMElement;
use Ups\NodeInterface;

class PackageAssociated implements NodeInterface
{

/**
* @var string
*/
private $packageNumber;

/**
* @var string
*/
private $productAmount;

/**
* @param null|object $attributes
*/
public function __construct($attributes = null)
{
if (null !== $attributes) {
if (isset($attributes->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;
}
}
78 changes: 78 additions & 0 deletions src/Entity/PackingListInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace Ups\Entity;

use DOMDocument;
use DOMElement;
use Ups\NodeInterface;

class PackingListInfo implements NodeInterface
{

/**
* @var PackageAssociateds
*/
private $PackageAssociateds = [];


/**
* @param null|object $attributes
*/
public function __construct($attributes = null)
{
if (null !== $attributes) {
if (isset($attributes->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;
}

}
31 changes: 31 additions & 0 deletions src/Entity/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class Product implements NodeInterface
*/
private $unit;

/**
* @var PackingListInfo
*/
private $PackingListInfo;

/**
* @param null|object $attributes
*/
Expand All @@ -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);
}
}
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}