diff --git a/vendor/magento/module-company/Model/CompanyFieldPool.php b/vendor/magento/module-company/Model/CompanyFieldPool.php new file mode 100644 index 000000000000..75c11129bbaa --- /dev/null +++ b/vendor/magento/module-company/Model/CompanyFieldPool.php @@ -0,0 +1,42 @@ +fields); + } +} diff --git a/vendor/magento/module-company/Model/CompanyProfile.php b/vendor/magento/module-company/Model/CompanyProfile.php index aa724504e876..71230b1887db 100644 --- a/vendor/magento/module-company/Model/CompanyProfile.php +++ b/vendor/magento/module-company/Model/CompanyProfile.php @@ -47,13 +47,23 @@ class CompanyProfile * @param CompanyContext $companyContext * @param DataObjectHelper $objectHelper * @param UserContextInterface $userContext + * @param CompanyFieldPool|null $companyProfileFieldPool + * @param CompanyFieldPool|null $companyAddressFieldPool */ public function __construct( private readonly CompanyContext $companyContext, DataObjectHelper $objectHelper, private readonly UserContextInterface $userContext, + ?CompanyFieldPool $companyProfileFieldPool = null, + ?CompanyFieldPool $companyAddressFieldPool = null, ) { $this->objectHelper = $objectHelper; + if ($companyProfileFieldPool !== null) { + $this->companyProfileFields = $companyProfileFieldPool->getFields(); + } + if ($companyAddressFieldPool !== null) { + $this->companyAddressFields = $companyAddressFieldPool->getFields(); + } } /** @@ -85,16 +95,13 @@ public function filterDataBasedOnCompanyAclPermissions(array $data): array // company ACL permissions only apply in the storefront customer context return $data; } - if (!$this->companyContext->isResourceAllowed('Magento_Company::edit_account')) { - foreach ($this->companyProfileFields as $field) { - unset($data[$field]); - } + $allowedFields = []; + if ($this->companyContext->isResourceAllowed('Magento_Company::edit_account')) { + $allowedFields = array_merge($allowedFields, $this->companyProfileFields); } - if (!$this->companyContext->isResourceAllowed('Magento_Company::edit_address')) { - foreach ($this->companyAddressFields as $field) { - unset($data[$field]); - } + if ($this->companyContext->isResourceAllowed('Magento_Company::edit_address')) { + $allowedFields = array_merge($allowedFields, $this->companyAddressFields); } - return $data; + return array_intersect_key($data, array_flip($allowedFields)); } } diff --git a/vendor/magento/module-company/etc/di.xml b/vendor/magento/module-company/etc/di.xml index 2dcc0af1a97d..cbc695188b7a 100755 --- a/vendor/magento/module-company/etc/di.xml +++ b/vendor/magento/module-company/etc/di.xml @@ -304,4 +304,34 @@ + + + + company_name + legal_name + company_email + vat_tax_id + reseller_id + + + + + + + street + city + country_id + region_id + region + postcode + telephone + + + + + + companyProfileFieldPool + companyAddressFieldPool + +