67 lines
1.8 KiB
PHP
67 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace KupShop\GTMBundle\Ecommerce;
|
|
|
|
use KupShop\GTMBundle\Utils\DataLoaders\Products;
|
|
use KupShop\KupShopBundle\Context\CurrencyContext;
|
|
|
|
class AddToCart extends AbstractEcommerce
|
|
{
|
|
/**
|
|
* @var Products
|
|
*/
|
|
protected $productLoader;
|
|
|
|
protected $currencyContext;
|
|
|
|
/**
|
|
* Specific PageData.
|
|
*
|
|
* @throws \Exception
|
|
*/
|
|
public function getData(&$dataContainer)
|
|
{
|
|
if (is_array($this->pageData['addedToCart'])) {
|
|
$addedProducts = $this->pageData['addedToCart'];
|
|
} else {
|
|
$addedProducts = [$this->pageData['addedToCart']];
|
|
}
|
|
|
|
$dataContainer->event = 'addToCart';
|
|
|
|
$addedProduct = $addedProducts[0];
|
|
$productObj = $addedProduct->fetchProduct();
|
|
$productObj->fetchVariations();
|
|
$productObj->fetchSections();
|
|
|
|
$addedProduct = $this->productLoader->getProducts([$productObj->getObject()], $this->view);
|
|
$addedProduct[0]->quantity = $addedProducts[0]->pieces_added ?? 1;
|
|
$dataContainer->add = new \stdClass();
|
|
$dataContainer->add->products = $addedProduct;
|
|
|
|
if ($this->pageData['listType'] ?? false) {
|
|
$this->pageData['listType'] = 'detail: ';
|
|
}
|
|
|
|
$dataContainer->add->listName = $this->productLoader->getListType($this->view, $this->pageData);
|
|
$dataContainer->add->listId = $this->productLoader->getListId($this->view, $this->pageData);
|
|
$dataContainer->_clear = true;
|
|
}
|
|
|
|
/**
|
|
* @required
|
|
*/
|
|
public function setProductLoader(Products $productLoader): void
|
|
{
|
|
$this->productLoader = $productLoader;
|
|
}
|
|
|
|
/**
|
|
* @required
|
|
*/
|
|
public function setCurrencyContext(CurrencyContext $currencyContext): void
|
|
{
|
|
$this->currencyContext = $currencyContext;
|
|
}
|
|
}
|