From 90eb523c28fee385379e91c81a4779d1c06bf195 Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Tue, 1 Sep 2020 20:40:48 -0500 Subject: [PATCH] MC-37193: Fix B2B performance toolkit profile generation on cloud --- .../CustomerTemplateGenerator.php | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/setup/src/Magento/Setup/Model/FixtureGenerator/CustomerTemplateGenerator.php b/setup/src/Magento/Setup/Model/FixtureGenerator/CustomerTemplateGenerator.php index ba57c95999284..4ecbfd3deebf8 100644 --- a/setup/src/Magento/Setup/Model/FixtureGenerator/CustomerTemplateGenerator.php +++ b/setup/src/Magento/Setup/Model/FixtureGenerator/CustomerTemplateGenerator.php @@ -10,6 +10,8 @@ use Magento\Customer\Model\AddressFactory; use Magento\Customer\Model\Customer; use Magento\Customer\Model\CustomerFactory; +use Magento\Directory\Model\ResourceModel\Region\CollectionFactory as RegionCollectionFactory; +use Magento\Framework\App\ObjectManager; use Magento\Store\Model\StoreManagerInterface; /** @@ -32,19 +34,29 @@ class CustomerTemplateGenerator implements TemplateEntityGeneratorInterface */ private $storeManager; + /** + * @var RegionCollectionFactory + */ + private $regionsCollectionFactory; + /** * @param CustomerFactory $customerFactory * @param AddressFactory $addressFactory * @param StoreManagerInterface $storeManager + * @param RegionCollectionFactory|null $regionsCollectionFactory */ public function __construct( CustomerFactory $customerFactory, AddressFactory $addressFactory, - StoreManagerInterface $storeManager + StoreManagerInterface $storeManager, + RegionCollectionFactory $regionsCollectionFactory = null ) { $this->customerFactory = $customerFactory; $this->addressFactory = $addressFactory; $this->storeManager = $storeManager; + $this->regionsCollectionFactory = $regionsCollectionFactory ?: ObjectManager::getInstance()->get( + RegionCollectionFactory::class + ); } /** @@ -119,7 +131,7 @@ private function getAddressTemplate($customerId) 'street' => 'Green str, 67', 'lastname' => 'Smith', 'firstname' => 'John', - 'region_id' => 1, + 'region_id' => $this->getFirstRegionId(), 'fax' => '04040404', 'middlename' => '', 'prefix' => '', @@ -131,4 +143,18 @@ private function getAddressTemplate($customerId) ] ]); } + + /** + * Get first region id. + * + * @return mixed + */ + private function getFirstRegionId() + { + $regionsCollection = $this->regionsCollectionFactory->create(); + $regionsCollection->unshiftOrder('region_id', 'ASC'); + $region = $regionsCollection->getFirstItem(); + + return $region->getRegionId(); + } }