Skip to content

Commit

Permalink
Merge branch '2.4-develop' of https://github.com/adobe-commerce-tier-…
Browse files Browse the repository at this point in the history
…4/magento2ce into PR-03-12-2024-anna
  • Loading branch information
abukatar committed Mar 28, 2024
2 parents 9c381b5 + 488c103 commit 32f8948
Show file tree
Hide file tree
Showing 26 changed files with 547 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
<createData entity="NewSubCategoryWithParent" stepKey="createSubCategory">
<requiredEntity createDataKey="createParentCategory"/>
</createData>
<actionGroup ref="CliIndexerReindexActionGroup" stepKey="reindexToReflectNewCategory">
<argument name="indices" value=""/>
</actionGroup>
<actionGroup ref="CliCacheCleanActionGroup" stepKey="flushCacheToReflectNewCategory">
<argument name="tags" value="config full_page"/>
</actionGroup>
</before>
<after>
<!-- Reset the window size to its original state -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
<argument name="country" value="Afghanistan"/>
<argument name="placeNumber" value="2"/>
</actionGroup>

<after>
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>

Expand Down
23 changes: 15 additions & 8 deletions app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Magento\Customer\Model\EmailNotificationInterface;
use Magento\Customer\Model\Metadata\Form;
use Magento\Customer\Model\Metadata\FormFactory;
use Magento\Customer\Model\SetCustomerStore;
use Magento\Framework\Api\DataObjectHelper;
use Magento\Framework\Api\ExtensibleDataObjectConverter;
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
Expand Down Expand Up @@ -75,6 +76,11 @@ class Save extends \Magento\Customer\Controller\Adminhtml\Index implements HttpP
*/
private $storeManager;

/**
* @var SetCustomerStore|null
*/
private $customerStore;

/**
* Constructor
*
Expand Down Expand Up @@ -106,7 +112,9 @@ class Save extends \Magento\Customer\Controller\Adminhtml\Index implements HttpP
* @param SubscriptionManagerInterface $subscriptionManager
* @param AddressRegistry|null $addressRegistry
* @param StoreManagerInterface|null $storeManager
* @param SetCustomerStore|null $customerStore
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function __construct(
Context $context,
Expand Down Expand Up @@ -136,7 +144,8 @@ public function __construct(
JsonFactory $resultJsonFactory,
SubscriptionManagerInterface $subscriptionManager,
AddressRegistry $addressRegistry = null,
?StoreManagerInterface $storeManager = null
?StoreManagerInterface $storeManager = null,
?SetCustomerStore $customerStore = null
) {
parent::__construct(
$context,
Expand Down Expand Up @@ -168,6 +177,7 @@ public function __construct(
$this->subscriptionManager = $subscriptionManager;
$this->addressRegistry = $addressRegistry ?: ObjectManager::getInstance()->get(AddressRegistry::class);
$this->storeManager = $storeManager ?? ObjectManager::getInstance()->get(StoreManagerInterface::class);
$this->customerStore = $customerStore ?? ObjectManager::getInstance()->get(SetCustomerStore::class);
}

/**
Expand Down Expand Up @@ -335,6 +345,10 @@ public function execute()

if ($this->getRequest()->getPostValue()) {
try {
$this->customerStore->setStore(
$this->getRequest()->getPostValue(CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER)
);

// optional fields might be set in request for future processing by observers in other modules
$customerData = $this->_extractCustomerData();

Expand Down Expand Up @@ -370,13 +384,6 @@ public function execute()
}
}

$storeId = $customer->getStoreId();
if (empty($storeId)) {
$website = $this->storeManager->getWebsite($customer->getWebsiteId());
$storeId = current($website->getStoreIds());
}
$this->storeManager->setCurrentStore($storeId);

// Save customer
if ($customerId) {
$this->_customerRepository->save($customer);
Expand Down
22 changes: 15 additions & 7 deletions app/code/Magento/Customer/Controller/Adminhtml/Index/Validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

use Magento\Customer\Api\AccountManagementInterface;
use Magento\Customer\Api\AddressRepositoryInterface;
use Magento\Customer\Api\CustomerMetadataInterface;
use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Customer\Api\Data\AddressInterfaceFactory;
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
use Magento\Customer\Model\Address\Mapper;
use Magento\Customer\Model\SetCustomerStore;
use Magento\Framework\Api\DataObjectHelper;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
Expand All @@ -33,6 +35,11 @@ class Validate extends CustomerAction implements HttpPostActionInterface, HttpGe
*/
private $storeManager;

/**
* @var SetCustomerStore|null
*/
private $customerStore;

/**
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\Registry $coreRegistry
Expand Down Expand Up @@ -60,7 +67,9 @@ class Validate extends CustomerAction implements HttpPostActionInterface, HttpGe
* @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
* @param StoreManagerInterface|null $storeManager
* @param SetCustomerStore|null $customerStore
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
Expand Down Expand Up @@ -88,7 +97,8 @@ public function __construct(
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
\Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory,
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
?StoreManagerInterface $storeManager = null
?StoreManagerInterface $storeManager = null,
?SetCustomerStore $customerStore = null
) {
parent::__construct(
$context,
Expand Down Expand Up @@ -117,8 +127,8 @@ public function __construct(
$resultForwardFactory,
$resultJsonFactory
);

$this->storeManager = $storeManager ?? ObjectManager::getInstance()->get(StoreManagerInterface::class);
$this->customerStore = $customerStore ?? ObjectManager::getInstance()->get(SetCustomerStore::class);
}

/**
Expand All @@ -145,6 +155,9 @@ protected function _validateCustomer($response)
);
$customerForm->setInvisibleIgnored(true);

$this->customerStore->setStore(
$this->getRequest()->getParam(CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER)
);
$data = $customerForm->extractData($this->getRequest(), 'customer');

if ($customer->getWebsiteId()) {
Expand All @@ -161,11 +174,6 @@ protected function _validateCustomer($response)
$entity_id = $submittedData['entity_id'];
$customer->setId($entity_id);
}
if (isset($data['website_id']) && is_numeric($data['website_id'])) {
$website = $this->storeManager->getWebsite($data['website_id']);
$storeId = current($website->getStoreIds());
$this->storeManager->setCurrentStore($storeId);
}
$errors = $this->customerAccountManagement->validate($customer)->getMessages();
} catch (\Magento\Framework\Validator\Exception $exception) {
/* @var $error Error */
Expand Down
55 changes: 55 additions & 0 deletions app/code/Magento/Customer/Model/SetCustomerStore.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/************************************************************************
*
* Copyright 2024 Adobe
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe and its suppliers, if any. The intellectual
* and technical concepts contained herein are proprietary to Adobe
* and its suppliers and are protected by all applicable intellectual
* property laws, including trade secret and copyright laws.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe.
* ************************************************************************
*/
declare(strict_types=1);

namespace Magento\Customer\Model;

use Magento\Customer\Api\Data\CustomerInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Store\Model\StoreManagerInterface;

class SetCustomerStore
{
/**
* @param StoreManagerInterface $storeManager
*/
public function __construct(private StoreManagerInterface $storeManager)
{
}

/**
* Set store ID for the current customer.
*
* @param array|null $requestData
* @return void
*/
public function setStore(array|null $requestData = null): void
{
$websiteId = $requestData[CustomerInterface::WEBSITE_ID] ?? null;
try {
$website = $this->storeManager->getWebsite($websiteId);
$storeId = $website ? current($website->getStoreIds()) : null;
} catch (LocalizedException $e) {
$storeId = null;
}
if (!$storeId) {
$storeId = $requestData[CustomerInterface::STORE_ID] ?? null;
}

$this->storeManager->setCurrentStore($storeId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Magento\Customer\Model\EmailNotificationInterface;
use Magento\Customer\Model\Metadata\Form;
use Magento\Customer\Model\Metadata\FormFactory;
use Magento\Customer\Model\SetCustomerStore;
use Magento\Framework\Api\DataObjectHelper;
use Magento\Framework\App\Request\Http;
use Magento\Framework\App\RequestInterface;
Expand All @@ -44,8 +45,6 @@
use Magento\Framework\View\Result\PageFactory;
use Magento\Newsletter\Model\SubscriberFactory;
use Magento\Newsletter\Model\SubscriptionManagerInterface;
use Magento\Store\Api\Data\WebsiteInterface;
use Magento\Store\Model\StoreManagerInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -287,13 +286,9 @@ protected function setUp(): void
$this->emailNotificationMock = $this->getMockBuilder(EmailNotificationInterface::class)
->disableOriginalConstructor()
->getMockForAbstractClass();
$website = $this->createPartialMock(\Magento\Store\Model\Website::class, ['getStoreIds']);
$website->method('getStoreIds')
->willReturn([1]);
$storeManager = $this->getMockBuilder(StoreManagerInterface::class)
->getMockForAbstractClass();
$storeManager->method('getWebsite')
->willReturn($website);

$customerStoreMock = $this->createMock(SetCustomerStore::class);
$customerStoreMock->expects($this->once())->method('setStore');

$objectManager = new ObjectManager($this);

Expand All @@ -320,7 +315,7 @@ protected function setUp(): void
'addressRepository' => $this->customerAddressRepositoryMock,
'addressMapper' => $this->customerAddressMapperMock,
'subscriptionManager' => $this->subscriptionManager,
'storeManager' => $storeManager,
'customerStore' => $customerStoreMock
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Magento\Customer\Controller\Adminhtml\Index\Validate;
use Magento\Customer\Model\Metadata\Form;
use Magento\Customer\Model\Metadata\FormFactory;
use Magento\Customer\Model\SetCustomerStore;
use Magento\Framework\Api\DataObjectHelper;
use Magento\Framework\Api\ExtensibleDataObjectConverter;
use Magento\Framework\App\RequestInterface;
Expand Down Expand Up @@ -143,6 +144,9 @@ protected function setUp(): void
);
$this->resultJsonFactory->expects($this->once())->method('create')->willReturn($this->resultJson);

$customerStoreMock = $this->createMock(SetCustomerStore::class);
$customerStoreMock->expects($this->once())->method('setStore');

$objectHelper = new ObjectManager($this);
$this->controller = $objectHelper->getObject(
Validate::class,
Expand All @@ -155,18 +159,20 @@ protected function setUp(): void
'customerAccountManagement' => $this->customerAccountManagement,
'resultJsonFactory' => $this->resultJsonFactory,
'dataObjectHelper' => $this->dataObjectHelper,
'customerStore' => $customerStoreMock
]
);
}

public function testExecute()
{
$customerEntityId = 2;
$this->request->expects($this->once())
$this->request->expects($this->exactly(2))
->method('getParam')
->with('customer')
->willReturn([
'entity_id' => $customerEntityId
'entity_id' => $customerEntityId,
'website_id' => 1
]);

$this->customer->expects($this->once())
Expand Down Expand Up @@ -268,7 +274,7 @@ public function testExecuteWithException()

public function testExecuteWithNewCustomerAndNoEntityId()
{
$this->request->expects($this->once())
$this->request->expects($this->exactly(2))
->method('getParam')
->with('customer')
->willReturn([]);
Expand Down
Loading

0 comments on commit 32f8948

Please sign in to comment.