Skip to content

Commit

Permalink
shoppingflux#44 Add channel resource linked to orders
Browse files Browse the repository at this point in the history
  • Loading branch information
ronan-gloo authored and ddattee committed Aug 1, 2018
1 parent b08b5b0 commit 225d3cf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Api/Order/OrderItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,16 @@ public function getTotalPrice()
{
return $this->getUnitPrice() * $this->getQuantity();
}

/**
* @return array
*/
public function toArray()
{
return [
'reference' => $this->getReference(),
'quantity' => $this->getQuantity(),
'price' => $this->getUnitPrice()
];
}
}
10 changes: 10 additions & 0 deletions src/Api/Order/OrderItemCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ public function getIterator()
return new \ArrayIterator($this->items);
}

/**
* @return array
*/
public function toArray()
{
return array_map(function(OrderItem $item) {
return $item->toArray();
}, $this->items);
}

/**
* @param OrderItem $item
*/
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/Api/Order/OrderItemCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,10 @@ public function testItemsAreWellConstructedFromArray()

$this->assertEquals($items[1], $secondOne);
}

public function testCollectionCanBeRevertedBackToArray()
{
$instance = OrderItemCollection::fromProperties($this->items);
$this->assertEquals($this->items, $instance->toArray());
}
}

0 comments on commit 225d3cf

Please sign in to comment.