first commit

This commit is contained in:
2025-08-02 16:30:27 +02:00
commit 23646bfcee
14851 changed files with 1750626 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
<?php
namespace KupShop\GTMBundle\Ecommerce;
use KupShop\GTMBundle\ServerSideGTMEvent\FetchUsersStatsOrderData;
use KupShop\GTMBundle\Utils\DataLoaders\Products;
use KupShop\GTMBundle\Utils\PriceComputer;
use KupShop\GTMBundle\Utils\ViewDataHelper;
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
use KupShop\KupShopBundle\Views\View;
abstract class AbstractEcommerce
{
use ViewDataHelper;
use FetchUsersStatsOrderData;
/** @var View */
protected $view;
/**
* @var PriceComputer
*/
protected $priceComputer;
protected $pageData;
/**
* @var Products
*/
protected $productLoader;
public function __construct()
{
// Největší hnus světa, ale prostě to jinak nejde
// Je to kvůli kolizi předefinování servisy symfony a typový kontroly php
// Až se odstrihne v2 / komponentový GTM, může se tohle zahodit
$this->productLoader = ServiceContainer::getService(findModule(\Modules::COMPONENTS) ? \KupShop\ComponentsBundle\GTM\Utils\DataLoaders\Products::class : Products::class);
}
/**
* Specific PageData.
*/
abstract public function getData(&$dataContainer);
public function setView(&$view)
{
$this->view = $view;
}
public function setPageData($pageData)
{
$this->pageData = $pageData;
}
protected function addAdditionalFields(&$container, $object)
{
}
/**
* @required
*/
public function setPriceComputer(PriceComputer $priceComputer): void
{
$this->priceComputer = $priceComputer;
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace KupShop\GTMBundle\Ecommerce;
class AddDeliveryInfo extends AbstractEcommerce
{
/**
* Specific PageData.
*
* @throws \Exception
*/
public function getData(&$dataContainer)
{
/** @var \Delivery $delivery */
$delivery = $this->pageData['delivery'];
$dataContainer->event = 'addDeliveryInfo';
$dataContainer->addDeliveryInfo = new \stdClass();
$dataContainer->addDeliveryInfo->deliveryType = $delivery->getClassName() ?? '';
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace KupShop\GTMBundle\Ecommerce;
class AddPaymentInfo extends AbstractEcommerce
{
/**
* Specific PageData.
*
* @throws \Exception
*/
public function getData(&$dataContainer)
{
/** @var \Payment $delivery */
$payment = $this->pageData['payment'];
if ($method = ($this->pageData['method'] ?? false)) {
$paymentType = $method['name'];
} else {
$paymentType = is_object($payment['class']) ? $payment['class']->getName() : $payment['name'];
}
$dataContainer->event = 'addPaymentInfo';
$dataContainer->addPaymentInfo = new \stdClass();
$dataContainer->addPaymentInfo->paymentType = $paymentType;
$dataContainer->addPaymentInfo->payment = [
'type' => $payment['name'] ?? '',
'method' => [
'id' => $method['id'] ?? null,
],
];
}
}

View File

@@ -0,0 +1,66 @@
<?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;
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace KupShop\GTMBundle\Ecommerce;
use KupShop\GTMBundle\Utils\DataLoaders\Products;
use KupShop\KupShopBundle\Context\CurrencyContext;
class AddToWishList extends AbstractEcommerce
{
/**
* @var Products
*/
protected $productLoader;
protected $currencyContext;
/**
* Specific PageData.
*
* @throws \Exception
*/
public function getData(&$dataContainer)
{
$dataContainer->event = 'addToWishlist';
$products = !empty($this->pageData['addedToWishList']) ? [$this->pageData['addedToWishList']] : $this->pageData['products'];
$addedProduct = $this->productLoader->getProducts($products);
$dataContainer->products = $addedProduct;
$dataContainer->_clear = true;
}
/**
* @required
*/
public function setProductLoader(Products $productLoader): void
{
$this->productLoader = $productLoader;
}
/**
* @required
*/
public function setCurrencyContext(CurrencyContext $currencyContext): void
{
$this->currencyContext = $currencyContext;
}
}

View File

@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace KupShop\GTMBundle\Ecommerce;
class ApplyFilterCampaigns extends AbstractEcommerce
{
private string $eventName = 'applyFilterCampaigns';
/**
* Specific PageData.
*
* @throws \Exception
*/
public function getData(&$dataContainer): void
{
$dataContainer->event = $this->eventName;
$dataContainer->filtrValue = ['active' => ''];
$dataContainer->filtrCampaignId = (string) $this->pageData['id'];
$dataContainer->filtrCampaignName = $this->pageData['name'];
}
}

View File

@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
namespace KupShop\GTMBundle\Ecommerce;
use KupShop\CatalogBundle\View\CategoryView;
class ApplyFilterParams extends AbstractEcommerce
{
private string $eventName = 'applyFilterParams';
/**
* Specific PageData.
*
* @throws \Exception
*/
public function getData(&$dataContainer): void
{
$dataContainer->event = $this->eventName;
$input = $this->pageData['inputValue'] ?? null;
$dataContainer->filtrId = $filterId = $this->pageData['filterId'];
$dataContainer->filtrName = $input['param_name'] ?? $input['name'] ?? '';
$min = $input['min'] ?? $input['values']['min'] ?? '';
$max = $input['max'] ?? $input['values']['max'] ?? '';
if ($this->view instanceof CategoryView) {
if ($parameter = $this->view->filterParams?->getParameters()[$filterId]['values'] ?? false) {
$input['value'] = sprintf('%s - %s', $parameter['min'] ?? $min, $parameter['max'] ?? $max);
}
}
$dataContainer->filtrValue = [
'id' => $input['id'],
'name' => $input['name'],
'min' => $min,
'max' => $max,
'active' => $input['active'] ?? '',
'value' => $input['value'] ?? '',
];
}
}

View File

@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
namespace KupShop\GTMBundle\Ecommerce;
class ApplyFilterSort extends AbstractEcommerce
{
private string $eventName = 'applyFilterSort';
/**
* Specific PageData.
*
* @throws \Exception
*/
public function getData(&$dataContainer): void
{
$dataContainer->event = $this->eventName;
$dataContainer->filtrValue = [
'id' => $this->pageData['id'],
'name' => $this->pageData['name'],
];
}
}

View File

@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace KupShop\GTMBundle\Ecommerce;
class ApplyFilterVariations extends AbstractEcommerce
{
private string $eventName = 'applyFilterVariations';
/**
* Specific PageData.
*
* @throws \Exception
*/
public function getData(&$dataContainer): void
{
$label = $this->pageData['label'];
$id = $this->pageData['id'] ?? -1;
if ($id === null) {
return;
}
$value = $label['values'][$id];
$dataContainer->event = $this->eventName;
$dataContainer->filtrVariationLabelId = $label['id'];
$dataContainer->filtrVariationName = $label['name'];
$dataContainer->filtrValue = [
'id' => $id,
'name' => $value['name'],
'active' => '',
];
}
}

View File

@@ -0,0 +1,77 @@
<?php
namespace KupShop\GTMBundle\Ecommerce;
use KupShop\GTMBundle\Utils\DataLoaders\PurchaseState;
class Checkout extends AbstractEcommerce
{
/**
* @var PurchaseState
*/
protected $purchaseStateLoader;
/**
* Specific PageData.
*/
public function getData(&$dataContainer)
{
/** @var \Cart $cart */
$cart = $this->pageData['body'];
if (empty($cart->products)) {
return;
}
$dataContainer->event = 'checkout';
$step = '';
$stepName = '';
$counter = 1;
foreach ($cart->steps as $step) {
if (!empty($step['selected'])) {
$step = $counter;
$stepName = $cart->stepName;
break;
}
$counter++;
}
$products = [];
$cart->productList->fetchSections();
$cart->productList->fetchVariations(true);
foreach ($cart->products as $product) {
$p = $this->productLoader->getData($product['product'], $this->view);
$p->quantity = $product['pieces'];
if ($p->categoryCurrent == '@breadcrumbs') {
$p->categoryCurrent = [];
}
$products[] = $p;
}
foreach ($cart->orders_charges ?: [] as $charge) {
$dataContainer->cart->charges[] = [
'id' => $charge['id'],
'title' => $charge['title'],
'price' => $this->priceComputer->getPrice($charge['price']),
];
}
$discounts = $this->purchaseStateLoader->getDiscounts($cart->getPurchaseState());
$dataContainer->checkout = [
'products' => $products,
'step' => $step,
'stepName' => $stepName,
'option' => $cart->getDeliveryType()->name,
'discounts' => $discounts,
];
}
/**
* @required
*/
public function setPurchaseStateLoader(PurchaseState $purchaseStateLoader): void
{
$this->purchaseStateLoader = $purchaseStateLoader;
}
}

View File

@@ -0,0 +1,34 @@
<?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;
}
}

View File

@@ -0,0 +1,32 @@
<?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;
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace KupShop\GTMBundle\Ecommerce;
class PhotoInteract extends AbstractEcommerce
{
public function getData(&$dataContainer)
{
$dataContainer->event = 'photoInteract';
$dataContainer->product = $this->productLoader->getData($this->pageData['product']);
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace KupShop\GTMBundle\Ecommerce;
class ProductClick extends AbstractEcommerce
{
/**
* Specific PageData.
*
* @throws \Exception
*/
public function getData(&$dataContainer)
{
$dbcfg = \Settings::getDefault();
$productOnPage = $dbcfg->cat_show_products;
$products = $this->productLoader->getProducts([$this->pageData['product'] ?? null], $this->view);
if ($this->view) {
$templateData = $this->view->getTemplateData();
$page = $templateData['body']['pager']->number ?? 1;
$products[0]->position = $this->pageData['position'] + (($page - 1) * $productOnPage);
// Když není k dispozici view, tak se bere pozice produktu, která se posílá ze šablony.
// např. když se AJAXem načítají recommended produkty v košíku #18414
} elseif (!findModule(\Modules::COMPONENTS) && ($this->pageData['position'] ?? false)) {
$products[0]->position = $this->pageData['position'];
}
$dataContainer->event = 'productClick';
$dataContainer->click = new \stdClass();
$dataContainer->click->products = $products;
$dataContainer->click->listName = $this->productLoader->getListType($this->view, $this->pageData);
$dataContainer->click->listId = $this->productLoader->getListId($this->view, $this->pageData);
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace KupShop\GTMBundle\Ecommerce;
class ProductsImpressions extends AbstractEcommerce
{
/**
* Specific PageData.
*
* @throws \Exception
*/
public function getData(&$dataContainer)
{
if (!$this->pageData['products']) {
return false;
}
$dataContainer->_clear = true;
$dataContainer->event = 'productsImpressions';
$impressions = new \stdClass();
$impressions->products = $this->productLoader->getProducts($this->pageData['products'], $this->view);
$impressions->listName = $this->productLoader->getListType($this->view, $this->pageData);
$impressions->listId = $this->productLoader->getListId($this->view, $this->pageData);
$dataContainer->impressions = $impressions;
}
}

View File

@@ -0,0 +1,56 @@
<?php
namespace KupShop\GTMBundle\Ecommerce;
use KupShop\CatalogBundle\View\CategoryView;
use KupShop\ContentBundle\Entity\Slider;
abstract class PromotionAbstractEvent extends AbstractEcommerce
{
/**
* Specific PageData.
*
* @throws \Exception
*/
public function getData(&$dataContainer)
{
$promotions = [];
$slides = $this->pageData['slider'] instanceof Slider ? $this->pageData['slider']['images'] : [$this->pageData['slide']];
$index = $this->pageData['position'] ?? null;
$indexCatalog = false;
if ($this->view instanceof CategoryView) {
$i = 1;
$sliderId = $this->pageData['slider']['id'] ?? false;
$collection = $this->view->getTemplateData()['body']['productsList'] ?? [];
foreach ($collection as $product) {
$bannerId = $product['banner']['slider']['id'] ?? $product['banner']['id'] ?? null;
if ($bannerId === $sliderId) {
$indexCatalog = $i;
break;
}
$i++;
}
}
foreach ($slides ?? [] as $key => $slide) {
if ($index && ($indexCatalog === false) && ($index - 1) != $key) {
continue;
}
$promotion = [
'id' => $slide['id'],
'name' => $slide['description'],
'creative' => $slide['slider']->name,
'position' => $key + 1,
];
if ($indexCatalog) {
$promotion['positionCatalog'] = $indexCatalog;
}
$promotions[] = $promotion;
}
$dataContainer->promotions = $promotions;
$dataContainer->_clear = true;
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace KupShop\GTMBundle\Ecommerce;
class PromotionClick extends PromotionAbstractEvent
{
/**
* Specific PageData.
*
* @throws \Exception
*/
public function getData(&$dataContainer)
{
$dataContainer->event = 'promotionClick';
parent::getData($dataContainer);
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace KupShop\GTMBundle\Ecommerce;
class PromotionImpression extends PromotionAbstractEvent
{
/**
* Specific PageData.
*
* @throws \Exception
*/
public function getData(&$dataContainer)
{
$dataContainer->event = 'promotionView';
parent::getData($dataContainer);
}
}

View File

@@ -0,0 +1,232 @@
<?php
namespace KupShop\GTMBundle\Ecommerce;
use KupShop\GTMBundle\Utils\DataLoaders\PurchaseState;
use KupShop\KupShopBundle\Context\CurrencyContext;
use KupShop\KupShopBundle\Context\LanguageContext;
use KupShop\OrderingBundle\Util\Order\DeliveryInfo;
use KupShop\OrderingBundle\Util\Order\OrderInfo;
class Purchase extends AbstractEcommerce
{
protected $currencyContext;
/**
* @var LanguageContext
*/
protected $languageContext;
/**
* @var DeliveryInfo
*/
private $deliveryInfo;
/**
* @var OrderInfo
*/
private $orderInfo;
/**
* @var PurchaseState
*/
protected $purchaseStateLoader;
/**
* Specific PageData.
*
* @throws \Exception
*/
public function getData(&$dataContainer)
{
$dbcfg = \Settings::getDefault();
$ec = new \stdClass();
$order = $this->pageData['body']['order'];
if (!empty($order) && $order instanceof \Order && !$order->getData('conversion_sent')) {
$orderVAT = $this->priceComputer->getPrice($order->total_price_array['value_vat']);
$deliveryType = $order->getDeliveryType();
$delivery = $deliveryType->getDelivery()?->getClassName() ?? '';
$payment = $deliveryType->getPayment()?->getClassName() ?? '';
$affiliation = join(' | ', [$delivery, $payment, $this->languageContext->getActiveId()]);
$discounts = $this->purchaseStateLoader->getDiscounts($order->getPurchaseState(true));
$this->addAdditionalFields($dataContainer, $order);
$dataContainer->event = 'orderSuccess';
if (!empty($order->invoice_name)) {
$dataContainer->user = $dataContainer->user ?? new \stdClass();
$dataContainer->user->name = $order->invoice_name;
$dataContainer->user->surname = $order->invoice_surname;
$dataContainer->user->email = $order->invoice_email;
$dataContainer->user->phone = $order->invoice_phone;
$dataContainer->user->address = [
'street' => $order->invoice_street,
'city' => $order->invoice_city,
'region' => $order->invoice_state,
'postalCode' => $order->invoice_zip,
'country' => $order->invoice_country,
];
}
$purchase = new \stdClass();
$purchase->id = $order->order_no;
$purchase->affiliation = $affiliation;
$purchase->paymentType = $payment;
$purchase->payment = $this->purchaseStateLoader->getPaymentObject($order);
$purchase->deliveryType = $delivery;
$currency = $this->priceComputer->getOutputCurrency();
$purchase->currency = $currency->getId();
$shippingPrice = $this->getDeliveryPrice($order);
$shippWithVat = $shippingPrice['value_with_vat'] ?? \DecimalConstants::zero();
$shippWithoutVat = $shippingPrice['value_without_vat'] ?? \DecimalConstants::zero();
$purchase->shipping = $this->priceComputer->getPrice($shippingPrice ?? toDecimal(0));
$purchase->shippingWithVat = $this->priceComputer->getPrice($shippWithVat);
$purchase->shippingWithOutVat = $this->priceComputer->getPrice($shippWithoutVat);
if (($dbcfg->analytics['google_tag_manager']['withoutDelivery'] ?? 'N') == 'Y') {
// Tohle je kvuli tomu, ze podle nastaveni nevime jestli ma byt bez nebo s dph, proto nechame rozhodnout funkce uvnitr a pak to akorat proste odectu
$tp = toDecimal($this->priceComputer->getPrice($order->getTotalPrice()));
$shipp = toDecimal($purchase->shipping);
$purchase->total = $tp->sub($shipp);
$purchase->totalWithVat = $this->priceComputer->getPrice($order->getTotalPrice()->getPriceWithVat()->sub($shippWithVat));
$purchase->totalWithoutVat = $this->priceComputer->getPrice($order->getTotalPrice()->getPriceWithoutVat()->sub($shippWithoutVat));
} else {
$purchase->total = $this->priceComputer->getPrice($order->getTotalPrice());
$purchase->totalWithVat = $this->priceComputer->getPrice($order->getTotalPrice()->getPriceWithVat());
$purchase->totalWithoutVat = $this->priceComputer->getPrice($order->getTotalPrice()->getPriceWithoutVat());
}
$purchase->totalWithoutVatAndShipping = $this->priceComputer->getPrice($order->getTotalPrice()->getPriceWithoutVat()->sub(toDecimal($shippingPrice['value_without_vat'] ?? 0)));
$purchase->vat = $orderVAT;
$purchase->flags = array_filter(array_keys($order->getFlags()));
if ($coupons = OrderInfo::getUsedCoupons($order)) {
$coupons = join(',', $coupons);
}
$purchase->coupons = $coupons ?: '';
$purchase->heurekaDisagree = $order->getData('heurekaDisagree');
$purchase->discounts = $discounts;
$purchase->products = [];
$order->productList->fetchVariations(true);
$order->productList->fetchSections();
$order->productList->fetchProducers();
$order->productList->fetchMainImages(1);
foreach ($order->fetchItems() as $item) {
if ($item['id_product']) {
$p = $this->productLoader->getData($item['product'], $this->view);
$p->quantity = $item['pieces'];
if ($p->categoryCurrent == '@breadcrumbs') {
$p->categoryCurrent = [];
}
$prices = $this->purchaseStateLoader->getPrices($item);
$p->price = $prices['price'];
$p->priceWithVat = $prices['priceWithVat'];
$p->priceWithoutVat = $prices['priceWithoutVat'];
$p->priceVat = $prices['priceVat'];
$purchase->products[] = $p;
}
}
$purchase->charges = $this->purchaseStateLoader->getCharges($order);
$this->appendAfilliateCodes($purchase);
$dataContainer->purchase = $purchase;
if (!$dataContainer->user) {
$dataContainer->user = new \stdClass();
}
$dataContainer->user->email = $order->invoice_email;
$userStats = $this->fetchUsersStatsOrderData($order);
$dataContainer->user->lastOrderDate = $userStats['last_date'] ?? null;
$dataContainer->user->firstOrderDate = $userStats['first_date'] ?? null;
$dataContainer->user->countOrders = $userStats['count'] ?? null;
$dataContainer->user->shaEmail = hash('sha256', $order->invoice_email.($dbcfg->analytics['google_tag_manager']['sha_salt'] ?? false ?: ''));
}
}
/**
* @required
*/
public function setLanguageContext(LanguageContext $languageContext): void
{
$this->languageContext = $languageContext;
}
/**
* @return \Decimal
*/
public function getDeliveryPrice(\Order $order)
{
$delivery_item = $this->deliveryInfo->getDeliveryItem($order);
return $delivery_item ? $order->fetchItems()[$delivery_item]['total_price'] : null;
}
/**
* @required
*/
public function setPurchaseStateLoader(PurchaseState $purchaseStateLoader): void
{
$this->purchaseStateLoader = $purchaseStateLoader;
}
protected function appendAfilliateCodes(\stdClass &$purchase)
{
$request = $this->getRequest();
if (!$request) {
return;
}
$cjevent = $request->cookies->get('cjevent') ?: $request->getSession()->get('cjevent');
if ($cjevent) {
$purchase->cjevent = $cjevent;
}
$AP_tracker_TID = $request->cookies->get('AP_tracker_TID') ?: $request->getSession()->get('AP_tracker_TID');
if ($AP_tracker_TID) {
$purchase->AP_tracker_TID = $AP_tracker_TID;
}
}
/**
* @required
*/
public function setCurrencyContext(CurrencyContext $currencyContext): void
{
$this->currencyContext = $currencyContext;
}
/**
* @required
*/
public function setDeliveryInfo(DeliveryInfo $deliveryInfo): void
{
$this->deliveryInfo = $deliveryInfo;
}
/**
* @required
*/
public function setOrderInfo(OrderInfo $orderInfo): void
{
$this->orderInfo = $orderInfo;
}
}

View File

@@ -0,0 +1,104 @@
<?php
namespace KupShop\GTMBundle\Ecommerce;
use KupShop\GTMBundle\PageType\CommonPageType;
use KupShop\KupShopBundle\Context\CurrencyContext;
use KupShop\KupShopBundle\Context\LanguageContext;
use Symfony\Contracts\Service\Attribute\Required;
class Reservation extends AbstractEcommerce
{
#[Required]
public CommonPageType $commonPageType;
protected $currencyContext;
/**
* @var LanguageContext
*/
protected $languageContext;
/**
* Specific PageData.
*
* @throws \Exception
*/
public function getData(&$dataContainer)
{
$dbcfg = \Settings::getDefault();
$reservation = $this->pageData['body'];
$dataContainer->event = 'orderSuccess';
$dataContainer->user = $this->commonPageType->getUserData();
if (!empty($reservation['userData'])) {
$dataContainer->user->name = $reservation['userData']['name'] ?? '';
$dataContainer->user->surname = $reservation['userData']['surname'] ?? '';
$dataContainer->user->email = $reservation['userData']['email'] ?? '';
$dataContainer->user->phone = $reservation['userData']['phone'] ?? '';
$dataContainer->user->shaEmail = hash('sha256', $dataContainer->user->email.($dbcfg->analytics['google_tag_manager']['sha_salt'] ?? false ?: ''));
}
$purchase = new \stdClass();
$purchase->id = 'RES'.$reservation['reservation']->id;
$purchase->orderId = $reservation['reservation']->order?->id;
$purchase->orderCode = $reservation['reservation']->order?->order_no;
$purchase->affiliation = 'reservation';
$allDeliveryTypes = \DeliveryType::getAll(true);
$deliveryType = $allDeliveryTypes[$dbcfg->reservations['delivery_type']];
$purchase->deliveryType = $deliveryType ? $deliveryType->getDelivery()->getName() : '';
$purchase->paymentType = $deliveryType ? $deliveryType->getPayment()->getName() : '';
$purchase->currency = $this->currencyContext->getActiveId();
$purchase->shipping = toDecimal(0);
$purchase->shippingWithVat = \DecimalConstants::zero();
$purchase->shippingWithOutVat = \DecimalConstants::zero();
$price = $this->pageData['body']['product']->getProductPrice();
$purchase->total = $this->priceComputer->getPrice($price);
$purchase->totalWithVat = $this->priceComputer->getPrice($price->getPriceWithVat());
$purchase->totalWithoutVat = $this->priceComputer->getPrice($price->getPriceWithoutVat());
$purchase->totalWithoutVatAndShipping = $purchase->totalWithoutVat;
$purchase->vat = $price->getVatValue();
$purchase->flags = [];
$purchase->coupons = '';
$purchase->heurekaDisagree = '';
$purchase->discounts = [];
$product = $this->productLoader->getData($this->pageData['body']['product']);
$product->quantity = 1;
$purchase->products = [
$product,
];
$dataContainer->purchase = $purchase;
$dataContainer->_clear = true;
}
/**
* @required
*/
public function setLanguageContext(LanguageContext $languageContext): void
{
$this->languageContext = $languageContext;
}
/**
* @required
*/
public function setCurrencyContext(CurrencyContext $currencyContext): void
{
$this->currencyContext = $currencyContext;
}
}

View File

@@ -0,0 +1,90 @@
<?php
namespace KupShop\GTMBundle\Ecommerce;
use Doctrine\Common\Collections\ArrayCollection;
class SearchResult extends AbstractEcommerce
{
public function getData(&$dataContainer)
{
$search = new \stdClass();
$search->searchTerm = $this->view->getTitle();
$search->results = $this->buildSearchData();
$dataContainer->search = $search;
$dataContainer->event = 'searchResults';
}
public function buildSearchData(): array
{
$results = [];
$termForEmptyResult = null;
$items = $this->view->getTemplateData()['body']['results'] ?? [];
foreach ($items as $title => $item) {
if ($title === 'sections') {
$title = 'categories';
}
$list = $item['list'] ?? null;
if ($list instanceof ArrayCollection) {
$list = $list->toArray();
}
$fitProperty = fn ($k, $object = null) => [$k => $object ?? null];
$newList = [];
foreach ($list as $v) {
if ($title === 'products') {
$newList[] = array_merge(
$fitProperty('id', $v['id']),
$fitProperty('name', $v['title']),
$fitProperty('price', $v['price_array']['price_without_vat']),
$fitProperty('brand', $v['producer']['name']),
);
}
if ($title === 'categories') {
$newList[] = array_merge(
$fitProperty('id', $v['id']),
$fitProperty('name', $v['name']),
$fitProperty('path', $v['original_url']),
$fitProperty('label', $v['title']),
$fitProperty('imageUrl', $v['photo_src']),
);
}
if ($title === 'articles') {
$newList[] = array_merge(
$fitProperty('id', $v['id']),
$fitProperty('image', $v['url']),
$fitProperty('label', $v['title']),
);
}
if ($title === 'producers') {
$newList[] = array_merge(
$fitProperty('id', $v['id']),
$fitProperty('name', $v['title']),
$fitProperty('label', $v['title'])
);
}
if ($title === 'pages') {
$newList[] = array_merge(
$fitProperty('id', $v['id']),
$fitProperty('name', $v['name']),
$fitProperty('path', $v['original_url']),
);
}
$list = $newList;
}
$results[$title] = $list === [] ? $termForEmptyResult : $list;
}
return $results;
}
}