105 lines
3.4 KiB
PHP
105 lines
3.4 KiB
PHP
<?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;
|
|
}
|
|
}
|