Skip to content

Commit 2d46d98

Browse files
authored
Merge pull request #5373 from magento-tsg-csl3/2.4-develop-pr14
Fixed issues: - MC-31293 [On Prem] - Review Grid Filters not working - MC-31449 [Escalation] [SAQ] - Customer migration is too slow - MC-30989 Adding a configurable product to the cart from the cross-sells tab shows a 404 - MC-31632 Dynamic Block based on segment not displaying correctly for visitor - MC-31435 PHPSessionId should changed after logout - MC-31763 [Layered Navigation] Yes/No attribute type is not render in layered navigation block - MC-31396 Free Shipping Price rule not working when using Table Rates
2 parents 48423d7 + 45550f5 commit 2d46d98

File tree

29 files changed

+960
-303
lines changed

29 files changed

+960
-303
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\ViewModel\Product\Listing;
9+
10+
use Magento\Framework\View\Element\Block\ArgumentInterface;
11+
use Magento\Framework\App\ActionInterface;
12+
use Magento\Framework\Url\Helper\Data as UrlHelper;
13+
14+
/**
15+
* Check is available add to compare.
16+
*/
17+
class PreparePostData implements ArgumentInterface
18+
{
19+
/**
20+
* @var UrlHelper
21+
*/
22+
private $urlHelper;
23+
24+
/**
25+
* @param UrlHelper $urlHelper
26+
*/
27+
public function __construct(UrlHelper $urlHelper)
28+
{
29+
$this->urlHelper = $urlHelper;
30+
}
31+
32+
/**
33+
* Wrapper for the PostHelper::getPostData()
34+
*
35+
* @param string $url
36+
* @param array $data
37+
* @return array
38+
*/
39+
public function getPostData(string $url, array $data = []):array
40+
{
41+
if (!isset($data[ActionInterface::PARAM_NAME_URL_ENCODED])) {
42+
$data[ActionInterface::PARAM_NAME_URL_ENCODED] = $this->urlHelper->getEncodedUrl();
43+
}
44+
return ['action' => $url, 'data' => $data];
45+
}
46+
}

app/code/Magento/Catalog/view/frontend/layout/catalog_product_view.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@
175175
<block class="Magento\Catalog\Block\Product\ProductList\Related" name="catalog.product.related" template="Magento_Catalog::product/list/items.phtml">
176176
<arguments>
177177
<argument name="type" xsi:type="string">related</argument>
178+
<argument name="view_model" xsi:type="object">Magento\Catalog\ViewModel\Product\Listing\PreparePostData</argument>
178179
</arguments>
179180
<block class="Magento\Catalog\Block\Product\ProductList\Item\Container" name="related.product.addto" as="addto">
180181
<block class="Magento\Catalog\Block\Product\ProductList\Item\AddTo\Compare"
@@ -185,6 +186,7 @@
185186
<block class="Magento\Catalog\Block\Product\ProductList\Upsell" name="product.info.upsell" template="Magento_Catalog::product/list/items.phtml">
186187
<arguments>
187188
<argument name="type" xsi:type="string">upsell</argument>
189+
<argument name="view_model" xsi:type="object">Magento\Catalog\ViewModel\Product\Listing\PreparePostData</argument>
188190
</arguments>
189191
<block class="Magento\Catalog\Block\Product\ProductList\Item\Container" name="upsell.product.addto" as="addto">
190192
<block class="Magento\Catalog\Block\Product\ProductList\Item\AddTo\Compare"

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

Lines changed: 85 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
use Magento\Catalog\ViewModel\Product\Listing\PreparePostData;
8+
use Magento\Framework\App\ActionInterface;
9+
710
// phpcs:disable Magento2.Templates.ThisInTemplate.FoundThis
811
// phpcs:disable Generic.WhiteSpace.ScopeIndent.Incorrect
912
// phpcs:disable Generic.Files.LineLength
@@ -156,6 +159,7 @@ switch ($type = $block->getType()) {
156159
default:
157160
$exist = null;
158161
}
162+
$_item = null;
159163
?>
160164

161165
<?php if ($exist):?>
@@ -170,13 +174,15 @@ switch ($type = $block->getType()) {
170174
<div class="block <?= $block->escapeHtmlAttr($class) ?>">
171175
<?php endif; ?>
172176
<div class="block-title title">
173-
<strong id="block-<?= $block->escapeHtmlAttr($class) ?>-heading" role="heading" aria-level="2"><?= $block->escapeHtml($title) ?></strong>
177+
<strong id="block-<?= $block->escapeHtmlAttr($class) ?>-heading" role="heading"
178+
aria-level="2"><?= $block->escapeHtml($title) ?></strong>
174179
</div>
175180
<div class="block-content content" aria-labelledby="block-<?= $block->escapeHtmlAttr($class) ?>-heading">
176181
<?php if ($type == 'related' && $canItemsAddToCart):?>
177182
<div class="block-actions">
178183
<?= $block->escapeHtml(__('Check items to add to the cart or')) ?>
179-
<button type="button" class="action select" data-role="select-all"><span><?= $block->escapeHtml(__('select all')) ?></span></button>
184+
<button type="button" class="action select"
185+
data-role="select-all"><span><?= $block->escapeHtml(__('select all')) ?></span></button>
180186
</div>
181187
<?php endif; ?>
182188
<div class="products wrapper grid products-grid products-<?= $block->escapeHtmlAttr($type) ?>">
@@ -195,11 +201,15 @@ switch ($type = $block->getType()) {
195201
<?php endif; ?>
196202
<div class="product-item-info <?= /* @noEscape */ $available ?>">
197203
<?= /* @noEscape */ '<!-- ' . $image . '-->' ?>
198-
<a href="<?= $block->escapeUrl($block->getProductUrl($_item)) ?>" class="product photo product-item-photo">
204+
<a href="<?= $block->escapeUrl($block->getProductUrl($_item)) ?>"
205+
class="product photo product-item-photo">
199206
<?= $block->getImage($_item, $image)->toHtml() ?>
200207
</a>
201208
<div class="product details product-item-details">
202-
<strong class="product name product-item-name"><a class="product-item-link" title="<?= $block->escapeHtml($_item->getName()) ?>" href="<?= $block->escapeUrl($block->getProductUrl($_item)) ?>">
209+
<strong class="product name product-item-name"><a
210+
class="product-item-link"
211+
title="<?= $block->escapeHtmlAttr($_item->getName()) ?>"
212+
href="<?= $block->escapeUrl($block->getProductUrl($_item)) ?>">
203213
<?= $block->escapeHtml($_item->getName()) ?></a>
204214
</strong>
205215

@@ -209,52 +219,88 @@ switch ($type = $block->getType()) {
209219
<?= $block->getReviewsSummaryHtml($_item, $templateType) ?>
210220
<?php endif; ?>
211221

212-
<?php if ($canItemsAddToCart && !$_item->isComposite() && $_item->isSaleable() && $type == 'related'):?>
222+
<?php if ($canItemsAddToCart && !$_item->isComposite() && $_item->isSaleable()
223+
&& $type == 'related'):?>
213224
<?php if (!$_item->getRequiredOptions()):?>
214-
<div class="field choice related">
215-
<input type="checkbox" class="checkbox related" id="related-checkbox<?= $block->escapeHtmlAttr($_item->getId()) ?>" name="related_products[]" value="<?= $block->escapeHtmlAttr($_item->getId()) ?>" />
216-
<label class="label" for="related-checkbox<?= $block->escapeHtmlAttr($_item->getId()) ?>"><span><?= $block->escapeHtml(__('Add to Cart')) ?></span></label>
225+
<div class="field choice related"><input
226+
type="checkbox"
227+
class="checkbox related"
228+
id="related-checkbox<?= $block->escapeHtmlAttr($_item->getId()) ?>"
229+
name="related_products[]"
230+
value="<?= $block->escapeHtmlAttr($_item->getId()) ?>" />
231+
<label
232+
class="label"
233+
for="related-checkbox<?= $block->escapeHtmlAttr(
234+
$_item->getId()
235+
) ?>"><span><?= $block->escapeHtml(__('Add to Cart')) ?></span>
236+
</label>
217237
</div>
218238
<?php endif; ?>
219239
<?php endif; ?>
220240

221241
<?php if ($showAddTo || $showCart):?>
242+
<?php // phpcs:disable ?>
222243
<div class="product actions product-item-actions">
223244
<?php if ($showCart):?>
224-
<div class="actions-primary">
225-
<?php if ($_item->isSaleable()):?>
226-
<?php if ($_item->getTypeInstance()->hasRequiredOptions($_item)):?>
227-
<button class="action tocart primary" data-mage-init='{"redirectUrl": {"url": "<?= $block->escapeUrl($block->getAddToCartUrl($_item)) ?>"}}' type="button" title="<?= $block->escapeHtmlAttr(__('Add to Cart')) ?>">
228-
<span><?= $block->escapeHtml(__('Add to Cart')) ?></span>
229-
</button>
230-
<?php else:?>
231-
<?php $postDataHelper = $this->helper(Magento\Framework\Data\Helper\PostHelper::class);
232-
$postData = $postDataHelper->getPostData($block->escapeUrl($block->getAddToCartUrl($_item)), ['product' => $_item->getEntityId()])
233-
?>
234-
<button class="action tocart primary"
235-
data-post='<?= /* @noEscape */ $postData ?>'
236-
type="button" title="<?= $block->escapeHtmlAttr(__('Add to Cart')) ?>">
245+
<?php if ($_item->isSaleable()):?>
246+
<div class="actions-primary">
247+
<?php if (!$_item->getTypeInstance()->isPossibleBuyFromList($_item)):?>
248+
<button
249+
class="action tocart primary"
250+
data-mage-init='{"redirectUrl": {"url": "<?= $block->escapeUrl($block->getAddToCartUrl($_item)) ?>"}}' type="button" title="<?= $block->escapeHtmlAttr(__('Add to Cart')) ?>">
251+
<span><?= $block->escapeHtml(__('Add to Cart')) ?></span>
252+
</button>
253+
<?php else :?>
254+
<?php
255+
/** @var $viewModel PreparePostData */
256+
$viewModel = $block->getViewModel();
257+
$postArray = $viewModel->getPostData(
258+
$block->escapeUrl($block->getAddToCartUrl($_item)),
259+
['product' => $_item->getEntityId()]
260+
);
261+
$value = $postArray['data'][ActionInterface::PARAM_NAME_URL_ENCODED];
262+
?>
263+
<form data-role="tocart-form"
264+
data-product-sku="<?= $block->escapeHtmlAttr($_item->getSku()) ?>"
265+
action="<?= $block->escapeUrl($block->getAddToCartUrl($_item)) ?>"
266+
method="post">
267+
<input type="hidden" name="product"
268+
value="<?= /* @noEscape */ (int)$_item->getEntityId() ?>">
269+
<input type="hidden"
270+
name="<?= /* @noEscape */ ActionInterface::PARAM_NAME_URL_ENCODED?>"
271+
value="<?= /* @noEscape */ $value ?>">
272+
<?= $block->getBlockHtml('formkey') ?>
273+
<button type="submit"
274+
title="<?= $block->escapeHtmlAttr(__('Add to Cart')) ?>"
275+
class="action tocart primary">
237276
<span><?= $block->escapeHtml(__('Add to Cart')) ?></span>
238277
</button>
239-
<?php endif; ?>
278+
</form>
279+
<?php endif; ?>
280+
<?php else:?>
281+
<?php if ($_item->getIsSalable()):?>
282+
<div class="stock available">
283+
<span><?= $block->escapeHtml(__('In stock')) ?></span>
284+
</div>
240285
<?php else:?>
241-
<?php if ($_item->getIsSalable()):?>
242-
<div class="stock available"><span><?= $block->escapeHtml(__('In stock')) ?></span></div>
243-
<?php else:?>
244-
<div class="stock unavailable"><span><?= $block->escapeHtml(__('Out of stock')) ?></span></div>
245-
<?php endif; ?>
286+
<div class="stock unavailable">
287+
<span><?= $block->escapeHtml(__('Out of stock')) ?></span>
288+
</div>
246289
<?php endif; ?>
290+
<?php endif; ?>
247291
</div>
248292
<?php endif; ?>
249293

250294
<?php if ($showAddTo):?>
251-
<div class="secondary-addto-links actions-secondary" data-role="add-to-links">
295+
<div class="secondary-addto-links actions-secondary"
296+
data-role="add-to-links">
252297
<?php if ($addToBlock = $block->getChildBlock('addto')):?>
253298
<?= $addToBlock->setProduct($_item)->getChildHtml() ?>
254299
<?php endif; ?>
255300
</div>
256301
<?php endif; ?>
257302
</div>
303+
<?php // phpcs:enable ?>
258304
<?php endif; ?>
259305
</div>
260306
</div>
@@ -264,4 +310,15 @@ switch ($type = $block->getType()) {
264310
</div>
265311
</div>
266312
</div>
313+
<?php if (!$block->isRedirectToCartEnabled() && $_item):?>
314+
<script type="text/x-magento-init">
315+
{
316+
"[data-role=tocart-form], .form.map.checkout": {
317+
"catalogAddToCart": {
318+
"product_sku": "<?= $block->escapeJs($_item->getSku()) ?>"
319+
}
320+
}
321+
}
322+
</script>
323+
<?php endif;?>
267324
<?php endif;?>

app/code/Magento/CatalogSearch/Model/Layer/Filter/Attribute.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ public function apply(\Magento\Framework\App\RequestInterface $request)
6767

6868
$labels = [];
6969
foreach ((array) $attributeValue as $value) {
70-
$labels[] = (array) $this->getOptionText($value);
70+
$label = $this->getOptionText($value);
71+
$labels[] = is_array($label) ? $label : [$label];
7172
}
7273
$label = implode(',', array_unique(array_merge(...$labels)));
7374
$this->getLayer()

app/code/Magento/Checkout/Test/Mftf/ActionGroup/StorefrontOpenMiniCartActionGroup.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@
88

99
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1010
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="clickViewAndEditCartFromMiniCartActionGroup">
12+
<annotations>
13+
<description>Clicks on the Storefront Mini Shopping Cart icon. Clicks on the 'View and Edit Cart' link. Validates that the URL is present and correct. PLEASE NOTE: The URL is Hardcoded.</description>
14+
</annotations>
15+
16+
<scrollTo selector="{{StorefrontMinicartSection.showCart}}" stepKey="scrollToMiniCart"/>
17+
<conditionalClick selector="{{StorefrontMinicartSection.showCart}}" dependentSelector="{{StorefrontMinicartSection.miniCartOpened}}" visible="false" stepKey="openMiniCart"/>
18+
<waitForElementVisible selector="{{StorefrontMinicartSection.viewAndEditCart}}" stepKey="waitForViewAndEditCartVisible"/>
19+
<click selector="{{StorefrontMinicartSection.viewAndEditCart}}" stepKey="viewAndEditCart"/>
20+
<waitForPageLoad stepKey="waitForPageToLoad"/>
21+
<seeInCurrentUrl url="checkout/cart" stepKey="seeInCurrentUrl"/>
22+
</actionGroup>
1123
<actionGroup name="StorefrontOpenMiniCartActionGroup">
1224
<annotations>
1325
<description>Clicks on the Mini Shopping Cart icon in the Storefront Header.</description>

app/code/Magento/Checkout/view/frontend/layout/checkout_cart_index.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@
189189
<block class="Magento\Checkout\Block\Cart\Crosssell" name="checkout.cart.crosssell" template="Magento_Catalog::product/list/items.phtml" after="-" ifconfig="checkout/cart/crosssell_enabled">
190190
<arguments>
191191
<argument name="type" xsi:type="string">crosssell</argument>
192+
<argument name="view_model" xsi:type="object">Magento\Catalog\ViewModel\Product\Listing\PreparePostData</argument>
192193
</arguments>
193194
<block class="Magento\Catalog\Block\Product\ProductList\Item\Container" name="crosssell.product.addto" as="addto">
194195
<block class="Magento\Catalog\Block\Product\ProductList\Item\AddTo\Compare"

app/code/Magento/Checkout/view/frontend/requirejs-config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ var config = {
1212
sidebar: 'Magento_Checkout/js/sidebar',
1313
checkoutLoader: 'Magento_Checkout/js/checkout-loader',
1414
checkoutData: 'Magento_Checkout/js/checkout-data',
15-
proceedToCheckout: 'Magento_Checkout/js/proceed-to-checkout'
15+
proceedToCheckout: 'Magento_Checkout/js/proceed-to-checkout',
16+
catalogAddToCart: 'Magento_Catalog/js/catalog-add-to-cart'
1617
}
1718
}
1819
};

0 commit comments

Comments
 (0)