Skip to content

Commit 982a732

Browse files
committed
Merge remote-tracking branch 'origin/2.4-develop' into application-server
2 parents 5100c9b + 7d724b7 commit 982a732

File tree

18 files changed

+578
-127
lines changed

18 files changed

+578
-127
lines changed

app/code/Magento/Catalog/Model/Category.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class Category extends \Magento\Catalog\Model\AbstractModel implements
109109
*
110110
* @var \Magento\UrlRewrite\Model\UrlRewrite
111111
* @deprecated 102.0.0
112+
* @see \Magento\UrlRewrite\Model\UrlFinderInterface
112113
*/
113114
protected $_urlRewrite;
114115

@@ -315,6 +316,7 @@ protected function getCustomAttributesCodes()
315316
* @throws \Magento\Framework\Exception\LocalizedException
316317
* @return \Magento\Catalog\Model\ResourceModel\Category
317318
* @deprecated 102.0.6 because resource models should be used directly
319+
* @see \Magento\Catalog\Model\ResourceModel\Category
318320
* phpcs:disable Generic.CodeAnalysis.UselessOverridingMethod
319321
* @since 102.0.6
320322
*/
@@ -615,6 +617,7 @@ public function getUrl()
615617
UrlRewrite::ENTITY_ID => $this->getId(),
616618
UrlRewrite::ENTITY_TYPE => CategoryUrlRewriteGenerator::ENTITY_TYPE,
617619
UrlRewrite::STORE_ID => $this->getStoreId(),
620+
UrlRewrite::REDIRECT_TYPE => 0
618621
]
619622
);
620623
if ($rewrite) {
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="ProductViewPageCustomOptionValidationErrorMessageTest">
12+
<annotations>
13+
<features value="Catalog"/>
14+
<stories value="Product view page"/>
15+
<title value="[Magento Cloud] Bug of product custom option validation in product view page"/>
16+
<description value="Check custom option validation error message is displayed in product view page"/>
17+
<severity value="AVERAGE"/>
18+
<testCaseId value="AC-9978"/>
19+
<useCaseId value="ACP2E-2404"/>
20+
<group value="Catalog"/>
21+
</annotations>
22+
<before>
23+
<actionGroup ref="AdminLoginActionGroup" stepKey="LoginAsAdmin" />
24+
<createData entity="SimpleProduct2" stepKey="createProduct"/>
25+
<!-- open product edit page -->
26+
<actionGroup ref="AdminProductPageOpenByIdActionGroup" stepKey="goToProductEditPage">
27+
<argument name="productId" value="$$createProduct.id$$"/>
28+
</actionGroup>
29+
<!-- Create a custom option(radio button) with 2 values -->
30+
<click stepKey="openCustomizableOptions" selector="{{AdminProductCustomizableOptionsSection.customizableOptions}}"/>
31+
<waitForPageLoad stepKey="waitForCustomOptionsOpen"/>
32+
<actionGroup ref="CreateCustomRadioOptionsActionGroup" stepKey="createCustomOption1">
33+
<argument name="customOptionName" value="ProductOptionRadiobutton.title"/>
34+
<argument name="productOption" value="ProductOptionField"/>
35+
<argument name="productOption2" value="ProductOptionField2"/>
36+
</actionGroup>
37+
<!-- Save the product -->
38+
<actionGroup ref="AdminProductFormSaveActionGroup" stepKey="saveProduct"/>
39+
<seeElement selector="{{AdminCategoryMessagesSection.SuccessMessage}}" stepKey="assertSuccess"/>
40+
<!-- indexer reindex -->
41+
<actionGroup ref="CliIndexerReindexActionGroup" stepKey="reindex">
42+
<argument name="indices" value=""/>
43+
</actionGroup>
44+
</before>
45+
<after>
46+
<deleteData createDataKey="createProduct" stepKey="deleteProduct"/>
47+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
48+
</after>
49+
<!-- Navigate to Product Page on StoreFront -->
50+
<actionGroup ref="StorefrontOpenProductPageActionGroup" stepKey="openStorefrontProductPage">
51+
<argument name="productUrl" value="$$createProduct.custom_attributes[url_key]$$"/>
52+
</actionGroup>
53+
<!-- Add Product to Cart from product detail page -->
54+
<click selector="{{StorefrontProductActionSection.addToCart}}" stepKey="addToCart"/>
55+
<!-- see custom option validation message -->
56+
<see userInput="This is a required field." stepKey="seeRequiredField"/>
57+
</test>
58+
</tests>

app/code/Magento/Catalog/view/frontend/web/product/view/validation.js

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -12,78 +12,78 @@ define([
1212

1313
$.widget('mage.validation', $.mage.validation, {
1414
options: {
15-
radioCheckboxClosest: 'ul, ol',
15+
radioCheckboxClosest: 'ul, ol'
16+
},
1617

17-
/**
18-
* @param {*} error
19-
* @param {HTMLElement} element
20-
*/
21-
errorPlacement: function (error, element) {
22-
var messageBox,
23-
dataValidate;
18+
/**
19+
* @param {*} error
20+
* @param {HTMLElement} element
21+
*/
22+
errorPlacement: function (error, element) {
23+
var messageBox,
24+
dataValidate;
2425

25-
if ($(element).hasClass('datetime-picker')) {
26-
element = $(element).parent();
26+
if ($(element).hasClass('datetime-picker')) {
27+
element = $(element).parent();
2728

28-
if (element.parent().find('.mage-error').length) {
29-
return;
30-
}
29+
if (element.parent().find('.mage-error').length) {
30+
return;
3131
}
32+
}
3233

33-
if (element.attr('data-errors-message-box')) {
34-
messageBox = $(element.attr('data-errors-message-box'));
35-
messageBox.html(error);
34+
if (element.attr('data-errors-message-box')) {
35+
messageBox = $(element.attr('data-errors-message-box'));
36+
messageBox.html(error);
3637

37-
return;
38-
}
38+
return;
39+
}
3940

40-
dataValidate = element.attr('data-validate');
41+
dataValidate = element.attr('data-validate');
4142

42-
if (dataValidate && dataValidate.indexOf('validate-one-checkbox-required-by-name') > 0) {
43-
error.appendTo('#links-advice-container');
44-
} else if (element.is(':radio, :checkbox')) {
45-
element.closest(this.radioCheckboxClosest).after(error);
46-
} else {
47-
element.after(error);
48-
}
49-
},
43+
if (dataValidate && dataValidate.indexOf('validate-one-checkbox-required-by-name') > 0) {
44+
error.appendTo('#links-advice-container');
45+
} else if (element.is(':radio, :checkbox')) {
46+
element.closest(this.radioCheckboxClosest).after(error);
47+
} else {
48+
element.after(error);
49+
}
50+
},
5051

51-
/**
52-
* @param {HTMLElement} element
53-
* @param {String} errorClass
54-
*/
55-
highlight: function (element, errorClass) {
56-
var dataValidate = $(element).attr('data-validate');
52+
/**
53+
* @param {HTMLElement} element
54+
* @param {String} errorClass
55+
*/
56+
highlight: function (element, errorClass) {
57+
var dataValidate = $(element).attr('data-validate');
5758

58-
if (dataValidate && dataValidate.indexOf('validate-required-datetime') > 0) {
59-
$(element).parent().find('.datetime-picker').each(function () {
60-
$(this).removeClass(errorClass);
59+
if (dataValidate && dataValidate.indexOf('validate-required-datetime') > 0) {
60+
$(element).parent().find('.datetime-picker').each(function () {
61+
$(this).removeClass(errorClass);
6162

62-
if ($(this).val().length === 0) {
63-
$(this).addClass(errorClass);
64-
}
65-
});
66-
} else if ($(element).is(':radio, :checkbox')) {
67-
$(element).closest(this.radioCheckboxClosest).addClass(errorClass);
68-
} else {
69-
$(element).addClass(errorClass);
70-
}
71-
},
63+
if ($(this).val().length === 0) {
64+
$(this).addClass(errorClass);
65+
}
66+
});
67+
} else if ($(element).is(':radio, :checkbox')) {
68+
$(element).closest(this.radioCheckboxClosest).addClass(errorClass);
69+
} else {
70+
$(element).addClass(errorClass);
71+
}
72+
},
7273

73-
/**
74-
* @param {HTMLElement} element
75-
* @param {String} errorClass
76-
*/
77-
unhighlight: function (element, errorClass) {
78-
var dataValidate = $(element).attr('data-validate');
74+
/**
75+
* @param {HTMLElement} element
76+
* @param {String} errorClass
77+
*/
78+
unhighlight: function (element, errorClass) {
79+
var dataValidate = $(element).attr('data-validate');
7980

80-
if (dataValidate && dataValidate.indexOf('validate-required-datetime') > 0) {
81-
$(element).parent().find('.datetime-picker').removeClass(errorClass);
82-
} else if ($(element).is(':radio, :checkbox')) {
83-
$(element).closest(this.radioCheckboxClosest).removeClass(errorClass);
84-
} else {
85-
$(element).removeClass(errorClass);
86-
}
81+
if (dataValidate && dataValidate.indexOf('validate-required-datetime') > 0) {
82+
$(element).parent().find('.datetime-picker').removeClass(errorClass);
83+
} else if ($(element).is(':radio, :checkbox')) {
84+
$(element).closest(this.radioCheckboxClosest).removeClass(errorClass);
85+
} else {
86+
$(element).removeClass(errorClass);
8787
}
8888
}
8989
});
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/**
3+
* Copyright 2023 Adobe
4+
* All Rights Reserved.
5+
*
6+
* NOTICE: All information contained herein is, and remains
7+
* the property of Adobe and its suppliers, if any. The intellectual
8+
* and technical concepts contained herein are proprietary to Adobe
9+
* and its suppliers and are protected by all applicable intellectual
10+
* property laws, including trade secret and copyright laws.
11+
* Dissemination of this information or reproduction of this material
12+
* is strictly forbidden unless prior written permission is obtained from
13+
* Adobe.
14+
*/
15+
declare(strict_types=1);
16+
17+
namespace Magento\Customer\Model\Cache;
18+
19+
class GroupExcludedWebsiteCache
20+
{
21+
/**
22+
* @var array
23+
*/
24+
private array $customerGroupExcludedWebsite = [];
25+
26+
/**
27+
* Adds entry to GroupExcludedWebsite cache
28+
*
29+
* @param int $customerGroupId
30+
* @param array $value
31+
*/
32+
public function addToCache(int $customerGroupId, array $value)
33+
{
34+
$this->customerGroupExcludedWebsite[$customerGroupId] = $value;
35+
}
36+
37+
/**
38+
* Gets entry from GroupExcludedWebsite cache
39+
*
40+
* @param int $customerGroupId
41+
* @return array
42+
*/
43+
public function getFromCache(int $customerGroupId): array
44+
{
45+
return $this->customerGroupExcludedWebsite[$customerGroupId] ?? [];
46+
}
47+
48+
/**
49+
* Checks presence of cached customer group in GroupExcludedWebsite cache
50+
*
51+
* @param int $customerGroupId
52+
* @return bool
53+
*/
54+
public function isCached(int $customerGroupId): bool
55+
{
56+
return isset($this->customerGroupExcludedWebsite[$customerGroupId]);
57+
}
58+
59+
/**
60+
* Cleans the cache
61+
*/
62+
public function invalidate()
63+
{
64+
$this->customerGroupExcludedWebsite = [];
65+
}
66+
}

app/code/Magento/Customer/Model/Plugin/SaveCustomerGroupExcludedWebsite.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,5 +145,4 @@ private function isValueChanged(array $currentValues, array $newValues): bool
145145
return !($currentValues === array_intersect($currentValues, $newValues)
146146
&& $newValues === array_intersect($newValues, $currentValues));
147147
}
148-
149148
}

app/code/Magento/Customer/Model/ResourceModel/GroupExcludedWebsite.php

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,40 @@
99

1010
use Magento\Framework\Exception\LocalizedException;
1111
use Magento\Framework\Model\ResourceModel\Db\VersionControl\AbstractDb;
12+
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
13+
use Magento\Customer\Model\Cache\GroupExcludedWebsiteCache;
14+
use Magento\Framework\Model\ResourceModel\Db\VersionControl\RelationComposite;
15+
use Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot;
16+
use Magento\Framework\Model\ResourceModel\Db\Context;
1217

1318
/**
1419
* Excluded customer group website resource model.
1520
*/
16-
class GroupExcludedWebsite extends AbstractDb
21+
class GroupExcludedWebsite extends AbstractDb implements ResetAfterRequestInterface
1722
{
23+
/**
24+
* @var GroupExcludedWebsiteCache $groupExcludedWebsiteCache
25+
*/
26+
private GroupExcludedWebsiteCache $groupExcludedWebsiteCache;
27+
28+
/**
29+
* @param Context $context
30+
* @param Snapshot $entitySnapshot
31+
* @param RelationComposite $entityRelationComposite
32+
* @param GroupExcludedWebsiteCache $groupExcludedWebsiteCache
33+
* @param string $connectionName
34+
*/
35+
public function __construct(
36+
Context $context,
37+
Snapshot $entitySnapshot,
38+
RelationComposite $entityRelationComposite,
39+
GroupExcludedWebsiteCache $groupExcludedWebsiteCache,
40+
$connectionName = null
41+
) {
42+
parent::__construct($context, $entitySnapshot, $entityRelationComposite, $connectionName);
43+
$this->groupExcludedWebsiteCache = $groupExcludedWebsiteCache;
44+
}
45+
1846
/**
1947
* Resource initialization
2048
*
@@ -25,15 +53,36 @@ protected function _construct()
2553
$this->_init('customer_group_excluded_website', 'entity_id');
2654
}
2755

56+
/**
57+
* @inheritDoc
58+
*/
59+
public function _resetState(): void
60+
{
61+
$this->groupExcludedWebsiteCache->invalidate();
62+
}
63+
64+
/**
65+
* Makes sure ExcludedWebsiteCache is invalidated when excluded websites are modified
66+
*/
67+
public function invalidateCache()
68+
{
69+
$this->_resetState();
70+
}
71+
2872
/**
2973
* Retrieve excluded website ids related to customer group.
3074
*
3175
* @param int $customerGroupId
3276
* @return array
3377
* @throws LocalizedException
3478
*/
79+
3580
public function loadCustomerGroupExcludedWebsites(int $customerGroupId): array
3681
{
82+
if ($this->groupExcludedWebsiteCache->isCached($customerGroupId)) {
83+
return $this->groupExcludedWebsiteCache->getFromCache($customerGroupId);
84+
}
85+
3786
$connection = $this->getConnection();
3887
$bind = ['customer_group_id' => $customerGroupId];
3988

@@ -44,7 +93,8 @@ public function loadCustomerGroupExcludedWebsites(int $customerGroupId): array
4493
'customer_group_id = :customer_group_id'
4594
);
4695

47-
return $connection->fetchCol($select, $bind);
96+
$this->groupExcludedWebsiteCache->addToCache($customerGroupId, $connection->fetchCol($select, $bind));
97+
return $this->groupExcludedWebsiteCache->getFromCache($customerGroupId);
4898
}
4999

50100
/**
@@ -76,6 +126,7 @@ public function delete($customerGroupId)
76126
{
77127
$connection = $this->getConnection();
78128
$connection->beginTransaction();
129+
$this->invalidateCache();
79130
try {
80131
$where = $connection->quoteInto('customer_group_id = ?', $customerGroupId);
81132
$connection->delete(
@@ -87,7 +138,6 @@ public function delete($customerGroupId)
87138
$connection->rollBack();
88139
throw $e;
89140
}
90-
91141
return $this;
92142
}
93143

0 commit comments

Comments
 (0)