79 lines
2.2 KiB
PHP
79 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace KupShop\ParameterGroupsBundle\Twig\Components;
|
|
|
|
use KupShop\ComponentsBundle\Attributes\Component;
|
|
use KupShop\ComponentsBundle\Attributes\Version;
|
|
use KupShop\ComponentsBundle\Entity\Thumbnail;
|
|
use KupShop\ComponentsBundle\Twig\BaseComponent;
|
|
use KupShop\ComponentsBundle\Twig\DataProvider\ProductDataTrait;
|
|
use KupShop\ComponentsBundle\Twig\ProducerTooltipTrait;
|
|
use KupShop\ParameterGroupsBundle\Util\ParameterGroupsUtil;
|
|
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
|
|
|
|
#[AsTwigComponent(template: '@ParameterGroups/components/ParameterGroups/ParameterGroups.1.html.twig')]
|
|
#[Component(1, [
|
|
new Version(1),
|
|
])]
|
|
class ParameterGroups extends BaseComponent
|
|
{
|
|
use ProductDataTrait;
|
|
use ProducerTooltipTrait;
|
|
public string $style = 'default'; // stripped, bordered
|
|
|
|
public bool $show_producer = false;
|
|
public int $breakpoint = 300;
|
|
|
|
public function __construct(protected ParameterGroupsUtil $parameterGroupsUtil)
|
|
{
|
|
}
|
|
|
|
public function getIsParameterGroupEmpty(array $parameterGroup): bool
|
|
{
|
|
foreach ($parameterGroup['parameters'] as $parameterId) {
|
|
$parameter = $this->getParameter($parameterId);
|
|
if ($parameter && $parameter['figure'] == 'Y') {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @return \Product[]
|
|
*/
|
|
public function getParameters(): array
|
|
{
|
|
return $this->product->fetchParameters();
|
|
}
|
|
|
|
public function getParameter(string $parameterId)
|
|
{
|
|
return $this->product->fetchParameters()[$parameterId] ?? null;
|
|
}
|
|
|
|
public function getParameterGroups(): array
|
|
{
|
|
return $this->parameterGroupsUtil->getParameterGroups($this->id_product);
|
|
}
|
|
|
|
public function getProducer()
|
|
{
|
|
$this->product->fetchProducer();
|
|
|
|
return $this->product->producer;
|
|
}
|
|
|
|
public function getProducerThumbnail(): ?Thumbnail
|
|
{
|
|
$producer = $this->getProducer();
|
|
|
|
if ($producer['image']['id'] ?? false) {
|
|
return new Thumbnail((string) $producer['image']['id'], $producer['image']['descr'], $producer['image']['date_update']);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|