35 lines
1.2 KiB
PHP
35 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace KupShop\GTMBundle\Ecommerce;
|
|
|
|
class ClickAddToCart extends AbstractEcommerce
|
|
{
|
|
/**
|
|
* Specific PageData.
|
|
*
|
|
* @throws \Exception
|
|
*/
|
|
public function getData(&$dataContainer)
|
|
{
|
|
$productObj = $this->pageData['product'];
|
|
$addedProduct = $this->productLoader->getProducts([$productObj], $this->view);
|
|
$dataContainer->add = new \stdClass();
|
|
if (findModule(\Modules::COMPONENTS)) {
|
|
$dataContainer->event = 'add_to_cart';
|
|
$fk = array_key_first($addedProduct);
|
|
$addedProduct[$fk]['quantity'] = $this->pageData['quantity'] ?: 1;
|
|
$dataContainer->ecommerce = (object) [
|
|
'items' => $addedProduct,
|
|
];
|
|
} else {
|
|
$dataContainer->event = 'addToCart';
|
|
$addedProduct[0]->quantity = $this->pageData['quantity'] ?: 1;
|
|
$dataContainer->add->products = $addedProduct;
|
|
}
|
|
|
|
$dataContainer->add->listName = $this->productLoader->getListType($this->view, $this->pageData);
|
|
$dataContainer->add->listId = $this->productLoader->getListId($this->view, $this->pageData);
|
|
$dataContainer->_clear = true;
|
|
}
|
|
}
|