Skip to content

Commit 3bf511a

Browse files
authored
Merge pull request #8252 from magento-l3/APR222023_PR_sarmistha
[L3 Kings] Bugfix delivery
2 parents 39ec4fa + 6ffb363 commit 3bf511a

File tree

18 files changed

+1174
-109
lines changed

18 files changed

+1174
-109
lines changed

app/code/Magento/ConfigurableProduct/view/frontend/web/js/configurable.js

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ define([
279279
_configureElement: function (element) {
280280
this.simpleProduct = this._getSimpleProductId(element);
281281

282-
if (element.value) {
282+
if (element.value && element.config) {
283283
this.options.state[element.config.id] = element.value;
284284

285285
if (element.nextSetting) {
@@ -298,9 +298,11 @@ define([
298298
}
299299

300300
this._reloadPrice();
301-
this._displayRegularPriceBlock(this.simpleProduct);
302-
this._displayTierPriceBlock(this.simpleProduct);
303-
this._displayNormalPriceLabel();
301+
if (element.config) {
302+
this._displayRegularPriceBlock(this.simpleProduct);
303+
this._displayTierPriceBlock(this.simpleProduct);
304+
this._displayNormalPriceLabel();
305+
}
304306
this._changeProductImage();
305307
},
306308

@@ -439,8 +441,10 @@ define([
439441
filteredSalableProducts;
440442

441443
this._clearSelect(element);
442-
element.options[0] = new Option('', '');
443-
element.options[0].innerHTML = this.options.spConfig.chooseText;
444+
if (element.options) {
445+
element.options[0] = new Option('', '');
446+
element.options[0].innerHTML = this.options.spConfig.chooseText;
447+
}
444448
prevConfig = false;
445449

446450
if (element.prevSetting) {
@@ -552,8 +556,10 @@ define([
552556
_clearSelect: function (element) {
553557
var i;
554558

555-
for (i = element.options.length - 1; i >= 0; i--) {
556-
element.remove(i);
559+
if (element.options) {
560+
for (i = element.options.length - 1; i >= 0; i--) {
561+
element.remove(i);
562+
}
557563
}
558564
},
559565

@@ -585,26 +591,31 @@ define([
585591
_getPrices: function () {
586592
var prices = {},
587593
elements = _.toArray(this.options.settings),
588-
allowedProduct;
594+
allowedProduct,
595+
selected,
596+
config,
597+
priceValue;
589598

590599
_.each(elements, function (element) {
591-
var selected = element.options[element.selectedIndex],
592-
config = selected && selected.config,
600+
if (element.options) {
601+
selected = element.options[element.selectedIndex];
602+
config = selected && selected.config;
593603
priceValue = this._calculatePrice({});
594604

595-
if (config && config.allowedProducts.length === 1) {
596-
priceValue = this._calculatePrice(config);
597-
} else if (element.value) {
598-
allowedProduct = this._getAllowedProductWithMinPrice(config.allowedProducts);
599-
priceValue = this._calculatePrice({
600-
'allowedProducts': [
601-
allowedProduct
602-
]
603-
});
604-
}
605+
if (config && config.allowedProducts.length === 1) {
606+
priceValue = this._calculatePrice(config);
607+
} else if (element.value) {
608+
allowedProduct = this._getAllowedProductWithMinPrice(config.allowedProducts);
609+
priceValue = this._calculatePrice({
610+
'allowedProducts': [
611+
allowedProduct
612+
]
613+
});
614+
}
605615

606-
if (!_.isEmpty(priceValue)) {
607-
prices.prices = priceValue;
616+
if (!_.isEmpty(priceValue)) {
617+
prices.prices = priceValue;
618+
}
608619
}
609620
}, this);
610621

@@ -664,19 +675,23 @@ define([
664675
_getSimpleProductId: function (element) {
665676
// TODO: Rewrite algorithm. It should return ID of
666677
// simple product based on selected options.
667-
var allOptions = element.config.options,
668-
value = element.value,
678+
var allOptions,
679+
value,
669680
config;
670681

671-
config = _.filter(allOptions, function (option) {
672-
return option.id === value;
673-
});
674-
config = _.first(config);
682+
if (element.config) {
683+
allOptions = element.config.options;
684+
value = element.value;
675685

676-
return _.isEmpty(config) ?
677-
undefined :
678-
_.first(config.allowedProducts);
686+
config = _.filter(allOptions, function (option) {
687+
return option.id === value;
688+
});
689+
config = _.first(config);
679690

691+
return _.isEmpty(config) ?
692+
undefined :
693+
_.first(config.allowedProducts);
694+
}
680695
},
681696

682697
/**

app/code/Magento/Customer/Model/AccountManagement.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -877,11 +877,6 @@ public function getConfirmationStatus($customerId)
877877
*/
878878
public function createAccount(CustomerInterface $customer, $password = null, $redirectUrl = '')
879879
{
880-
$groupId = $customer->getGroupId();
881-
if (isset($groupId) && !$this->authorization->isAllowed(self::ADMIN_RESOURCE)) {
882-
$customer->setGroupId(null);
883-
}
884-
885880
if ($password !== null) {
886881
$this->checkPasswordStrength($password);
887882
$customerEmail = $customer->getEmail();

app/code/Magento/Customer/Model/AccountManagementApi.php

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,158 @@
66

77
namespace Magento\Customer\Model;
88

9+
use Magento\Customer\Api\AddressRepositoryInterface;
10+
use Magento\Customer\Api\CustomerMetadataInterface;
11+
use Magento\Customer\Api\CustomerRepositoryInterface;
912
use Magento\Customer\Api\Data\CustomerInterface;
13+
use Magento\Customer\Api\Data\ValidationResultsInterfaceFactory;
14+
use Magento\Customer\Helper\View as CustomerViewHelper;
15+
use Magento\Customer\Model\Config\Share as ConfigShare;
16+
use Magento\Customer\Model\Customer as CustomerModel;
17+
use Magento\Customer\Model\Metadata\Validator;
18+
use Magento\Framework\Api\ExtensibleDataObjectConverter;
19+
use Magento\Framework\App\Config\ScopeConfigInterface;
20+
use Magento\Framework\AuthorizationInterface;
21+
use Magento\Framework\DataObjectFactory as ObjectFactory;
22+
use Magento\Framework\Encryption\EncryptorInterface as Encryptor;
23+
use Magento\Framework\Event\ManagerInterface;
24+
use Magento\Framework\Exception\AuthorizationException;
25+
use Magento\Framework\Mail\Template\TransportBuilder;
26+
use Magento\Framework\Math\Random;
27+
use Magento\Framework\Reflection\DataObjectProcessor;
28+
use Magento\Framework\Registry;
29+
use Magento\Framework\Stdlib\DateTime;
30+
use Magento\Framework\Stdlib\StringUtils as StringHelper;
31+
use Magento\Store\Model\StoreManagerInterface;
32+
use Psr\Log\LoggerInterface as PsrLogger;
1033

1134
/**
1235
* Account Management service implementation for external API access.
36+
*
1337
* Handle various customer account actions.
1438
*
1539
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
40+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1641
*/
1742
class AccountManagementApi extends AccountManagement
1843
{
44+
/**
45+
* @var AuthorizationInterface
46+
*/
47+
private $authorization;
48+
49+
/**
50+
* @param CustomerFactory $customerFactory
51+
* @param ManagerInterface $eventManager
52+
* @param StoreManagerInterface $storeManager
53+
* @param Random $mathRandom
54+
* @param Validator $validator
55+
* @param ValidationResultsInterfaceFactory $validationResultsDataFactory
56+
* @param AddressRepositoryInterface $addressRepository
57+
* @param CustomerMetadataInterface $customerMetadataService
58+
* @param CustomerRegistry $customerRegistry
59+
* @param PsrLogger $logger
60+
* @param Encryptor $encryptor
61+
* @param ConfigShare $configShare
62+
* @param StringHelper $stringHelper
63+
* @param CustomerRepositoryInterface $customerRepository
64+
* @param ScopeConfigInterface $scopeConfig
65+
* @param TransportBuilder $transportBuilder
66+
* @param DataObjectProcessor $dataProcessor
67+
* @param Registry $registry
68+
* @param CustomerViewHelper $customerViewHelper
69+
* @param DateTime $dateTime
70+
* @param CustomerModel $customerModel
71+
* @param ObjectFactory $objectFactory
72+
* @param ExtensibleDataObjectConverter $extensibleDataObjectConverter
73+
* @param AuthorizationInterface $authorization
74+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
75+
*/
76+
public function __construct(
77+
CustomerFactory $customerFactory,
78+
ManagerInterface $eventManager,
79+
StoreManagerInterface $storeManager,
80+
Random $mathRandom,
81+
Validator $validator,
82+
ValidationResultsInterfaceFactory $validationResultsDataFactory,
83+
AddressRepositoryInterface $addressRepository,
84+
CustomerMetadataInterface $customerMetadataService,
85+
CustomerRegistry $customerRegistry,
86+
PsrLogger $logger,
87+
Encryptor $encryptor,
88+
ConfigShare $configShare,
89+
StringHelper $stringHelper,
90+
CustomerRepositoryInterface $customerRepository,
91+
ScopeConfigInterface $scopeConfig,
92+
TransportBuilder $transportBuilder,
93+
DataObjectProcessor $dataProcessor,
94+
Registry $registry,
95+
CustomerViewHelper $customerViewHelper,
96+
DateTime $dateTime,
97+
CustomerModel $customerModel,
98+
ObjectFactory $objectFactory,
99+
ExtensibleDataObjectConverter $extensibleDataObjectConverter,
100+
AuthorizationInterface $authorization
101+
) {
102+
$this->authorization = $authorization;
103+
parent::__construct(
104+
$customerFactory,
105+
$eventManager,
106+
$storeManager,
107+
$mathRandom,
108+
$validator,
109+
$validationResultsDataFactory,
110+
$addressRepository,
111+
$customerMetadataService,
112+
$customerRegistry,
113+
$logger,
114+
$encryptor,
115+
$configShare,
116+
$stringHelper,
117+
$customerRepository,
118+
$scopeConfig,
119+
$transportBuilder,
120+
$dataProcessor,
121+
$registry,
122+
$customerViewHelper,
123+
$dateTime,
124+
$customerModel,
125+
$objectFactory,
126+
$extensibleDataObjectConverter
127+
);
128+
}
129+
19130
/**
20131
* @inheritDoc
21132
*
22133
* Override createAccount method to unset confirmation attribute for security purposes.
23134
*/
24135
public function createAccount(CustomerInterface $customer, $password = null, $redirectUrl = '')
25136
{
137+
$this->validateCustomerRequest($customer);
26138
$customer = parent::createAccount($customer, $password, $redirectUrl);
27139
$customer->setConfirmation(null);
28140

29141
return $customer;
30142
}
143+
144+
/**
145+
* Validate anonymous request
146+
*
147+
* @param CustomerInterface $customer
148+
* @return void
149+
* @throws AuthorizationException
150+
*/
151+
private function validateCustomerRequest(CustomerInterface $customer): void
152+
{
153+
$groupId = $customer->getGroupId();
154+
if (isset($groupId) &&
155+
!$this->authorization->isAllowed(self::ADMIN_RESOURCE)
156+
) {
157+
$params = ['resources' => self::ADMIN_RESOURCE];
158+
throw new AuthorizationException(
159+
__("The consumer isn't authorized to access %resources.", $params)
160+
);
161+
}
162+
}
31163
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Customer\Plugin;
10+
11+
use Magento\Customer\Api\Data\CustomerInterface;
12+
use Magento\Framework\App\ObjectManager;
13+
use Magento\Framework\AuthorizationInterface;
14+
use Magento\Framework\Exception\AuthorizationException;
15+
use Magento\AsynchronousOperations\Model\MassSchedule;
16+
17+
/**
18+
* Plugin to validate anonymous request for asynchronous operations containing group id.
19+
*/
20+
class AsyncRequestCustomerGroupAuthorization
21+
{
22+
/**
23+
* Authorization level of a basic admin session
24+
*
25+
* @see _isAllowed()
26+
*/
27+
public const ADMIN_RESOURCE = 'Magento_Customer::manage';
28+
29+
/**
30+
* @var AuthorizationInterface
31+
*/
32+
private $authorization;
33+
34+
/**
35+
*
36+
* @param AuthorizationInterface $authorization
37+
*/
38+
public function __construct(
39+
AuthorizationInterface $authorization
40+
) {
41+
$this->authorization = $authorization;
42+
}
43+
44+
/**
45+
* Validate groupId for anonymous request
46+
*
47+
* @param MassSchedule $massSchedule
48+
* @param string $topic
49+
* @param array $entitiesArray
50+
* @param string|null $groupId
51+
* @param string|null $userId
52+
* @return null
53+
* @throws AuthorizationException
54+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
55+
*/
56+
public function beforePublishMass(
57+
MassSchedule $massSchedule,
58+
string $topic,
59+
array $entitiesArray,
60+
string $groupId = null,
61+
string $userId = null
62+
) {
63+
foreach ($entitiesArray as $entityParams) {
64+
foreach ($entityParams as $entity) {
65+
if ($entity instanceof CustomerInterface) {
66+
$groupId = $entity->getGroupId();
67+
if (isset($groupId) && !$this->authorization->isAllowed(self::ADMIN_RESOURCE)) {
68+
$params = ['resources' => self::ADMIN_RESOURCE];
69+
throw new AuthorizationException(
70+
__("The consumer isn't authorized to access %resources.", $params)
71+
);
72+
}
73+
}
74+
}
75+
}
76+
return null;
77+
}
78+
}

0 commit comments

Comments
 (0)