first commit
This commit is contained in:
60
bundles/KupShop/ContentBundle/View/VariationBlockView.php
Normal file
60
bundles/KupShop/ContentBundle/View/VariationBlockView.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user