Skip to content

Commit

Permalink
Merge branch 'develop' into 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
glo21474 committed Oct 21, 2024
2 parents e87bd04 + 4f7bbdf commit 0b545cf
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 2 deletions.
3 changes: 3 additions & 0 deletions patches.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
new file mode 100644
--- /dev/null
+++ b/vendor/magento/module-company/Model/Customer/AccountManagement/CompanyRequestHydrator.php
@@ -0,0 +1,66 @@
+<?php
+/**
+ * Copyright © Magento, Inc. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+declare(strict_types=1);
+
+namespace Magento\Company\Model\Customer\AccountManagement;
+
+use Magento\Company\Api\Data\CompanyInterface;
+
+/**
+ * Getting company data form request.
+ */
+class CompanyRequestHydrator
+{
+ /**
+ * @var \Magento\Framework\App\Request\Http
+ */
+ private $request;
+ /**
+ * @var array
+ */
+ private $fieldsToSave = [
+ CompanyInterface::NAME,
+ CompanyInterface::LEGAL_NAME,
+ CompanyInterface::COMPANY_EMAIL,
+ CompanyInterface::VAT_TAX_ID,
+ CompanyInterface::RESELLER_ID,
+ CompanyInterface::STREET,
+ CompanyInterface::CITY,
+ CompanyInterface::COUNTRY_ID,
+ CompanyInterface::REGION,
+ CompanyInterface::REGION_ID,
+ CompanyInterface::POSTCODE,
+ CompanyInterface::TELEPHONE,
+ CompanyInterface::JOB_TITLE
+ ];
+
+ /**
+ * @param \Magento\Framework\App\Request\Http $request
+ */
+ public function __construct(
+ \Magento\Framework\App\Request\Http $request,
+ ) {
+ $this->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);
4 changes: 2 additions & 2 deletions src/Test/Functional/Acceptance/PatchApplierCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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)
);
}
}

0 comments on commit 0b545cf

Please # to comment.