Skip to content

Commit 0e21b00

Browse files
author
Matias Nombarasco
committed
magento#2434 fix for quick add to cart
Updated template file to support quick add to cart from the category view without being redirected to the product page. This change also fixes the enterprise version. Bug related: magento#2434
1 parent 4cae5d0 commit 0e21b00

File tree

1 file changed

+62
-62
lines changed
  • app/code/Magento/Catalog/view/frontend/templates/product

1 file changed

+62
-62
lines changed

app/code/Magento/Catalog/view/frontend/templates/product/list.phtml

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -60,75 +60,75 @@ $_helper = $this->helper('Magento\Catalog\Helper\Output');
6060
<?php echo $productImage->toHtml(); ?>
6161
</a>
6262
<div class="product details product-item-details">
63-
<?php
64-
$_productNameStripped = $block->stripTags($_product->getName(), null, true);
65-
?>
66-
<strong class="product name product-item-name">
67-
<a class="product-item-link"
68-
href="<?php /* @escapeNotVerified */ echo $_product->getProductUrl() ?>">
69-
<?php /* @escapeNotVerified */ echo $_helper->productAttribute($_product, $_product->getName(), 'name'); ?>
70-
</a>
71-
</strong>
72-
<?php echo $block->getReviewsSummaryHtml($_product, $templateType); ?>
73-
<?php /* @escapeNotVerified */ echo $block->getProductPrice($_product) ?>
74-
<?php echo $block->getProductDetailsHtml($_product); ?>
75-
76-
<div class="product-item-inner">
77-
<div class="product actions product-item-actions"<?php echo strpos($pos, $viewMode . '-actions') ? $position : ''; ?>>
78-
<div class="actions-primary"<?php echo strpos($pos, $viewMode . '-primary') ? $position : ''; ?>>
79-
<?php if ($_product->isSaleable()): ?>
80-
<?php $postParams = $block->getAddToCartPostParams($_product); ?>
81-
<form data-role="tocart-form" action="<?php /* @escapeNotVerified */ echo $postParams['action']; ?>" method="post">
82-
<input type="hidden" name="product" value="<?php /* @escapeNotVerified */ echo $postParams['data']['product']; ?>">
83-
<input type="hidden" name="<?php /* @escapeNotVerified */ echo Action::PARAM_NAME_URL_ENCODED; ?>" value="<?php /* @escapeNotVerified */ echo $postParams['data'][Action::PARAM_NAME_URL_ENCODED]; ?>">
84-
<?php echo $block->getBlockHtml('formkey')?>
85-
<button type="submit"
86-
title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>"
87-
class="action tocart primary">
88-
<span><?php /* @escapeNotVerified */ echo __('Add to Cart') ?></span>
89-
</button>
90-
</form>
91-
<?php else: ?>
92-
<?php if ($_product->getIsSalable()): ?>
93-
<div class="stock available"><span><?php /* @escapeNotVerified */ echo __('In stock') ?></span></div>
63+
<?php $postParams = $block->getAddToCartPostParams($_product); ?>
64+
<form data-role="tocart-form" action="<?php /* @escapeNotVerified */ echo $postParams['action']; ?>" method="post">
65+
<?php
66+
$_productNameStripped = $block->stripTags($_product->getName(), null, true);
67+
?>
68+
<strong class="product name product-item-name">
69+
<a class="product-item-link"
70+
href="<?php /* @escapeNotVerified */ echo $_product->getProductUrl() ?>">
71+
<?php /* @escapeNotVerified */ echo $_helper->productAttribute($_product, $_product->getName(), 'name'); ?>
72+
</a>
73+
</strong>
74+
<?php echo $block->getReviewsSummaryHtml($_product, $templateType); ?>
75+
<?php /* @escapeNotVerified */ echo $block->getProductPrice($_product) ?>
76+
<?php echo $block->getProductDetailsHtml($_product); ?>
77+
78+
<div class="product-item-inner">
79+
<div class="product actions product-item-actions"<?php echo strpos($pos, $viewMode . '-actions') ? $position : ''; ?>>
80+
<div class="actions-primary"<?php echo strpos($pos, $viewMode . '-primary') ? $position : ''; ?>>
81+
<?php if ($_product->isSaleable()): ?>
82+
<input type="hidden" name="product" value="<?php /* @escapeNotVerified */ echo $postParams['data']['product']; ?>">
83+
<input type="hidden" name="<?php /* @escapeNotVerified */ echo Action::PARAM_NAME_URL_ENCODED; ?>" value="<?php /* @escapeNotVerified */ echo $postParams['data'][Action::PARAM_NAME_URL_ENCODED]; ?>">
84+
<?php echo $block->getBlockHtml('formkey')?>
85+
<button type="submit"
86+
title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>"
87+
class="action tocart primary">
88+
<span><?php /* @escapeNotVerified */ echo __('Add to Cart') ?></span>
89+
</button>
9490
<?php else: ?>
95-
<div class="stock unavailable"><span><?php /* @escapeNotVerified */ echo __('Out of stock') ?></span></div>
91+
<?php if ($_product->getIsSalable()): ?>
92+
<div class="stock available"><span><?php /* @escapeNotVerified */ echo __('In stock') ?></span></div>
93+
<?php else: ?>
94+
<div class="stock unavailable"><span><?php /* @escapeNotVerified */ echo __('Out of stock') ?></span></div>
95+
<?php endif; ?>
9696
<?php endif; ?>
97-
<?php endif; ?>
98-
</div>
99-
<div data-role="add-to-links" class="actions-secondary"<?php echo strpos($pos, $viewMode . '-secondary') ? $position : ''; ?>>
100-
<?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow()): ?>
97+
</div>
98+
<div data-role="add-to-links" class="actions-secondary"<?php echo strpos($pos, $viewMode . '-secondary') ? $position : ''; ?>>
99+
<?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow()): ?>
100+
<a href="#"
101+
class="action towishlist"
102+
title="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
103+
aria-label="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
104+
data-post='<?php /* @escapeNotVerified */ echo $block->getAddToWishlistParams($_product); ?>'
105+
data-action="add-to-wishlist"
106+
role="button">
107+
<span><?php /* @escapeNotVerified */ echo __('Add to Wish List') ?></span>
108+
</a>
109+
<?php endif; ?>
110+
<?php
111+
$compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare');
112+
?>
101113
<a href="#"
102-
class="action towishlist"
103-
title="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
104-
aria-label="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
105-
data-post='<?php /* @escapeNotVerified */ echo $block->getAddToWishlistParams($_product); ?>'
106-
data-action="add-to-wishlist"
114+
class="action tocompare"
115+
title="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
116+
aria-label="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
117+
data-post='<?php /* @escapeNotVerified */ echo $compareHelper->getPostDataParams($_product); ?>'
107118
role="button">
108-
<span><?php /* @escapeNotVerified */ echo __('Add to Wish List') ?></span>
119+
<span><?php /* @escapeNotVerified */ echo __('Add to Compare') ?></span>
109120
</a>
110-
<?php endif; ?>
111-
<?php
112-
$compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare');
113-
?>
114-
<a href="#"
115-
class="action tocompare"
116-
title="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
117-
aria-label="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
118-
data-post='<?php /* @escapeNotVerified */ echo $compareHelper->getPostDataParams($_product); ?>'
119-
role="button">
120-
<span><?php /* @escapeNotVerified */ echo __('Add to Compare') ?></span>
121-
</a>
121+
</div>
122122
</div>
123+
<?php if ($showDescription):?>
124+
<div class="product description product-item-description">
125+
<?php /* @escapeNotVerified */ echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?>
126+
<a href="<?php /* @escapeNotVerified */ echo $_product->getProductUrl() ?>" title="<?php /* @escapeNotVerified */ echo $_productNameStripped ?>"
127+
class="action more"><?php /* @escapeNotVerified */ echo __('Learn More') ?></a>
128+
</div>
129+
<?php endif; ?>
123130
</div>
124-
<?php if ($showDescription):?>
125-
<div class="product description product-item-description">
126-
<?php /* @escapeNotVerified */ echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?>
127-
<a href="<?php /* @escapeNotVerified */ echo $_product->getProductUrl() ?>" title="<?php /* @escapeNotVerified */ echo $_productNameStripped ?>"
128-
class="action more"><?php /* @escapeNotVerified */ echo __('Learn More') ?></a>
129-
</div>
130-
<?php endif; ?>
131-
</div>
131+
</form>
132132
</div>
133133
</div>
134134
<?php echo($iterator == count($_productCollection)+1) ? '</li>' : '' ?>

0 commit comments

Comments
 (0)