<?php
namespace AmMacTradeCustomPlugins\Subscriber;
use Shopware\Core\Checkout\Cart\Event\AfterLineItemAddedEvent;
use Shopware\Core\Checkout\Cart\Event\BeforeLineItemAddedEvent;
use Shopware\Core\Checkout\Cart\Event\BeforeLineItemRemovedEvent;
use Shopware\Core\Checkout\Cart\Event\CheckoutOrderPlacedEvent;
use Shopware\Core\Checkout\Cart\LineItemFactoryRegistry;
use Shopware\Core\Checkout\Cart\Price\QuantityPriceCalculator;
use Shopware\Core\Checkout\Cart\Price\Struct\QuantityPriceDefinition;
use Shopware\Core\Checkout\Cart\SalesChannel\CartService;
use Shopware\Core\Checkout\Customer\Event\CustomerLoginEvent;
use Shopware\Core\Checkout\Promotion\Cart\PromotionProcessor;
use Shopware\Core\Content\Product\ProductEntity;
use Shopware\Core\Framework\Adapter\Translation\AbstractTranslator;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsAnyFilter;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\Struct\ArrayEntity;
use Shopware\Storefront\Page\Checkout\Finish\CheckoutFinishPageLoadedEvent;
use Shopware\Storefront\Page\Checkout\Offcanvas\OffcanvasCartPageLoadedEvent;
use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Shopware\Core\Checkout\Cart\LineItem\LineItem;
use Shopware\Core\System\SystemConfig\SystemConfigService;
class MacTradeSubscriber implements EventSubscriberInterface
{
// public const notableWeb = ["idealo.de/", "billiger.de/" , "geizhals.de/","testsieger.de/"];
public const SESSION_KEY_PROMOTION_CODES = 'cart-promotion-codes';
public const SEARCH_RESTRICTIONS_WORDS = ["idealo", "billiger", "protection", "protect","geizhals","testsieger"];
public const REFER_TAG = ["testsieger" => "testsieger.de/"];
public const SESSION_EXPIRE_TIME = 1800; //This is in seconds 120 = 2 minutes
protected EntityRepository $productRepository;
protected EntityRepository $macTradeInsuranceRepository;
protected EntityRepository $macTradeSppRepository;
protected EntityRepository $promotionRepository;
protected AbstractTranslator $abstractTranslator;
protected RequestStack $requestStack;
protected LineItemFactoryRegistry $factory;
protected CartService $cartService;
protected SystemConfigService $systemConfigService;
protected QuantityPriceCalculator $qPCalculator;
public function __construct(
EntityRepository $productRepository,
EntityRepository $macTradeInsuranceRepository,
EntityRepository $macTradeSppRepository,
EntityRepository $promotionRepository,
AbstractTranslator $abstractTranslator,
RequestStack $requestStack,
LineItemFactoryRegistry $factory,
CartService $cartService,
SystemConfigService $systemConfigService,
QuantityPriceCalculator $qPCalculator
)
{
$this->productRepository = $productRepository;
$this->macTradeInsuranceRepository = $macTradeInsuranceRepository;
$this->macTradeSppRepository = $macTradeSppRepository;
$this->promotionRepository = $promotionRepository;
$this->abstractTranslator = $abstractTranslator;
$this->requestStack = $requestStack;
$this->factory = $factory;
$this->cartService = $cartService;
$this->systemConfigService = $systemConfigService;
$this->qPCalculator = $qPCalculator;
}
public static function getSubscribedEvents()
{
return [
ProductPageLoadedEvent::class => 'onProductPageLoaded',
OffcanvasCartPageLoadedEvent::class => 'onOffCanvasCartPageLoaded',
BeforeLineItemAddedEvent::class => 'onBeforeLineItemAdded',
AfterLineItemAddedEvent::class => 'onAfterLineItemAdded',
BeforeLineItemRemovedEvent::class => 'onBeforeLineItemRemoved',
CustomerLoginEvent::class => 'onCustomerLoginEvent',
CheckoutFinishPageLoadedEvent::class => 'onCheckoutFinishPageLoadedEvent',
CheckoutOrderPlacedEvent::class => 'onCheckoutOrderPlacedEvent',
];
}
public function onCustomerLoginEvent(CustomerLoginEvent $event): void
{
$salesChannelContext = $event->getSalesChannelContext()->getSalesChannelId();
$config = $this->getConfigValue($salesChannelContext);
$data = [];
$configInsuranceWarranty = $config['amMacTradeInsuranceWarranty'] ?? false;
if ($configInsuranceWarranty) {
if (isset($_SESSION['session_token'])) {
$cartTokenName = $_SESSION['session_token'];
$token = $event->getContextToken();
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('userId', $cartTokenName));
$dataResults = $this->macTradeInsuranceRepository->search($criteria, $event->getContext());
if ($dataResults->count() > 0) {
$dataResult = $dataResults->first();
$data = [
'id' => $dataResult->getId(),
'userId' => $token,
'productId' => $dataResult->getProductId(),
];
}
if ($data) {
$this->macTradeInsuranceRepository->upsert([$data], Context::createDefaultContext());
}
}
}
}
public function onBeforeLineItemRemoved(BeforeLineItemRemovedEvent $event): void
{
$salesChannelContext = $event->getSalesChannelContext()->getSalesChannelId();
$config = $this->getConfigValue($salesChannelContext);
$configInsuranceWarranty = $config['amMacTradeInsuranceWarranty'] ?? false;
if ($configInsuranceWarranty) {
$deleteId = $event->getLineItem()->getId();
$cartTokenName = $event->getCart()->getToken();
if (!empty($cartTokenName)) {
$dbResultData = $dbProductData = $dbInsuranceProductData = [];
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('userId', $cartTokenName));
$cartResult = $this->macTradeInsuranceRepository->search($criteria, $event->getContext());
foreach ($cartResult as $cartRow) {
$id = $cartRow->getId();
$productId = $cartRow->getProductId();
$insuranceId = $cartRow->getInsuranceId();
$dbResultData[$productId] = $cartRow;
$dbResultData[$insuranceId] = $cartRow;
$dbProductData[$productId] = !isset($dbProductData[$productId]) ? 0 : $dbProductData[$productId];
$dbProductData[$productId]++;
$dbInsuranceProductData[$insuranceId] = !isset($dbInsuranceProductData[$insuranceId]) ? 0 : $dbInsuranceProductData[$insuranceId];
$dbInsuranceProductData[$insuranceId]++;
}
if (isset($dbInsuranceProductData[$deleteId])) {
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('insuranceId', $insuranceId));
$criteria->addFilter(new EqualsFilter('userId', $cartTokenName));
$dataResults = $this->macTradeInsuranceRepository->search($criteria, Context::createDefaultContext());
if ($dataResults->count() > 0) {
$deleteData = [];
foreach ($dataResults as $dataResult) {
$deleteData[] = ['id' => $dataResult->getId()];
}
$this->macTradeInsuranceRepository->delete($deleteData, Context::createDefaultContext());
}
}
}
}
}
public function onBeforeLineItemAdded(BeforeLineItemAddedEvent $event): void
{
$salesChannelContext = $event->getSalesChannelContext()->getSalesChannelId();
$config = $this->getConfigValue($salesChannelContext);
$configInsuranceWarranty = $config['amMacTradeInsuranceWarranty'] ?? false;
$configIdealoFeed = $config['idealoFeed'] ?? false;
if ($configInsuranceWarranty === true) {
$this->onBeforeLineItemAddedInsurance($event);
}
if ($configIdealoFeed === true) {
$this->onBeforeLineItemAddedIdealo($event);
}
}
public function onAfterLineItemAdded(AfterLineItemAddedEvent $event): void
{
unset($_SESSION['added_insurance']);
}
public function onProductPageLoaded(ProductPageLoadedEvent $event): void
{
$salesChannelContext = $event->getSalesChannelContext()->getSalesChannelId();
$config = $this->getConfigValue($salesChannelContext);
$configInsuranceWarranty = $config['amMacTradeInsuranceWarranty'] ?? false;
$configSppProduct = $config['sppProduct'] ?? false;
$configIdealoFeed = $config['idealoFeed'] ?? false;
if ($configInsuranceWarranty === true) {
$this->onProductPageLoadedInsurance($event);
}
if ($configSppProduct === true) {
$this->onProductPageLoadedSpp($event);
}
if($configIdealoFeed === true) {
// $urls = $config['notableWeb'];
if (isset($config['notableWeb'])) {
$configIdealNotableWeb = $config['notableWeb'];
$urls = array_map('trim', explode(',', str_replace(['"', ' '], '', $configIdealNotableWeb)));
} else {
$urls = ["idealo.de/", "billiger.de/" , "geizhals.de/","testsieger.de/"];
}
$this->onProductPageLoadedIdealo($event, $urls);
}
}
public function onOffCanvasCartPageLoaded(OffcanvasCartPageLoadedEvent $event): void
{
$salesChannelContext = $event->getSalesChannelContext()->getSalesChannelId();
$config = $this->getConfigValue($salesChannelContext);
$configInsuranceWarranty = $config['amMacTradeInsuranceWarranty'] ?? false;
if ($configInsuranceWarranty === true) {
if (isset($_SESSION['insu_id'])) {
$page = $event->getPage();
$context = $event->getContext();
$productId = @$_SESSION['insu_id'];
$criteria = new Criteria();
$criteria->setLimit(1);
$criteria->addFilter(new EqualsFilter('id', $productId));
$insuranceProduct = $this->getProduct($criteria, $context);
if ($insuranceProduct !== null) {
$insuranceProductName = $insuranceProduct->getName();
$insuranceProductDescription = $insuranceProduct->getDescription();
$insuranceProductPrice = $insuranceProduct->getPrice()->first()->getGross();
$insuranceProductTitle = $this->abstractTranslator->trans('macTrade.cart.insuranceProductTitle');
$noInsuranceProduct = $this->abstractTranslator->trans('macTrade.cart.noInsuranceProduct');
$mainProductId = @$_SESSION['added_main_prod_id'];
$insuranceWarranty = new ArrayEntity();
$insuranceWarranty->set('product_id_insurance_add', 0);
$insuranceWarranty->set('insurance_name', $insuranceProductName);
$insuranceWarranty->set('insurance_desc', $insuranceProductDescription);
$insuranceWarranty->set('insurance_price', $insuranceProductPrice);
$insuranceWarranty->set('insurance_add', $insuranceProductTitle);
$insuranceWarranty->set('insurance_no', $noInsuranceProduct);
$insuranceWarranty->set('insurance_prod_id', $productId);
$insuranceWarranty->set('main_prod_id', $mainProductId);
$page->addExtensions(['insurance_warranty' => $insuranceWarranty]);
}
}
}
unset($_SESSION['insu_id']);
}
public function getProduct($criteria, $context)
{
return $this->productRepository->search($criteria, $context)->getEntities()->first();
}
public function getConfigValue($context)
{
return $this->systemConfigService->get('AmMacTradeCustomPlugins.config', $context);
}
public function onCheckoutFinishPageLoadedEvent(CheckoutFinishPageLoadedEvent $event): void
{
unset($_SESSION['sw-idealo-feed-product-id']);
unset($_SESSION['sw-platform-url']);
unset($_SESSION['CREATED']);
}
public function onCheckoutOrderPlacedEvent(CheckoutOrderPlacedEvent $event): void
{
unset($_SESSION['sw-idealo-feed-product-id']);
unset($_SESSION['sw-platform-url']);
unset($_SESSION['CREATED']);
}
public function onBeforeLineItemAddedInsurance(BeforeLineItemAddedEvent $event): void
{
$params = $this->requestStack->getCurrentRequest()->request->all();
$payload = $event->getLineItem()->getPayload();
if (isset($params['lineItems'])) {
$params = array_values($params['lineItems'])[0];
}
if (isset($params['id'])) {
$productId = $params['id'];
}
$randomId = time();
$cartTokenName = $event->getCart()->getToken();
$availableInsuranceId = $this->requestStack->getCurrentRequest()->request->get('product_insurance_exist');
$time = @$_SESSION['added_insurance'];
if (!empty($availableInsuranceId) && empty($time)) {
$insuranceEvent = $this->requestStack->getCurrentRequest()->request->get('product-insurance');
if ($insuranceEvent !== '0') {
$_SESSION['added_insurance'] = time();
$_SESSION['added_main_prod_id'] = $productId;
$_SESSION['added_insu_prod_id'] = $availableInsuranceId;
$lineItem = $this->factory->create([
'id' => $availableInsuranceId,
'type' => LineItem::PRODUCT_LINE_ITEM_TYPE,
'referencedId' => $availableInsuranceId,
'quantity' => 1,
'payload' => [
'product_id_insurance' => $availableInsuranceId,
'product_id_ref' => $productId,
]
], $event->getSalesChannelContext());
$data = [
'userId' => $cartTokenName,
'productId' => $productId,
'insuranceId' => $availableInsuranceId,
];
$this->macTradeInsuranceRepository->create([$data], Context::createDefaultContext());
$this->cartService->add($event->getCart(), $lineItem, $event->getSalesChannelContext());
$_SESSION['session_token'] = $cartTokenName;
} else {
$_SESSION['insu_id'] = $availableInsuranceId;
$_SESSION['added_main_prod_id'] = $productId;
}
}
$availableInsuranceId = $this->requestStack->getCurrentRequest()->request->get('product-insurance-popup');
if (!empty($availableInsuranceId)) {
$productId = $this->requestStack->getCurrentRequest()->request->get('product_main_id_from_popup');
$data = [
'userId' => $cartTokenName,
'productId' => $productId,
'insuranceId' => $availableInsuranceId,
];
$this->macTradeInsuranceRepository->create([$data], Context::createDefaultContext());
$_SESSION['session_token'] = $cartTokenName;
}
}
public function onBeforeLineItemAddedIdealo(BeforeLineItemAddedEvent $event): void
{
if (isset($config['notableWeb'])) {
$configIdealNotableWeb = $config['notableWeb'];
$urls = array_map('trim', explode(',', str_replace(['"', ' '], '', $configIdealNotableWeb)));
} else {
$urls = ["idealo.de/", "billiger.de/" , "geizhals.de/","testsieger.de/"];
}
$context = $event->getSalesChannelContext();
$session = $this->requestStack->getSession();
if ($event->getLineItem()->getType() === PromotionProcessor::LINE_ITEM_TYPE) {
$criteria = new Criteria();
$criteria->setTitle(PromotionProcessor::LINE_ITEM_TYPE);
$allPromotionCodesObj = $this->promotionRepository->search($criteria, $context->getContext());
$allPromotionCodes = $allPromotionCodesObj->getElements();
$cart = $event->getCart();
$lineTimes = $cart->getLineItems();
$promotions = $lineTimes->filterFlatByType(PromotionProcessor::LINE_ITEM_TYPE);
$notableWeb = $urls;
$platFormUrl = @$_SESSION['sw-platform-url'];
if (@$_SESSION['CREATED'] && (time() - $_SESSION['CREATED'] > self::SESSION_EXPIRE_TIME)) {
// session started more than 2 minutes ago
unset($_SESSION['sw-idealo-feed-product-id']);
unset($_SESSION['sw-platform-url']);
unset($_SESSION['CREATED']);
}
array_filter($promotions, function($promotion) use ($notableWeb, $platFormUrl, $allPromotionCodes, $event, $context, $lineTimes, $cart, $session) {
if(@$_SESSION['sw-idealo-feed-product-id'] && sizeof($_SESSION['sw-idealo-feed-product-id']) > 0) {
array_map(function($webURL) use ($platFormUrl, $promotion, $allPromotionCodes, $event, $context, $lineTimes, $cart, $session) {
$getName = explode(".", $webURL);
$webName = strtolower($getName[0]);
if($webURL == @$platFormUrl) {
$com = str_contains(strtolower($promotion->getLabel()), $webName);
if($com == true) {
array_filter($allPromotionCodes, function($allPromotionCode) use ($event, $context, $lineTimes, $cart, $platFormUrl, $session, $webName) {
if($allPromotionCode->getCode() == $event->getLineItem()->getReferencedId()) {
if (isset($config['notableWeb'])) {
$configIdealNotableWeb = $config['notableWeb'];
$urls = array_map('trim', explode(',', str_replace(['"', ' '], '', $configIdealNotableWeb)));
} else {
$urls = ["idealo.de/", "billiger.de/" , "geizhals.de/","testsieger.de/"];
}
$getPromotionDetail = $allPromotionCode;
$promotionId = $getPromotionDetail->getId();
$promotionName = $getPromotionDetail->getCode();
$notableWeb = $urls;
if(in_array(@$platFormUrl, $notableWeb)) {
$promotionsCode = $cart->getData()->getElements()['promotions-code']->getAutomaticPromotions();
array_map(function($promotionsCode) use ($webName, $promotionId, $promotionName, $lineTimes, $cart, $context) {
$comPar = str_contains(strtolower($promotionsCode->getName()), $webName);
if($comPar == true) {
if(in_array($promotionId, $promotionsCode->getExclusionIds())) {
foreach ($lineTimes as $key => $value) {
if($value->getReferencedId() == $promotionName) {
$lineTimes->removeElement($value);
$this->cartService->remove($cart, $promotionId, $context);
}
}
}
}
}, $promotionsCode);
}
}
});
}
}
}, $notableWeb);
}
});
}
}
public function onProductPageLoadedInsurance(ProductPageLoadedEvent $event): void
{
$_SESSION['product_id_insurance_add'] = 0;
$context = $event->getContext();
$page = $event->getPage();
$product = $page->getProduct();
$customFields = $product->getCustomFields();
if (array_key_exists('custom_insurance_product', $customFields)
&& !empty($customFields['custom_insurance_product'])
&& $customFields['custom_insurance_product'] !== '0'
) {
$criteria = new Criteria();
$criteria->setLimit(1);
$criteria->addFilter(new EqualsFilter('productNumber', $customFields['custom_insurance_product']));
$criteria->addAssociation('cover.media');
$criteria->addAssociation('media.media');
$insuranceProduct = $this->getProduct($criteria, $context);
if ($insuranceProduct !== null) {
$insuranceProductId = $insuranceProduct->getId();
$insuranceProductName = $insuranceProduct->getName();
$insuranceProductDescription = $insuranceProduct->getDescription();
$insuranceProductPrice = $insuranceProduct->getPrice()->first()->getGross();
$insurance = ['insurance' => $insuranceProduct];
$page->assign($insurance);
$insuranceProductTitle = $this->abstractTranslator->trans('macTrade.pdp.insuranceProductTitle');
$noInsuranceProduct = $this->abstractTranslator->trans('macTrade.pdp.noInsuranceProduct');
$insuranceWarranty = new ArrayEntity();
$insuranceWarranty->set('insurance_prod_id', $insuranceProductId);
$insuranceWarranty->set('insurance_title', $insuranceProductTitle);
$insuranceWarranty->set('insurance_name', $insuranceProductName);
$insuranceWarranty->set('insurance_desc', $insuranceProductDescription);
$insuranceWarranty->set('insurance_price', $insuranceProductPrice);
$insuranceWarranty->set('insurance_no', $noInsuranceProduct);
$page->addExtensions(['insurance_warranty' => $insuranceWarranty]);
}
}
}
public function getSppCriteriaData($product, $event)
{
$categoryIds = $product->getCategoryTree();
// $categoryId = end($categoryIds);
$categoryId = array_key_last($product->getSeoCategory()->getTranslated()['breadcrumb']);
$salesChannelId = $event->getSalesChannelContext()->getSalesChannelId();
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('categoryId', $categoryId));
$criteria->addFilter(new EqualsFilter('salesChannelId', $salesChannelId));
return $this->macTradeSppRepository->search($criteria, Context::createDefaultContext());
}
public function onProductPageLoadedSpp(ProductPageLoadedEvent $event): void
{
$page = $event->getPage();
$product = $page->getProduct();
$customFields = $product->getCustomFields();
$sppId = '';
$productNumber = $product->getProductNumber();
$productNumber = substr($productNumber, strpos($productNumber, '.') + 1);
if (isset($customFields['custom_insurance_product']) && !empty($customFields['custom_insurance_product'])) {
if ($productNumber === '0001' && !empty($customFields['custom_insurance_product'])) {
$dataResults = $this->getSppCriteriaData($product, $event);
// $sppId = $customFields['custom_main_variant_spp_configuration'] ?? '';
if ($dataResults->count() !== 0) {
foreach ($dataResults->getElements() as $dataElement) {
$sppId = $dataElement->getStoreRepresentProductId();
}
}
} else {
$dataResults = $this->getSppCriteriaData($product, $event);
// $categoryIds = $product->getCategoryTree();
// $categoryId = end($categoryIds);
//
//// $categoryId = $product->getSeoCategory()->getId();
//
//// $categoryIds = $product->getSeoCategory()->getPlainBreadcrumb();
//// $categoryId = array_key_last($categoryIds);
//
// $salesChannelId = $event->getSalesChannelContext()->getSalesChannelId();
//
// $criteria = new Criteria();
// $criteria->addFilter(new EqualsFilter('categoryId', $categoryId));
// $criteria->addFilter(new EqualsFilter('salesChannelId', $salesChannelId));
// $dataResults = $this->macTradeSppRepository->search($criteria, Context::createDefaultContext());
if ($dataResults->count() !== 0) {
foreach ($dataResults->getElements() as $dataElement) {
$sppId = $dataElement->getNonRepresentProductId();
}
}
}
$customFieldsData = [
'customSppId' => $sppId
];
$this->productRepository->update([
[
'id' => $product->getId(),
'customFields' => $customFieldsData,
]
], Context::createDefaultContext());
$sppProduct = new ArrayEntity();
$sppProduct->set('spp', $sppId);
$page->addExtensions(['spp_product' => $sppProduct]);
}
}
public function onProductPageLoadedIdealo(ProductPageLoadedEvent $event, $urls): void
{
$server = $_SERVER;
$server_referer = @$server["HTTP_REFERER"];
// $server_referer = "https://www.idealo.de/preisvergleich/OffersOfProduct/201673212_-macbook-pro-14-2021-m1-pro-8-core-mkgp3d-a-z07975213-apple.html";
$tag = isset($_GET['tag']) ? $_GET['tag'] : '';
if(@$server_referer != null){
foreach ($urls as $url) {
$com = str_contains($server_referer, $url);
if($com != false){
$StatuCheck = $url;
}
}
}
if(!isset($StatuCheck) && isset($tag)) {
if($tag == 'testsieger') {
$StatuCheck = self::REFER_TAG[$tag];
}
}
$product = $event->getPage()->getProduct();
$getTaxRules = $product->calculatedPrice->getTaxRules();
$getQuantity = $product->calculatedPrice->getQuantity();
$getListPrice = $product->calculatedPrice->getListPrice();
$getProductId = $product->getId();
if($getListPrice){
$productPrice = ((@$getListPrice->getPrice() + @$getListPrice->getDiscount()));
} else {
$getUnitPriceWithoutListPrice = $product->calculatedPrice->getUnitPrice();
$productPrice = $getUnitPriceWithoutListPrice;
}
if (!isset($_SESSION['CREATED'])) {
$_SESSION['CREATED'] = time();
} else if (time() - $_SESSION['CREATED'] > self::SESSION_EXPIRE_TIME) {
// session started more than 2 minutes ago
unset($_SESSION['sw-idealo-feed-product-id']);
unset($_SESSION['sw-platform-url']);
unset($_SESSION['CREATED']);
sleep(1);
}
$sessionFeedProductId = @$_SESSION['sw-idealo-feed-product-id'];
$customPrice = @$product->translated['customFields']['product_custom_fields_idealo'] ? @$product->translated['customFields']['product_custom_fields_idealo'] : @$productPrice ;
if ((@$StatuCheck || (@$sessionFeedProductId && in_array($getProductId, $sessionFeedProductId))) && @$customPrice) {
if (@$sessionFeedProductId && sizeof($sessionFeedProductId) > 0) {
!in_array($getProductId, $sessionFeedProductId) ? array_push($sessionFeedProductId, $getProductId) : '';
$_SESSION['sw-idealo-feed-product-id'] = $sessionFeedProductId;
} else {
$_SESSION['sw-idealo-feed-product-id'] = array($getProductId);
}
$_SESSION['sw-platform-url'] = @$StatuCheck;
$newPrice = @$customPrice;
// build new price definition
$definition = new QuantityPriceDefinition(
$newPrice,
$getTaxRules,
$getQuantity
);
if ($getListPrice !== null) {
$definition->setListPrice($getListPrice->getPrice());
}
// build CalculatedPrice over calculator class for overwritten price
$QPCalculated = $this->qPCalculator->calculate($definition, $event->getSalesChannelContext());
// set new price into line item
$product->setCalculatedPrice($QPCalculated);
} else {
$newPrice = $productPrice;
// build new price definition
$definition = new QuantityPriceDefinition(
$newPrice,
$getTaxRules,
$getQuantity
);
if ($getListPrice !== null) {
$definition->setListPrice($getListPrice->getPrice());
}
// build CalculatedPrice over calculator class for overwritten price
$QPCalculated = $this->qPCalculator->calculate($definition, $event->getSalesChannelContext());
// set new price into line item
$product->setCalculatedPrice($QPCalculated);
}
if(@$StatuCheck && (@$sessionFeedProductId && !in_array($getProductId, $sessionFeedProductId))){
if(@$sessionFeedProductId && sizeof($sessionFeedProductId) > 0){
!in_array($getProductId, $sessionFeedProductId) ? array_push($sessionFeedProductId, $getProductId) : '';
$_SESSION['sw-idealo-feed-product-id'] = $sessionFeedProductId;
} else {
$_SESSION['sw-idealo-feed-product-id'] = array($getProductId);
}
}
}
}