Skip to content

New product widget #27741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: 2.4-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
use Magento\Framework\App\Action\Action;
?>
<?php
/**
Expand Down Expand Up @@ -31,7 +32,7 @@ if ($exist = ($block->getProductCollection() && $block->getProductCollection()->
}
?>

<?php if ($exist) :?>
<?php if ($exist):?>
<div class="block widget block-new-products <?= /* @noEscape */ $mode ?>">
<div class="block-title">
<strong role="heading" aria-level="2"><?= $block->escapeHtml($title) ?></strong>
Expand All @@ -40,7 +41,7 @@ if ($exist = ($block->getProductCollection() && $block->getProductCollection()->
<?= /* @noEscape */ '<!-- ' . $image . '-->' ?>
<div class="products-<?= /* @noEscape */ $mode ?> <?= /* @noEscape */ $mode ?>">
<ol class="product-items <?= /* @noEscape */ $type ?>">
<?php foreach ($items as $_item) :?>
<?php foreach ($items as $_item):?>
<li class="product-item">
<div class="product-item-info">
<a href="<?= $block->escapeUrl($block->getProductUrl($_item)) ?>"
Expand All @@ -57,53 +58,64 @@ if ($exist = ($block->getProductCollection() && $block->getProductCollection()->
</strong>
<?= $block->getProductPriceHtml($_item, $type); ?>

<?php if ($templateType) :?>
<?php if ($templateType):?>
<?= $block->getReviewsSummaryHtml($_item, $templateType) ?>
<?php endif; ?>

<?php if ($showWishlist || $showCompare || $showCart) :?>
<?php if ($showWishlist || $showCompare || $showCart):?>
<div class="product-item-actions">
<?php if ($showCart) :?>
<?php if ($showCart):?>
<div class="actions-primary">
<?php if ($_item->isSaleable()) :?>
<?php if (!$_item->getTypeInstance()->isPossibleBuyFromList($_item)) :?>
<?php if ($_item->isSaleable()):?>
<?php if (!$_item->getTypeInstance()->isPossibleBuyFromList($_item)):?>
<button class="action tocart primary"
data-mage-init='{"redirectUrl":{"url":"<?= $block->escapeUrl($block->getAddToCartUrl($_item)) ?>"}}'
type="button"
title="<?= $block->escapeHtmlAttr(__('Add to Cart')) ?>">
<span><?= $block->escapeHtml(__('Add to Cart')) ?></span>
</button>
<?php else :?>
<?php else:?>
<?php
$postDataHelper = $this->helper(Magento\Framework\Data\Helper\PostHelper::class);
$postData = $postDataHelper->getPostData(
$block->escapeUrl($block->getAddToCartUrl($_item)),
['product' => (int) $_item->getEntityId()]
)
);
$postParams = json_decode($postData, true);
?>
<button class="action tocart primary"
data-post='<?= /* @noEscape */ $postData ?>'
type="button"
title="<?= $block->escapeHtmlAttr(__('Add to Cart')) ?>">
<span><?= $block->escapeHtml(__('Add to Cart')) ?></span>
</button>
<form data-role="tocart-form"
data-product-sku="<?= $escaper->escapeHtml($_item->getSku()) ?>"
action="<?= $escaper->escapeUrl($postParams['action']) ?>"
method="post">
<input type="hidden"
name="product"
value="<?= /* @noEscape */ $postParams['data']['product'] ?>">
<input type="hidden" name="<?= /* @noEscape */ Action::PARAM_NAME_URL_ENCODED ?>"
value="<?= /* @noEscape */ $postParams['data'][Action::PARAM_NAME_URL_ENCODED] ?>">
<?= $block->getBlockHtml('formkey') ?>
<button type="submit"
title="<?= $escaper->escapeHtmlAttr(__('Add to Cart')) ?>"
class="action tocart primary">
<span><?= $escaper->escapeHtml(__('Add to Cart')) ?></span>
</button>
</form>
<?php endif; ?>
<?php else :?>
<?php if ($_item->isAvailable()) :?>
<div class="stock available">
<span><?= $block->escapeHtml(__('In stock')) ?></span>
</div>
<?php else :?>
<?php else:?>
<div class="stock unavailable">
<span><?= $block->escapeHtml(__('Out of stock')) ?></span>
</div>
<?php endif; ?>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if ($showWishlist || $showCompare) :?>
<?php if ($showWishlist || $showCompare):?>
<div class="actions-secondary" data-role="add-to-links">
<?php if ($this->helper(Magento\Wishlist\Helper\Data::class)->isAllow() && $showWishlist) :?>
<?php if ($this->helper(Magento\Wishlist\Helper\Data::class)->isAllow() && $showWishlist):?>
<a href="#"
data-post='<?= /* @noEscape */ $block->getAddToWishlistParams($_item) ?>'
class="action towishlist"
Expand All @@ -112,7 +124,7 @@ if ($exist = ($block->getProductCollection() && $block->getProductCollection()->
<span><?= $block->escapeHtml(__('Add to Wish List')) ?></span>
</a>
<?php endif; ?>
<?php if ($block->getAddToCompareUrl() && $showCompare) :?>
<?php if ($block->getAddToCompareUrl() && $showCompare):?>
<?php $compareHelper = $this->helper(Magento\Catalog\Helper\Product\Compare::class);?>
<a href="#" class="action tocompare"
data-post='<?= /* @noEscape */ $compareHelper->getPostDataParams($_item) ?>'
Expand All @@ -134,3 +146,12 @@ if ($exist = ($block->getProductCollection() && $block->getProductCollection()->
</div>
</div>
<?php endif;?>
<script type="text/x-magento-init">
{
"[data-role=tocart-form], .form.map.checkout": {
"catalogAddToCart": {
"product_sku": "<?= $escaper->escapeJs($_item->getSku()) ?>"
}
}
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
use Magento\Framework\App\Action\Action;
?>
<?php

Expand Down Expand Up @@ -33,7 +34,7 @@ if ($exist = ($block->getProductCollection() && $block->getProductCollection()->
}
?>

<?php if ($exist) :?>
<?php if ($exist):?>
<div class="block widget block-new-products <?= /* @noEscape */ $mode ?>">
<div class="block-title">
<strong role="heading" aria-level="2"><?= $block->escapeHtml($title) ?></strong>
Expand All @@ -42,7 +43,7 @@ if ($exist = ($block->getProductCollection() && $block->getProductCollection()->
<?= /* @noEscape */ '<!-- ' . $image . '-->' ?>
<div class="products-<?= /* @noEscape */ $mode ?> <?= /* @noEscape */ $mode ?>">
<ol class="product-items <?= /* @noEscape */ $type ?>">
<?php foreach ($items as $_item) :?>
<?php foreach ($items as $_item):?>
<li class="product-item">
<div class="product-item-info">
<a href="<?= $block->escapeUrl($block->getProductUrl($_item)) ?>"
Expand All @@ -59,54 +60,66 @@ if ($exist = ($block->getProductCollection() && $block->getProductCollection()->
</strong>
<?= $block->getProductPriceHtml($_item, $type) ?>

<?php if ($templateType) :?>
<?php if ($templateType):?>
<?= $block->getReviewsSummaryHtml($_item, $templateType) ?>
<?php endif; ?>

<?php if ($showWishlist || $showCompare || $showCart) :?>
<?php if ($showWishlist || $showCompare || $showCart):?>
<div class="product-item-actions">
<?php if ($showCart) :?>
<?php if ($showCart):?>
<div class="actions-primary">
<?php if ($_item->isSaleable()) :?>
<?php if ($_item->isSaleable()):?>
<?php if (!$_item->getTypeInstance()->isPossibleBuyFromList($_item)
) :?>
):?>
<button class="action tocart primary"
data-mage-init='{"redirectUrl":{"url":"<?= $block->escapeUrl($block->getAddToCartUrl($_item)) ?>"}}'
type="button"
title="<?= $block->escapeHtmlAttr(__('Add to Cart')) ?>">
<span><?= $block->escapeHtml(__('Add to Cart')) ?></span>
</button>
<?php else :?>
<?php else:?>
<?php
$postDataHelper = $this->helper(Magento\Framework\Data\Helper\PostHelper::class);
$postData = $postDataHelper->getPostData($block->getAddToCartUrl($_item), ['product' => $_item->getEntityId()])
$postData = $postDataHelper->getPostData($block->getAddToCartUrl($_item), ['product' => $_item->getEntityId()]);
$postParams = json_decode($postData, true);
?>
<button class="action tocart primary"
data-post='<?= /* @noEscape */ $postData ?>'
type="button" title="<?= $block->escapeHtmlAttr(__('Add to Cart')) ?>">
<span><?= $block->escapeHtml(__('Add to Cart')) ?></span>
</button>
<form data-role="tocart-form"
data-product-sku="<?= $escaper->escapeHtml($_item->getSku()) ?>"
action="<?= $escaper->escapeUrl($postParams['action']) ?>"
method="post">
<input type="hidden"
name="product"
value="<?= /* @noEscape */ $postParams['data']['product'] ?>">
<input type="hidden" name="<?= /* @noEscape */ Action::PARAM_NAME_URL_ENCODED ?>"
value="<?= /* @noEscape */ $postParams['data'][Action::PARAM_NAME_URL_ENCODED] ?>">
<?= $block->getBlockHtml('formkey') ?>
<button type="submit"
title="<?= $escaper->escapeHtmlAttr(__('Add to Cart')) ?>"
class="action tocart primary">
<span><?= $escaper->escapeHtml(__('Add to Cart')) ?></span>
</button>
</form>
<?php endif; ?>
<?php else :?>
<?php if ($_item->isAvailable()) :?>
<div class="stock available"><span><?= $block->escapeHtml(__('In stock')) ?></span></div>
<?php else :?>
<?php else:?>
<div class="stock unavailable"><span><?= $block->escapeHtml(__('Out of stock')) ?></span></div>
<?php endif; ?>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if ($showWishlist || $showCompare) :?>
<div class="actions-secondary" data-role="add-to-links">
<?php if ($this->helper(Magento\Wishlist\Helper\Data::class)->isAllow() && $showWishlist) :?>
<?php if ($this->helper(Magento\Wishlist\Helper\Data::class)->isAllow() && $showWishlist):?>
<a href="#"
data-post='<?= /* @noEscape */ $block->getAddToWishlistParams($_item) ?>'
class="action towishlist" data-action="add-to-wishlist"
title="<?= $block->escapeHtmlAttr(__('Add to Wish List')) ?>">
<span><?= $block->escapeHtml(__('Add to Wish List')) ?></span>
</a>
<?php endif; ?>
<?php if ($block->getAddToCompareUrl() && $showCompare) :?>
<?php if ($block->getAddToCompareUrl() && $showCompare):?>
<?php $compareHelper = $this->helper(Magento\Catalog\Helper\Product\Compare::class); ?>
<a href="#" class="action tocompare"
title="<?= $block->escapeHtmlAttr(__('Add to Compare')) ?>"
Expand All @@ -119,7 +132,7 @@ if ($exist = ($block->getProductCollection() && $block->getProductCollection()->
<?php endif; ?>
</div>
<?php endif; ?>
<?php if ($description) :?>
<?php if ($description):?>
<div class="product-item-description">
<?= /* @noEscape */ $_helper->productAttribute(
$_item,
Expand All @@ -141,3 +154,12 @@ if ($exist = ($block->getProductCollection() && $block->getProductCollection()->
</div>
</div>
<?php endif;?>
<script type="text/x-magento-init">
{
"[data-role=tocart-form], .form.map.checkout": {
"catalogAddToCart": {
"product_sku": "<?= $escaper->escapeJs($_item->getSku()) ?>"
}
}
}
</script>