88 private $priceCurrency;
139 parent::_construct();
141 ->addColumnCountLayoutDepend(
'1column', 5)
142 ->addColumnCountLayoutDepend(
'2columns-left', 4)
143 ->addColumnCountLayoutDepend(
'2columns-right', 4)
144 ->addColumnCountLayoutDepend(
'3columns', 3);
147 'cache_lifetime' => 86400,
148 'cache_tags' => [\
Magento\Catalog\Model\Product::CACHE_TAG,
159 $conditions = $this->
getData(
'conditions')
161 : $this->
getData(
'conditions_encoded');
164 'CATALOG_PRODUCTS_LIST_WIDGET',
165 $this->getPriceCurrency()->getCurrency()->getCode(),
166 $this->_storeManager->getStore()->getId(),
167 $this->_design->getDesignTheme()->getId(),
168 $this->httpContext->getValue(\
Magento\Customer\Model\Context::CONTEXT_GROUP),
172 $this->json->serialize($this->
getRequest()->getParams()),
189 public function getProductPriceHtml(
192 $renderZone = \
Magento\Framework\Pricing\Render::ZONE_ITEM_LIST,
209 $priceRender = $this->
getLayout()->getBlock(
'product.price.render.default');
211 $priceRender = $this->
getLayout()->createBlock(
212 \
Magento\Framework\Pricing\Render::class,
213 'product.price.render.default',
214 [
'data' => [
'price_render_handle' =>
'catalog_product_prices']]
218 $price = $priceRender->render(
219 \
Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE,
234 $this->setProductCollection($this->createCollection());
235 return parent::_beforeToHtml();
243 public function createCollection()
246 $collection = $this->productCollectionFactory->create();
247 $collection->setVisibility($this->catalogProductVisibility->getVisibleInCatalogIds());
255 $conditions->collectValidatedAttributes(
$collection);
256 $this->sqlBuilder->attachConditionToCollection(
$collection, $conditions);
274 $conditions = $this->
getData(
'conditions_encoded')
275 ? $this->
getData(
'conditions_encoded')
276 : $this->
getData(
'conditions');
279 $conditions = $this->conditionsHelper->decode($conditions);
282 foreach ($conditions as $key => $condition) {
283 if (!empty($condition[
'attribute'])
284 && in_array($condition[
'attribute'], [
'special_from_date',
'special_to_date'])
286 $conditions[$key][
'value'] = date(
'Y-m-d H:i:s', strtotime($condition[
'value']));
290 $this->rule->loadPost([
'conditions' => $conditions]);
291 return $this->rule->getConditions();
301 if ($this->
hasData(
'products_count')) {
302 return $this->
getData(
'products_count');
305 if (
null === $this->
getData(
'products_count')) {
306 $this->
setData(
'products_count', self::DEFAULT_PRODUCTS_COUNT);
309 return $this->
getData(
'products_count');
319 if (!$this->
hasData(
'products_per_page')) {
320 $this->
setData(
'products_per_page', self::DEFAULT_PRODUCTS_PER_PAGE);
322 return $this->
getData(
'products_per_page');
332 if (!$this->
hasData(
'show_pager')) {
333 $this->
setData(
'show_pager', self::DEFAULT_SHOW_PAGER);
335 return (
bool)$this->
getData(
'show_pager');
357 $this->pager = $this->
getLayout()->createBlock(
358 \
Magento\Catalog\Block\Product\Widget\Html\Pager::class,
359 'widget.products.list.pager' 362 $this->pager->setUseContainer(
true)
363 ->setShowAmounts(
true)
364 ->setShowPerPage(
false)
365 ->setPageVarName($this->
getData(
'page_var_name'))
368 ->setCollection($this->getProductCollection());
370 if ($this->pager instanceof \
Magento\Framework\View\Element\AbstractBlock) {
371 return $this->pager->toHtml();
385 if ($this->getProductCollection()) {
386 foreach ($this->getProductCollection() as
$product) {
388 $identities = array_merge($identities,
$product->getIdentities());
403 return $this->
getData(
'title');
412 private function getPriceCurrency()
414 if ($this->priceCurrency ===
null) {
416 ->get(PriceCurrencyInterface::class);
418 return $this->priceCurrency;
getData($key='', $index=null)
_addProductAttributesAndPrices(\Magento\Catalog\Model\ResourceModel\Product\Collection $collection)
addColumnCountLayoutDepend($pageLayout, $columnCount)