diff --git a/vendor/magento/module-company/Model/CompanyFieldPool.php b/vendor/magento/module-company/Model/CompanyFieldPool.php new file mode 100644 index 000000000000..114b1f48de30 --- /dev/null +++ b/vendor/magento/module-company/Model/CompanyFieldPool.php @@ -0,0 +1,43 @@ +fields); + } +} diff --git a/vendor/magento/module-company/Model/CompanyProfile.php b/vendor/magento/module-company/Model/CompanyProfile.php index 0056b67950d7..77cc55506c35 100644 --- a/vendor/magento/module-company/Model/CompanyProfile.php +++ b/vendor/magento/module-company/Model/CompanyProfile.php @@ -53,12 +53,22 @@ 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, private readonly DataObjectHelper $objectHelper, private readonly UserContextInterface $userContext, + ?CompanyFieldPool $companyProfileFieldPool = null, + ?CompanyFieldPool $companyAddressFieldPool = null, ) { + if ($companyProfileFieldPool !== null) { + $this->companyProfileFields = $companyProfileFieldPool->getFields(); + } + if ($companyAddressFieldPool !== null) { + $this->companyAddressFields = $companyAddressFieldPool->getFields(); + } } /** @@ -90,16 +100,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 1fe919d2e34c..2ab47c94a40c 100644 --- a/vendor/magento/module-company/etc/di.xml +++ b/vendor/magento/module-company/etc/di.xml @@ -366,4 +366,34 @@ + + + + company_name + legal_name + company_email + vat_tax_id + reseller_id + + + + + + + street + city + country_id + region_id + region + postcode + telephone + + + + + + companyProfileFieldPool + companyAddressFieldPool + +