From ef3196b0a826d3190c440fd4d95d86b976b7215d Mon Sep 17 00:00:00 2001 From: glo42671 Date: Tue, 15 Oct 2024 20:29:49 +0530 Subject: [PATCH 1/6] MCLOUD-12968: Push B2B isolated patch through Magento Cloud Patch Tool --- patches.json | 3 + ...company_account_create_request_1.3.3.patch | 144 ++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 patches/B2B-4051_fields_hydration_company_account_create_request_1.3.3.patch diff --git a/patches.json b/patches.json index 7b55679..5ce0992 100644 --- a/patches.json +++ b/patches.json @@ -370,6 +370,9 @@ "magento/magento2-b2b-base": { "Layered navigation filter is present only when product is present on the listing page with enabled Shared catalog": { ">=1.1.5 <1.3.1": "MCLOUD-6923__layered_navigation_filter_is_present_only_when_product_is_present_on_the_listing_page_with_enabled_shared_catalog__2.3.5.patch" + }, + "Fields hydration on company account create request": { + ">=1.3.3 <1.3.3-p11 || >=1.3.4 <1.3.4-p10 || >=1.3.5 <1.3.5-p8 || >=1.4.2 <1.4.2-p3": "B2B-4051_fields_hydration_company_account_create_request_1.3.3.patch" } }, "magento/magento2-ee-base": { diff --git a/patches/B2B-4051_fields_hydration_company_account_create_request_1.3.3.patch b/patches/B2B-4051_fields_hydration_company_account_create_request_1.3.3.patch new file mode 100644 index 0000000..74fa42d --- /dev/null +++ b/patches/B2B-4051_fields_hydration_company_account_create_request_1.3.3.patch @@ -0,0 +1,144 @@ +new file mode 100644 +--- /dev/null ++++ b/vendor/magento/module-company/Model/Customer/AccountManagement/CompanyRequestHydrator.php +@@ -0,0 +1,66 @@ ++request = $request; ++ } ++ ++ /** ++ * Get and hydrate company data from HTTP request. ++ * ++ * @return array ++ */ ++ public function getCompanyDataFromRequest(): array ++ { ++ $result = []; ++ $companyData = $this->request->getPost('company', []); ++ foreach ($this->fieldsToSave as $item) { ++ if (isset($companyData[$item])) { ++ $result[$item] = $companyData[$item]; ++ } ++ } ++ ++ return $result; ++ } ++} +--- a/vendor/magento/module-company/Plugin/Customer/Api/AccountManagement.php ++++ b/vendor/magento/module-company/Plugin/Customer/Api/AccountManagement.php +@@ -11,17 +11,13 @@ + use Magento\Customer\Api\CustomerRepositoryInterface; + use Magento\Company\Api\CompanyManagementInterface; + use Magento\Framework\Exception\NoSuchEntityException; ++use Magento\Company\Model\Customer\AccountManagement\CompanyRequestHydrator; + + /** + * Plugin for AccountManagement. Processing company data. + */ + class AccountManagement + { +- /** +- * @var \Magento\Framework\App\Request\Http +- */ +- private $request; +- + /** + * @var \Magento\Company\Model\Email\Sender + */ +@@ -47,30 +43,35 @@ + */ + private $customerRepository; + ++ /** ++ * @var CompanyRequestHydrator ++ */ ++ private $companyRequestHydrator; ++ + /** + * AccountManagement constructor + * +- * @param \Magento\Framework\App\Request\Http $request + * @param \Magento\Company\Model\Email\Sender $companyEmailSender + * @param \Magento\Backend\Model\UrlInterface $urlBuilder + * @param \Magento\Company\Model\Customer\Company $customerCompany + * @param CompanyManagementInterface $companyManagement + * @param CustomerRepositoryInterface $customerRepository ++ * @param CompanyRequestHydrator $companyRequestHydrator + */ + public function __construct( +- \Magento\Framework\App\Request\Http $request, + \Magento\Company\Model\Email\Sender $companyEmailSender, + \Magento\Backend\Model\UrlInterface $urlBuilder, + \Magento\Company\Model\Customer\Company $customerCompany, + CompanyManagementInterface $companyManagement, +- CustomerRepositoryInterface $customerRepository ++ CustomerRepositoryInterface $customerRepository, ++ CompanyRequestHydrator $companyRequestHydrator + ) { +- $this->request = $request; + $this->companyEmailSender = $companyEmailSender; + $this->urlBuilder = $urlBuilder; + $this->customerCompany = $customerCompany; + $this->companyManagement = $companyManagement; + $this->customerRepository = $customerRepository; ++ $this->companyRequestHydrator = $companyRequestHydrator; + } + + /** +@@ -127,11 +128,7 @@ + \Magento\Customer\Api\AccountManagementInterface $subject, + \Magento\Customer\Api\Data\CustomerInterface $result + ) { +- $companyData = $this->request->getPost('company', []); +- if (isset($companyData['status'])) { +- unset($companyData['status']); +- } +- ++ $companyData = $this->companyRequestHydrator->getCompanyDataFromRequest(); + if (is_array($companyData) && !empty($companyData)) { + $jobTitle = $companyData['job_title'] ?? null; + $companyDataObject = $this->customerCompany->createCompany($result, $companyData, $jobTitle); \ No newline at end of file From 071d4e6749efc01f3e0f431101193ae7907118c8 Mon Sep 17 00:00:00 2001 From: glo42671 Date: Wed, 16 Oct 2024 09:47:42 +0530 Subject: [PATCH 2/6] MCLOUD-12968: Push B2B isolated patch through Magento Cloud Patch Tool --- ..._fields_hydration_company_account_create_request__1.3.3.patch} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename patches/{B2B-4051_fields_hydration_company_account_create_request_1.3.3.patch => B2B-4051__fields_hydration_company_account_create_request__1.3.3.patch} (100%) diff --git a/patches/B2B-4051_fields_hydration_company_account_create_request_1.3.3.patch b/patches/B2B-4051__fields_hydration_company_account_create_request__1.3.3.patch similarity index 100% rename from patches/B2B-4051_fields_hydration_company_account_create_request_1.3.3.patch rename to patches/B2B-4051__fields_hydration_company_account_create_request__1.3.3.patch From c9972731aca5092325926acbb6751344812fcae9 Mon Sep 17 00:00:00 2001 From: glo42671 Date: Wed, 16 Oct 2024 20:15:30 +0530 Subject: [PATCH 3/6] MCLOUD-12968: Push B2B isolated patch through Magento Cloud Patch Tool --- patches.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patches.json b/patches.json index 5ce0992..637d3e1 100644 --- a/patches.json +++ b/patches.json @@ -372,7 +372,7 @@ ">=1.1.5 <1.3.1": "MCLOUD-6923__layered_navigation_filter_is_present_only_when_product_is_present_on_the_listing_page_with_enabled_shared_catalog__2.3.5.patch" }, "Fields hydration on company account create request": { - ">=1.3.3 <1.3.3-p11 || >=1.3.4 <1.3.4-p10 || >=1.3.5 <1.3.5-p8 || >=1.4.2 <1.4.2-p3": "B2B-4051_fields_hydration_company_account_create_request_1.3.3.patch" + ">=1.3.3 <1.3.3-p11 || >=1.3.4 <1.3.4-p10 || >=1.3.5 <1.3.5-p8 || >=1.4.2 <1.4.2-p3": "B2B-4051__fields_hydration_company_account_create_request__1.3.3.patch" } }, "magento/magento2-ee-base": { From face366a43a35c5791adc07337127e8815c4f6b9 Mon Sep 17 00:00:00 2001 From: Sivaram Manijeganathan Date: Wed, 16 Oct 2024 13:00:34 -0500 Subject: [PATCH 4/6] update log file path --- src/Test/Functional/Acceptance/PatchApplierCest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Test/Functional/Acceptance/PatchApplierCest.php b/src/Test/Functional/Acceptance/PatchApplierCest.php index 05a0990..f5e58e1 100644 --- a/src/Test/Functional/Acceptance/PatchApplierCest.php +++ b/src/Test/Functional/Acceptance/PatchApplierCest.php @@ -42,7 +42,7 @@ public function testApplyingPatch(\CliTester $I): void $targetFile = $I->grabFileContent('/target_file.md', Docker::BUILD_CONTAINER); $I->assertStringContainsString('# Hello Magento', $targetFile); $I->assertStringContainsString('## Additional Info', $targetFile); - $log = $I->grabFileContent('/var/log/cloud.log', Docker::BUILD_CONTAINER); + $log = $I->grabFileContent('/init/var/log/cloud.log', Docker::BUILD_CONTAINER); $I->assertStringContainsString('Patch ../m2-hotfixes/patch.patch has been applied', $log); } @@ -65,7 +65,7 @@ public function testApplyingExistingPatch(\CliTester $I): void $I->assertStringContainsString('## Additional Info', $targetFile); $I->assertStringContainsString( 'Patch ../m2-hotfixes/patch.patch was already applied', - $I->grabFileContent('/var/log/cloud.log', Docker::BUILD_CONTAINER) + $I->grabFileContent('/init/var/log/cloud.log', Docker::BUILD_CONTAINER) ); } } From 93545569a78d59528282693fb618de0357e94f78 Mon Sep 17 00:00:00 2001 From: Sivaram Manijeganathan Date: Wed, 16 Oct 2024 13:16:37 -0500 Subject: [PATCH 5/6] fix codesniffer issue --- src/Test/Functional/Acceptance/AbstractCest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Test/Functional/Acceptance/AbstractCest.php b/src/Test/Functional/Acceptance/AbstractCest.php index 4346122..07c9c21 100644 --- a/src/Test/Functional/Acceptance/AbstractCest.php +++ b/src/Test/Functional/Acceptance/AbstractCest.php @@ -134,7 +134,6 @@ class AbstractCest "magento/module-page-builder-admin-gws-admin-ui" => "1.7.1" ]; - /** * @param \CliTester $I */ From 0618a33a43a7d97d23babbe5bab790417168ce59 Mon Sep 17 00:00:00 2001 From: Sivaram Manijeganathan Date: Thu, 17 Oct 2024 14:06:40 -0500 Subject: [PATCH 6/6] add new line --- ...fields_hydration_company_account_create_request__1.3.3.patch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patches/B2B-4051__fields_hydration_company_account_create_request__1.3.3.patch b/patches/B2B-4051__fields_hydration_company_account_create_request__1.3.3.patch index 74fa42d..c17eab6 100644 --- a/patches/B2B-4051__fields_hydration_company_account_create_request__1.3.3.patch +++ b/patches/B2B-4051__fields_hydration_company_account_create_request__1.3.3.patch @@ -141,4 +141,4 @@ new file mode 100644 + $companyData = $this->companyRequestHydrator->getCompanyDataFromRequest(); if (is_array($companyData) && !empty($companyData)) { $jobTitle = $companyData['job_title'] ?? null; - $companyDataObject = $this->customerCompany->createCompany($result, $companyData, $jobTitle); \ No newline at end of file + $companyDataObject = $this->customerCompany->createCompany($result, $companyData, $jobTitle);