57 lines
1.7 KiB
PHP
57 lines
1.7 KiB
PHP
<?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;
|
|
}
|
|
}
|