Skip to content

Commit

Permalink
Merge pull request #6097 from magento-performance/MC-37193
Browse files Browse the repository at this point in the history
[Performance] Fix B2B performance toolkit profile generation on cloud
  • Loading branch information
gabrieldagama authored Sep 4, 2020
2 parents 05fce8b + 7fd2c34 commit ddf3c62
Showing 1 changed file with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

/**
Expand Down Expand Up @@ -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' => '',
Expand All @@ -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();
}
}

0 comments on commit ddf3c62

Please sign in to comment.