| 
 | 1 | +diff --git a/vendor/magento/module-company-graph-ql/Model/Company/PrepareCompanyData.php b/vendor/magento/module-company-graph-ql/Model/Company/PrepareCompanyData.php  | 
 | 2 | +index 0b7630e9fe6b..b369bf6af119 100644  | 
 | 3 | +--- a/vendor/magento/module-company-graph-ql/Model/Company/PrepareCompanyData.php  | 
 | 4 | ++++ b/vendor/magento/module-company-graph-ql/Model/Company/PrepareCompanyData.php  | 
 | 5 | +@@ -1,13 +1,28 @@  | 
 | 6 | + <?php  | 
 | 7 | +-/**  | 
 | 8 | +- * Copyright © Magento, Inc. All rights reserved.  | 
 | 9 | +- * See COPYING.txt for license details.  | 
 | 10 | ++/************************************************************************  | 
 | 11 | ++ *  | 
 | 12 | ++ * ADOBE CONFIDENTIAL  | 
 | 13 | ++ * ___________________  | 
 | 14 | ++ *  | 
 | 15 | ++ * Copyright 2020 Adobe  | 
 | 16 | ++ * All Rights Reserved.  | 
 | 17 | ++ *  | 
 | 18 | ++ * NOTICE: All information contained herein is, and remains  | 
 | 19 | ++ * the property of Adobe and its suppliers, if any. The intellectual  | 
 | 20 | ++ * and technical concepts contained herein are proprietary to Adobe  | 
 | 21 | ++ * and its suppliers and are protected by all applicable intellectual  | 
 | 22 | ++ * property laws, including trade secret and copyright laws.  | 
 | 23 | ++ * Dissemination of this information or reproduction of this material  | 
 | 24 | ++ * is strictly forbidden unless prior written permission is obtained  | 
 | 25 | ++ * from Adobe.  | 
 | 26 | ++ * ************************************************************************  | 
 | 27 | +  */  | 
 | 28 | + declare(strict_types=1);  | 
 | 29 | +   | 
 | 30 | + namespace Magento\CompanyGraphQl\Model\Company;  | 
 | 31 | +   | 
 | 32 | + use Magento\CompanyGraphQl\Model\Company\Address\RegionLoader;  | 
 | 33 | ++use Magento\Directory\Helper\Data;  | 
 | 34 | + use Magento\Framework\GraphQl\Exception\GraphQlInputException;  | 
 | 35 | +   | 
 | 36 | + /**  | 
 | 37 | +@@ -22,9 +37,11 @@ class PrepareCompanyData  | 
 | 38 | +   | 
 | 39 | +     /**  | 
 | 40 | +      * @param RegionLoader $loadRegion  | 
 | 41 | ++     * @param Data $directoryData  | 
 | 42 | +      */  | 
 | 43 | +     public function __construct(  | 
 | 44 | +-        RegionLoader $loadRegion  | 
 | 45 | ++        RegionLoader $loadRegion,  | 
 | 46 | ++        private Data $directoryData  | 
 | 47 | +     ) {  | 
 | 48 | +         $this->loadRegion = $loadRegion;  | 
 | 49 | +     }  | 
 | 50 | +@@ -37,43 +54,106 @@ public function __construct(  | 
 | 51 | +      * @throws GraphQlInputException  | 
 | 52 | +      */  | 
 | 53 | +     public function execute(array $companyData): array  | 
 | 54 | ++    {  | 
 | 55 | ++        $companyData = $this->mergeCompanyAdminData($companyData);  | 
 | 56 | ++        $companyData = $this->mergeLegalAddressData($companyData);  | 
 | 57 | ++  | 
 | 58 | ++        return $companyData;  | 
 | 59 | ++    }  | 
 | 60 | ++  | 
 | 61 | ++    /**  | 
 | 62 | ++     * Merge company admin data into company data.  | 
 | 63 | ++     *  | 
 | 64 | ++     * @param array $companyData  | 
 | 65 | ++     * @return array  | 
 | 66 | ++     */  | 
 | 67 | ++    private function mergeCompanyAdminData(array $companyData): array  | 
 | 68 | +     {  | 
 | 69 | +         if (!empty($companyData['company_admin'])) {  | 
 | 70 | +-            $companyData = array_merge($companyData, $companyData['company_admin']);  | 
 | 71 | ++            return array_merge($companyData, $companyData['company_admin']);  | 
 | 72 | +         }  | 
 | 73 | ++        return $companyData;  | 
 | 74 | ++    }  | 
 | 75 | +   | 
 | 76 | +-        if (!empty($companyData['legal_address'])) {  | 
 | 77 | +-            $addressData = $companyData['legal_address'];  | 
 | 78 | +-            unset($companyData['legal_address']);  | 
 | 79 | +-            $companyData = array_merge($companyData, $addressData);  | 
 | 80 | +-  | 
 | 81 | +-            if (!empty($companyData['region'])) {  | 
 | 82 | +-                $regionData = $addressData['region'];  | 
 | 83 | +-                unset($companyData['region']);  | 
 | 84 | +-                $companyData = array_merge($companyData, $regionData);  | 
 | 85 | +-                if (!isset($regionData['region_id'])) {  | 
 | 86 | +-                    $region = $this->loadRegion->execute(  | 
 | 87 | +-                        $addressData['country_id'] ?? null,  | 
 | 88 | +-                        $regionData['region_id'] ?? null,  | 
 | 89 | +-                        $regionData['region_code'] ?? null,  | 
 | 90 | +-                        $regionData['region'] ?? null  | 
 | 91 | +-                    );  | 
 | 92 | +-                    if ($region && $region->getRegionId()) {  | 
 | 93 | +-                        $companyData['region_id'] = $region->getRegionId();  | 
 | 94 | +-                    } else {  | 
 | 95 | +-                        throw new GraphQlInputException(  | 
 | 96 | +-                            __(  | 
 | 97 | +-                                'Invalid value of "%1" provided for the %2 field.',  | 
 | 98 | +-                                isset($regionData['region_code']) ? $regionData['region_code'] : $regionData['region'],  | 
 | 99 | +-                                isset($regionData['region_code']) ? 'region_code' : 'region'  | 
 | 100 | +-                            )  | 
 | 101 | +-                        );  | 
 | 102 | +-                    }  | 
 | 103 | +-                }  | 
 | 104 | +-  | 
 | 105 | +-            }  | 
 | 106 | ++    /**  | 
 | 107 | ++     * Merge legal address data into company data.  | 
 | 108 | ++     *  | 
 | 109 | ++     * @param array $companyData  | 
 | 110 | ++     * @return array  | 
 | 111 | ++     * @throws GraphQlInputException  | 
 | 112 | ++     */  | 
 | 113 | ++    private function mergeLegalAddressData(array $companyData): array  | 
 | 114 | ++    {  | 
 | 115 | ++        if (empty($companyData['legal_address'])) {  | 
 | 116 | ++            return $companyData;  | 
 | 117 | +         }  | 
 | 118 | +   | 
 | 119 | +-        return $companyData;  | 
 | 120 | ++        $addressData = $companyData['legal_address'];  | 
 | 121 | ++        unset($companyData['legal_address']);  | 
 | 122 | ++        $companyData = array_merge($companyData, $addressData);  | 
 | 123 | ++  | 
 | 124 | ++        return $this->handleRegionData($companyData, $addressData);  | 
 | 125 | ++    }  | 
 | 126 | ++  | 
 | 127 | ++    /**  | 
 | 128 | ++     * Handle region data.  | 
 | 129 | ++     *  | 
 | 130 | ++     * @param array $companyData  | 
 | 131 | ++     * @param array $addressData  | 
 | 132 | ++     * @return array  | 
 | 133 | ++     * @throws GraphQlInputException  | 
 | 134 | ++     */  | 
 | 135 | ++    private function handleRegionData(array $companyData, array $addressData): array  | 
 | 136 | ++    {  | 
 | 137 | ++        if (empty($addressData['region'])) {  | 
 | 138 | ++            $companyData['region'] = '';  | 
 | 139 | ++            return $companyData;  | 
 | 140 | ++        }  | 
 | 141 | ++  | 
 | 142 | ++        $regionData = $addressData['region'];  | 
 | 143 | ++        unset($companyData['region']);  | 
 | 144 | ++        $companyData = array_merge($companyData, $regionData);  | 
 | 145 | ++  | 
 | 146 | ++        return $this->processRegionValidation($companyData, $addressData, $regionData);  | 
 | 147 | ++    }  | 
 | 148 | ++  | 
 | 149 | ++    /**  | 
 | 150 | ++     * Process region validation.  | 
 | 151 | ++     *  | 
 | 152 | ++     * @param array $companyData  | 
 | 153 | ++     * @param array $addressData  | 
 | 154 | ++     * @param array $regionData  | 
 | 155 | ++     * @return array  | 
 | 156 | ++     * @throws GraphQlInputException  | 
 | 157 | ++     */  | 
 | 158 | ++    private function processRegionValidation(array $companyData, array $addressData, array $regionData): array  | 
 | 159 | ++    {  | 
 | 160 | ++        if (!$this->directoryData->isRegionRequired($addressData['country_id'])) {  | 
 | 161 | ++            return $companyData;  | 
 | 162 | ++        }  | 
 | 163 | ++  | 
 | 164 | ++        if (isset($regionData['region_id'])) {  | 
 | 165 | ++            return $companyData;  | 
 | 166 | ++        }  | 
 | 167 | ++  | 
 | 168 | ++        $region = $this->loadRegion->execute(  | 
 | 169 | ++            $addressData['country_id'] ?? null,  | 
 | 170 | ++            $regionData['region_id'] ?? null,  | 
 | 171 | ++            $regionData['region_code'] ?? null,  | 
 | 172 | ++            $regionData['region'] ?? null  | 
 | 173 | ++        );  | 
 | 174 | ++  | 
 | 175 | ++        if ($region && $region->getRegionId()) {  | 
 | 176 | ++            $companyData['region_id'] = $region->getRegionId();  | 
 | 177 | ++            return $companyData;  | 
 | 178 | ++        }  | 
 | 179 | ++  | 
 | 180 | ++        throw new GraphQlInputException(  | 
 | 181 | ++            __(  | 
 | 182 | ++                'Invalid value of "%1" provided for the %2 field.',  | 
 | 183 | ++                $regionData['region_code'] ?? $regionData['region'],  | 
 | 184 | ++                isset($regionData['region_code']) ? 'region_code' : 'region'  | 
 | 185 | ++            )  | 
 | 186 | ++        );  | 
 | 187 | +     }  | 
 | 188 | + }  | 
 | 189 | +diff --git a/vendor/magento/module-company-graph-ql/Model/Resolver/Company/LegalAddress.php b/vendor/magento/module-company-graph-ql/Model/Resolver/Company/LegalAddress.php  | 
 | 190 | +index d3d8d24355b0..3d19a2a36f1d 100644  | 
 | 191 | +--- a/vendor/magento/module-company-graph-ql/Model/Resolver/Company/LegalAddress.php  | 
 | 192 | ++++ b/vendor/magento/module-company-graph-ql/Model/Resolver/Company/LegalAddress.php  | 
 | 193 | +@@ -8,8 +8,10 @@  | 
 | 194 | + namespace Magento\CompanyGraphQl\Model\Resolver\Company;  | 
 | 195 | +   | 
 | 196 | + use Magento\CompanyGraphQl\Model\Company\ResolverAccess;  | 
 | 197 | ++use Magento\Directory\Helper\Data;  | 
 | 198 | + use Magento\Directory\Model\RegionFactory;  | 
 | 199 | + use Magento\Directory\Model\ResourceModel\Region;  | 
 | 200 | ++use Magento\Framework\App\ObjectManager;  | 
 | 201 | + use Magento\Framework\Exception\LocalizedException;  | 
 | 202 | + use Magento\Framework\GraphQl\Config\Element\Field;  | 
 | 203 | + use Magento\Framework\GraphQl\Query\ResolverInterface;  | 
 | 204 | +@@ -45,17 +47,20 @@ class LegalAddress implements ResolverInterface  | 
 | 205 | +      * @param RegionFactory $regionFactory  | 
 | 206 | +      * @param ResolverAccess $resolverAccess  | 
 | 207 | +      * @param array $allowedResources  | 
 | 208 | ++     * @param Data|null $directoryData  | 
 | 209 | +      */  | 
 | 210 | +     public function __construct(  | 
 | 211 | +         Region $regionResource,  | 
 | 212 | +         RegionFactory $regionFactory,  | 
 | 213 | +         ResolverAccess $resolverAccess,  | 
 | 214 | +-        array $allowedResources = []  | 
 | 215 | ++        array $allowedResources = [],  | 
 | 216 | ++        private ?Data $directoryData = null  | 
 | 217 | +     ) {  | 
 | 218 | +         $this->regionResource = $regionResource;  | 
 | 219 | +         $this->regionFactory = $regionFactory;  | 
 | 220 | +         $this->resolverAccess = $resolverAccess;  | 
 | 221 | +         $this->allowedResources = $allowedResources;  | 
 | 222 | ++        $this->directoryData = $directoryData ?? ObjectManager::getInstance()->get(Data::class);  | 
 | 223 | +     }  | 
 | 224 | +   | 
 | 225 | +     /**  | 
 | 226 | +@@ -77,8 +82,13 @@ public function resolve(  | 
 | 227 | +         }  | 
 | 228 | +   | 
 | 229 | +         $company = $value['model'];  | 
 | 230 | ++  | 
 | 231 | +         $region = $this->regionFactory->create();  | 
 | 232 | +-        $this->regionResource->load($region, $company->getRegionId());  | 
 | 233 | ++        if ($this->directoryData->isRegionRequired($company->getCountryId())) {  | 
 | 234 | ++            $this->regionResource->load($region, $company->getRegionId());  | 
 | 235 | ++        } elseif ($company->getRegion()) {  | 
 | 236 | ++            $region->setName($company->getRegion());  | 
 | 237 | ++        }  | 
 | 238 | +   | 
 | 239 | +         return [  | 
 | 240 | +             'street' => $company->getStreet(),  | 
0 commit comments