Files
kupshop/bundles/KupShop/GTMBundle/Ecommerce/ClickRemoveFromCart.php
2025-08-02 16:30:27 +02:00

33 lines
1.0 KiB
PHP

<?php
namespace KupShop\GTMBundle\Ecommerce;
class ClickRemoveFromCart extends AbstractEcommerce
{
/**
* Specific PageData.
*
* @throws \Exception
*/
public function getData(&$dataContainer)
{
$addedProduct = $this->productLoader->getProducts([$this->pageData['product']], $this->view);
if (findModule(\Modules::COMPONENTS)) {
$dataContainer->event = 'remove_from_cart';
$fk = array_key_first($addedProduct);
$addedProduct[$fk]['quantity'] = $this->pageData['quantity'] ?: 1;
$dataContainer->ecommerce = (object) [
'items' => (object) [
$addedProduct[$fk],
],
];
} else {
$dataContainer->event = 'removeFromCart';
$dataContainer->remove = new \stdClass();
$dataContainer->remove->products = $addedProduct;
$addedProduct[0]->quantity = $this->pageData['quantity'] ?: 1;
}
$dataContainer->_clear = true;
}
}