Skip to content

Commit 13e620b

Browse files
committed
MC-39107: [MAGENTO CLOUD] Page refresh on add to cart from product block
1 parent 661c15c commit 13e620b

File tree

1 file changed

+26
-14
lines changed
  • app/code/Magento/CatalogWidget/view/frontend/templates/product/widget/content

1 file changed

+26
-14
lines changed

app/code/Magento/CatalogWidget/view/frontend/templates/product/widget/content/grid.phtml

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
use Magento\Framework\App\Action\Action;
78

89
/** @var \Magento\CatalogWidget\Block\Product\ProductsList $block */
10+
11+
// phpcs:disable Generic.Files.LineLength.TooLong
12+
// phpcs:disable Magento2.Templates.ThisInTemplate.FoundHelper
913
?>
10-
<?php if ($exist = ($block->getProductCollection() && $block->getProductCollection()->getSize())) : ?>
14+
<?php if ($exist = ($block->getProductCollection() && $block->getProductCollection()->getSize())): ?>
1115
<?php
1216
$type = 'widget-product-grid';
1317

@@ -23,7 +27,7 @@ use Magento\Framework\App\Action\Action;
2327
$description = false;
2428
?>
2529
<div class="block widget block-products-list <?= /* @noEscape */ $mode ?>">
26-
<?php if ($block->getTitle()) : ?>
30+
<?php if ($block->getTitle()): ?>
2731
<div class="block-title">
2832
<strong><?= $block->escapeHtml(__($block->getTitle())) ?></strong>
2933
</div>
@@ -33,7 +37,7 @@ use Magento\Framework\App\Action\Action;
3337
<div class="products-<?= /* @noEscape */ $mode ?> <?= /* @noEscape */ $mode ?>">
3438
<ol class="product-items <?= /* @noEscape */ $type ?>">
3539
<?php $iterator = 1; ?>
36-
<?php foreach ($items as $_item) : ?>
40+
<?php foreach ($items as $_item): ?>
3741
<?= /* @noEscape */ ($iterator++ == 1) ? '<li class="product-item">' : '</li><li class="product-item">' ?>
3842
<div class="product-item-info">
3943
<a href="<?= $block->escapeUrl($block->getProductUrl($_item)) ?>" class="product-item-photo">
@@ -47,49 +51,50 @@ use Magento\Framework\App\Action\Action;
4751
<?= $block->escapeHtml($_item->getName()) ?>
4852
</a>
4953
</strong>
50-
<?php if ($templateType) : ?>
54+
<?php if ($templateType): ?>
5155
<?= $block->getReviewsSummaryHtml($_item, $templateType) ?>
5256
<?php endif; ?>
5357

5458
<?= $block->getProductPriceHtml($_item, $type) ?>
5559

5660
<?= $block->getProductDetailsHtml($_item) ?>
5761

58-
<?php if ($showWishlist || $showCompare || $showCart) : ?>
62+
<?php if ($showWishlist || $showCompare || $showCart): ?>
5963
<div class="product-item-inner">
6064
<div class="product-item-actions">
61-
<?php if ($showCart) : ?>
65+
<?php if ($showCart): ?>
6266
<div class="actions-primary">
63-
<?php if ($_item->isSaleable()) : ?>
67+
<?php if ($_item->isSaleable()): ?>
6468
<?php $postParams = $block->getAddToCartPostParams($_item); ?>
6569
<form data-role="tocart-form" data-product-sku="<?= $block->escapeHtml($_item->getSku()) ?>" action="<?= $block->escapeUrl($postParams['action']) ?>" method="post">
6670
<input type="hidden" name="product" value="<?= $block->escapeHtmlAttr($postParams['data']['product']) ?>">
6771
<input type="hidden" name="<?= /* @noEscape */ Action::PARAM_NAME_URL_ENCODED ?>" value="<?= /* @noEscape */ $postParams['data'][Action::PARAM_NAME_URL_ENCODED] ?>">
6872
<?= $block->getBlockHtml('formkey') ?>
6973
<button type="submit"
7074
title="<?= $block->escapeHtml(__('Add to Cart')) ?>"
71-
class="action tocart primary">
75+
class="action tocart primary"
76+
disabled>
7277
<span><?= $block->escapeHtml(__('Add to Cart')) ?></span>
7378
</button>
7479
</form>
75-
<?php else : ?>
76-
<?php if ($_item->getIsSalable()) : ?>
80+
<?php else: ?>
81+
<?php if ($_item->getIsSalable()): ?>
7782
<div class="stock available"><span><?= $block->escapeHtml(__('In stock')) ?></span></div>
78-
<?php else : ?>
83+
<?php else: ?>
7984
<div class="stock unavailable"><span><?= $block->escapeHtml(__('Out of stock')) ?></span></div>
8085
<?php endif; ?>
8186
<?php endif; ?>
8287
</div>
8388
<?php endif; ?>
84-
<?php if ($showWishlist || $showCompare) : ?>
89+
<?php if ($showWishlist || $showCompare): ?>
8590
<div class="actions-secondary" data-role="add-to-links">
86-
<?php if ($this->helper(\Magento\Wishlist\Helper\Data::class)->isAllow() && $showWishlist) : ?>
91+
<?php if ($this->helper(\Magento\Wishlist\Helper\Data::class)->isAllow() && $showWishlist): ?>
8792
<a href="#"
8893
data-post='<?= /* @noEscape */ $block->getAddToWishlistParams($_item) ?>' class="action towishlist" data-action="add-to-wishlist" title="<?= $block->escapeHtmlAttr(__('Add to Wish List')) ?>">
8994
<span><?= $block->escapeHtml(__('Add to Wish List')) ?></span>
9095
</a>
9196
<?php endif; ?>
92-
<?php if ($block->getAddToCompareUrl() && $showCompare) : ?>
97+
<?php if ($block->getAddToCompareUrl() && $showCompare): ?>
9398
<?php $compareHelper = $this->helper(\Magento\Catalog\Helper\Product\Compare::class);?>
9499
<a href="#" class="action tocompare" data-post='<?= /* @noEscape */ $compareHelper->getPostDataParams($_item) ?>' title="<?= $block->escapeHtmlAttr(__('Add to Compare')) ?>">
95100
<span><?= $block->escapeHtml(__('Add to Compare')) ?></span>
@@ -109,4 +114,11 @@ use Magento\Framework\App\Action\Action;
109114
<?= $block->getPagerHtml() ?>
110115
</div>
111116
</div>
117+
<script type="text/x-magento-init">
118+
{
119+
".block.widget [data-role=tocart-form]": {
120+
"Magento_Catalog/js/validate-product": {}
121+
}
122+
}
123+
</script>
112124
<?php endif;?>

0 commit comments

Comments
 (0)