Skip to content

Commit

Permalink
Merge branch 'dnna-reset'
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandoorn committed Aug 30, 2018
2 parents b816d12 + a84819b commit 1024e39
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/TagManager/CheckoutStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ final class CheckoutStep implements CheckoutStepInterface
const STEP_CONFIRM = 5;
const STEP_THANKYOU = 6;

/**
* @var array
*/
private $products = [];

/**
* @var GoogleTagManagerInterface
*/
Expand All @@ -43,18 +38,14 @@ public function __construct(GoogleTagManagerInterface $googleTagManager)
*/
public function addStep(OrderInterface $order, int $step): void
{
if ($step < self::STEP_THANKYOU) {
$this->setProducts($order);
}

$checkout = [
'actionField' => [
'step' => $step,
],
];

if (!empty($this->products)) {
$checkout['products'] = $this->products;
if ($step < self::STEP_THANKYOU) {
$checkout['products'] = $this->getProducts($order);
}

$this->googleTagManager->addPush([
Expand All @@ -67,20 +58,26 @@ public function addStep(OrderInterface $order, int $step): void

/**
* @param OrderInterface $order
* @return array
*/
private function setProducts(OrderInterface $order): void
private function getProducts(OrderInterface $order): array
{
$products = [];

foreach ($order->getItems() as $item) {
$this->addProduct($item);
$products[] = $this->createProduct($item);
}

return $products;
}

/**
* @param OrderItemInterface $item
* @return array
*/
private function addProduct(OrderItemInterface $item): void
private function createProduct(OrderItemInterface $item): array
{
$this->products[] = [
return [
'name' => $item->getProduct()->getName(),
'id' => $item->getProduct()->getId(),
'quantity' => $item->getQuantity(),
Expand Down

0 comments on commit 1024e39

Please sign in to comment.