61 lines
1.5 KiB
PHP
61 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace KupShop\ContentBundle\View;
|
|
|
|
use KupShop\ContentBundle\Entity\ProductUnified;
|
|
use KupShop\ContentBundle\Entity\Wrapper\ProductUnifiedWrapper;
|
|
use KupShop\KupShopBundle\Views\View;
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
|
|
class VariationBlockView extends View
|
|
{
|
|
protected $template = 'product/product.ajax.tpl';
|
|
|
|
protected $productId;
|
|
protected $variationId;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->proxyCacheEnabled = findModule(\Modules::PROXY_CACHE, 'product');
|
|
}
|
|
|
|
public function setProductId(int $productId): void
|
|
{
|
|
$this->productId = $productId;
|
|
}
|
|
|
|
public function setVariationId(int $variationId): void
|
|
{
|
|
$this->variationId = $variationId;
|
|
}
|
|
|
|
public function getTemplateVariables()
|
|
{
|
|
$vars = parent::getTemplateVariables();
|
|
|
|
$vars['product'] = ProductUnifiedWrapper::wrap($this->getProductUnified());
|
|
|
|
return $vars;
|
|
}
|
|
|
|
public function getProductUnified(): ProductUnified
|
|
{
|
|
$product = new \Product();
|
|
if (!$product->createFromDB($this->productId)) {
|
|
throw new NotFoundHttpException('Product not found');
|
|
}
|
|
|
|
$unified = new ProductUnified($product, $product->fetchVariations());
|
|
if ($this->variationId) {
|
|
$unified->selectVariation($this->variationId);
|
|
}
|
|
|
|
return $unified;
|
|
}
|
|
|
|
public function getShowInSearch(): bool
|
|
{
|
|
return false;
|
|
}
|
|
}
|