Skip to content

Commit cc00ad3

Browse files
PB-77: Product Carousel Appearance
- fix empty product list
1 parent 52a547b commit cc00ad3

File tree

1 file changed

+78
-76
lines changed
  • app/code/Magento/PageBuilder/view/frontend/templates/catalog/product/widget/content

1 file changed

+78
-76
lines changed

app/code/Magento/PageBuilder/view/frontend/templates/catalog/product/widget/content/carousel.phtml

Lines changed: 78 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -9,88 +9,90 @@ use Magento\Framework\App\Action\Action;
99

1010
/** @var \Magento\CatalogWidget\Block\Product\ProductsList $block */
1111
?>
12-
<?php
13-
$type = 'widget-product-carousel';
12+
<?php if ($exist = ($block->getProductCollection() && $block->getProductCollection()->getSize())) : ?>
13+
<?php
14+
$type = 'widget-product-carousel';
1415

15-
$image = 'new_products_content_widget_grid';
16-
$items = $block->getProductCollection()->getItems();
16+
$image = 'new_products_content_widget_grid';
17+
$items = $block->getProductCollection()->getItems();
1718

18-
$showWishlist = true;
19-
$showCompare = true;
20-
$showCart = true;
21-
$templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
22-
?>
23-
<ol class="product-items <?= /* @noEscape */ $type ?>">
24-
<?php $iterator = 1; ?>
25-
<?php foreach ($items as $_item) : ?>
26-
<?= /* @noEscape */ ($iterator++ == 1) ? '<li class="product-item">' : '</li><li class="product-item">' ?>
27-
<div class="product-item-info">
28-
<a href="<?= $block->escapeUrl($block->getProductUrl($_item)) ?>" class="product-item-photo">
29-
<?= $block->getImage($_item, $image)->toHtml() ?>
30-
</a>
31-
<div class="product-item-details">
32-
<strong class="product-item-name">
33-
<a title="<?= $block->escapeHtml($_item->getName()) ?>"
34-
href="<?= $block->escapeUrl($block->getProductUrl($_item)) ?>"
35-
class="product-item-link">
36-
<?= $block->escapeHtml($_item->getName()) ?>
37-
</a>
38-
</strong>
39-
<?php if ($templateType) : ?>
40-
<?= $block->getReviewsSummaryHtml($_item, $templateType) ?>
41-
<?php endif; ?>
19+
$showWishlist = true;
20+
$showCompare = true;
21+
$showCart = true;
22+
$templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
23+
?>
24+
<ol class="product-items <?= /* @noEscape */ $type ?>">
25+
<?php $iterator = 1; ?>
26+
<?php foreach ($items as $_item) : ?>
27+
<?= /* @noEscape */ ($iterator++ == 1) ? '<li class="product-item">' : '</li><li class="product-item">' ?>
28+
<div class="product-item-info">
29+
<a href="<?= $block->escapeUrl($block->getProductUrl($_item)) ?>" class="product-item-photo">
30+
<?= $block->getImage($_item, $image)->toHtml() ?>
31+
</a>
32+
<div class="product-item-details">
33+
<strong class="product-item-name">
34+
<a title="<?= $block->escapeHtml($_item->getName()) ?>"
35+
href="<?= $block->escapeUrl($block->getProductUrl($_item)) ?>"
36+
class="product-item-link">
37+
<?= $block->escapeHtml($_item->getName()) ?>
38+
</a>
39+
</strong>
40+
<?php if ($templateType) : ?>
41+
<?= $block->getReviewsSummaryHtml($_item, $templateType) ?>
42+
<?php endif; ?>
4243

43-
<?= $block->getProductPriceHtml($_item, $type) ?>
44+
<?= $block->getProductPriceHtml($_item, $type) ?>
4445

45-
<?= $block->getProductDetailsHtml($_item) ?>
46+
<?= $block->getProductDetailsHtml($_item) ?>
4647

47-
<?php if ($showWishlist || $showCompare || $showCart) : ?>
48-
<div class="product-item-inner">
49-
<div class="product-item-actions">
50-
<?php if ($showCart) : ?>
51-
<div class="actions-primary">
52-
<?php if ($_item->isSaleable()) : ?>
53-
<?php $postParams = $block->getAddToCartPostParams($_item); ?>
54-
<form data-role="tocart-form" data-product-sku="<?= $block->escapeHtml($_item->getSku()) ?>" action="<?= $block->escapeUrl($postParams['action']) ?>" method="post">
55-
<input type="hidden" name="product" value="<?= $block->escapeHtmlAttr($postParams['data']['product']) ?>">
56-
<input type="hidden" name="<?= /* @noEscape */ Action::PARAM_NAME_URL_ENCODED ?>" value="<?= /* @noEscape */ $postParams['data'][Action::PARAM_NAME_URL_ENCODED] ?>">
57-
<?= $block->getBlockHtml('formkey') ?>
58-
<button type="submit"
59-
title="<?= $block->escapeHtml(__('Add to Cart')) ?>"
60-
class="action tocart primary">
61-
<span><?= $block->escapeHtml(__('Add to Cart')) ?></span>
62-
</button>
63-
</form>
64-
<?php else : ?>
65-
<?php if ($_item->getIsSalable()) : ?>
66-
<div class="stock available"><span><?= $block->escapeHtml(__('In stock')) ?></span></div>
48+
<?php if ($showWishlist || $showCompare || $showCart) : ?>
49+
<div class="product-item-inner">
50+
<div class="product-item-actions">
51+
<?php if ($showCart) : ?>
52+
<div class="actions-primary">
53+
<?php if ($_item->isSaleable()) : ?>
54+
<?php $postParams = $block->getAddToCartPostParams($_item); ?>
55+
<form data-role="tocart-form" data-product-sku="<?= $block->escapeHtml($_item->getSku()) ?>" action="<?= $block->escapeUrl($postParams['action']) ?>" method="post">
56+
<input type="hidden" name="product" value="<?= $block->escapeHtmlAttr($postParams['data']['product']) ?>">
57+
<input type="hidden" name="<?= /* @noEscape */ Action::PARAM_NAME_URL_ENCODED ?>" value="<?= /* @noEscape */ $postParams['data'][Action::PARAM_NAME_URL_ENCODED] ?>">
58+
<?= $block->getBlockHtml('formkey') ?>
59+
<button type="submit"
60+
title="<?= $block->escapeHtml(__('Add to Cart')) ?>"
61+
class="action tocart primary">
62+
<span><?= $block->escapeHtml(__('Add to Cart')) ?></span>
63+
</button>
64+
</form>
6765
<?php else : ?>
68-
<div class="stock unavailable"><span><?= $block->escapeHtml(__('Out of stock')) ?></span></div>
66+
<?php if ($_item->getIsSalable()) : ?>
67+
<div class="stock available"><span><?= $block->escapeHtml(__('In stock')) ?></span></div>
68+
<?php else : ?>
69+
<div class="stock unavailable"><span><?= $block->escapeHtml(__('Out of stock')) ?></span></div>
70+
<?php endif; ?>
71+
<?php endif; ?>
72+
</div>
73+
<?php endif; ?>
74+
<?php if ($showWishlist || $showCompare) : ?>
75+
<div class="actions-secondary" data-role="add-to-links">
76+
<?php if ($this->helper(\Magento\Wishlist\Helper\Data::class)->isAllow() && $showWishlist) : ?>
77+
<a href="#"
78+
data-post='<?= /* @noEscape */ $block->getAddToWishlistParams($_item) ?>' class="action towishlist" data-action="add-to-wishlist" title="<?= $block->escapeHtmlAttr(__('Add to Wish List')) ?>">
79+
<span><?= $block->escapeHtml(__('Add to Wish List')) ?></span>
80+
</a>
81+
<?php endif; ?>
82+
<?php if ($block->getAddToCompareUrl() && $showCompare) : ?>
83+
<?php $compareHelper = $this->helper(\Magento\Catalog\Helper\Product\Compare::class);?>
84+
<a href="#" class="action tocompare" data-post='<?= /* @noEscape */ $compareHelper->getPostDataParams($_item) ?>' title="<?= $block->escapeHtmlAttr(__('Add to Compare')) ?>">
85+
<span><?= $block->escapeHtml(__('Add to Compare')) ?></span>
86+
</a>
6987
<?php endif; ?>
70-
<?php endif; ?>
71-
</div>
72-
<?php endif; ?>
73-
<?php if ($showWishlist || $showCompare) : ?>
74-
<div class="actions-secondary" data-role="add-to-links">
75-
<?php if ($this->helper(\Magento\Wishlist\Helper\Data::class)->isAllow() && $showWishlist) : ?>
76-
<a href="#"
77-
data-post='<?= /* @noEscape */ $block->getAddToWishlistParams($_item) ?>' class="action towishlist" data-action="add-to-wishlist" title="<?= $block->escapeHtmlAttr(__('Add to Wish List')) ?>">
78-
<span><?= $block->escapeHtml(__('Add to Wish List')) ?></span>
79-
</a>
80-
<?php endif; ?>
81-
<?php if ($block->getAddToCompareUrl() && $showCompare) : ?>
82-
<?php $compareHelper = $this->helper(\Magento\Catalog\Helper\Product\Compare::class);?>
83-
<a href="#" class="action tocompare" data-post='<?= /* @noEscape */ $compareHelper->getPostDataParams($_item) ?>' title="<?= $block->escapeHtmlAttr(__('Add to Compare')) ?>">
84-
<span><?= $block->escapeHtml(__('Add to Compare')) ?></span>
85-
</a>
86-
<?php endif; ?>
87-
</div>
88-
<?php endif; ?>
88+
</div>
89+
<?php endif; ?>
90+
</div>
8991
</div>
90-
</div>
91-
<?php endif; ?>
92+
<?php endif; ?>
93+
</div>
9294
</div>
93-
</div>
94-
<?= ($iterator == count($items) + 1) ? '</li>' : '' ?>
95-
<?php endforeach ?>
96-
</ol>
95+
<?= ($iterator == count($items) + 1) ? '</li>' : '' ?>
96+
<?php endforeach ?>
97+
</ol>
98+
<?php endif;?>

0 commit comments

Comments
 (0)