Skip to content

Commit

Permalink
wip - finishing orders
Browse files Browse the repository at this point in the history
  • Loading branch information
diegofelix committed Jul 12, 2018
1 parent 6638af2 commit f48f66d
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/Elements/ElementBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ public function generateXMLArray(): array
return $element;
}

public function generateElementXMLArray(string $name, ?string $value = '', array $attributes = []): array
public function generateElementXMLArray(string $name, $value = '', array $attributes = []): array
{
$element = [
'#name' => $name,
];

if ($value) {
$element['#value'] = htmlspecialchars($value);
$element['#value'] = is_string($value) ? htmlspecialchars($value) : $value;
}

if (!empty($attributes)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Elements/ElementInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function generateXMLArray(): array;
* - #attributes : key/value array of XML attributes for element.
* - #children : array of child element arrays.
*/
public function generateElementXMLArray(string $name, ?string $value, array $attributes = []): array;
public function generateElementXMLArray(string $name, $value, array $attributes = []): array;

/**
* Builds array for an XML element that represents multiple values.
Expand Down
30 changes: 28 additions & 2 deletions src/Elements/FeedElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public function addProduct(ProductElementInterface $product): FeedElementInterfa
return $this;
}

public function addInteraction(InteractionElement $interaction): FeedElementInterface
{
$this->interactions[] = $interaction;
return $this;
}

public function addBrand(BrandElementInterface $brand): FeedElementInterface
{
$this->brands[$brand->getExternalId()] = $brand;
Expand Down Expand Up @@ -99,7 +105,7 @@ public function generateXMLArray(): array
'xmlns' => 'http://www.bazaarvoice.com/xs/PRR/ProductFeed/'.self::$apiVersion,
'name' => $this->name,
'incremental' => $this->incremental ? 'true' : 'false',
'extractDate' => date('Y-m-d').'T'.date('H:i:s'),
'extractDate' => date('Y-m-d\TH:i:s'),
],
];

Expand All @@ -115,6 +121,12 @@ public function generateXMLArray(): array
$element['#children'][] = $products;
}

if ($interactions = $this->generateInteractionsXMLArray()) {
$element['#children'][] = $interactions;
}



return $element;
}

Expand Down Expand Up @@ -146,7 +158,7 @@ private function generateCategoriesXMLArray(): array
return $element;
}

private function generateProductsXMLArray(): array
public function generateProductsXMLArray(): array
{
if (!count($this->products)) {
return [];
Expand All @@ -159,4 +171,18 @@ private function generateProductsXMLArray(): array

return $element;
}

private function generateInteractionsXMLArray(): array
{
if (!count($this->interactions)) {
return [];
}

// $element = $this->generateElementXMLArray('Interactions');
foreach ($this->interactions as $interaction) {
$element['#children'][] = $interaction->generateXMLArray();
}

return $element;
}
}
16 changes: 15 additions & 1 deletion src/Elements/InteractionElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,23 @@ public function generateXMLArray(): array
$this->generateElementXMLArray('UserName', $this->userName),
$this->generateElementXMLArray('UserID', $this->userId),
$this->generateElementXMLArray('Locale', $this->locale),
$this->generateMultipleElementsXMLArray('Products', $this->products),
$this->generateProductsXMLArray(),
];

return $element;
}

private function generateProductsXMLArray(): array
{
if (!count($this->products)) {
return [];
}

$element = parent::generateElementXMLArray('Products');
foreach ($this->products as $product) {
$element['#children'][] = $product->generateXMLArray();
}

return $element;
}
}
4 changes: 2 additions & 2 deletions src/Order/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
class Feed extends AbstractFeed implements FeedInterface
{
public function newOrder(
string $transationDate,
string $transactionDate,
string $emailAddress,
string $userName,
string $userId,
string $locale,
array $products
): InteractionElement {
return new InteractionElement(
$transationDate,
$transactionDate,
$emailAddress,
$userName,
$userId,
Expand Down

0 comments on commit f48f66d

Please sign in to comment.