|
7 | 7 |
|
8 | 8 | namespace Magento\Sales\Model\ResourceModel\Order\Customer;
|
9 | 9 |
|
| 10 | +use Magento\Framework\Exception\LocalizedException; |
10 | 11 | use Magento\Framework\ObjectManagerInterface;
|
11 | 12 | use Magento\Store\Api\StoreRepositoryInterface;
|
12 | 13 | use Magento\Store\Api\WebsiteRepositoryInterface;
|
@@ -50,4 +51,38 @@ public function testCollection(): void
|
50 | 51 | $this->assertEquals($website->getName(), $customer->getWebsiteName());
|
51 | 52 | $this->assertEquals($store->getName(), $customer->getStoreName());
|
52 | 53 | }
|
| 54 | + |
| 55 | + /** |
| 56 | + * Test customer collection with the website and the store name filter. |
| 57 | + * |
| 58 | + * @throws LocalizedException |
| 59 | + * @see \Magento\Customer\Model\ResourceModel\Customer\Collection::addFieldToFilter() |
| 60 | + * |
| 61 | + * @magentoDataFixture Magento/Customer/_files/customer_for_second_website.php |
| 62 | + */ |
| 63 | + public function testCollectionWithWebsiteStoreFilter(): void |
| 64 | + { |
| 65 | + /** @var Collection $customerCollection */ |
| 66 | + $customerCollection = $this->objectManager->create(Collection::class); |
| 67 | + |
| 68 | + $customer = $customerCollection->getItems(); |
| 69 | + $customer = array_shift($customer); |
| 70 | + |
| 71 | + /** @var WebsiteRepositoryInterface $websiteRepository */ |
| 72 | + $websiteRepository = $this->objectManager->get(WebsiteRepositoryInterface::class); |
| 73 | + $website = $websiteRepository->getById($customer->getWebsiteId()); |
| 74 | + |
| 75 | + /** @var StoreRepositoryInterface $storeRepository */ |
| 76 | + $storeRepository = $this->objectManager->get(StoreRepositoryInterface::class); |
| 77 | + $store = $storeRepository->getById($customer->getStoreId()); |
| 78 | + |
| 79 | + $customerCollectionWithStoreWebsiteFilter = $customerCollection |
| 80 | + ->addFieldToFilter('store_name', $store->getName()) |
| 81 | + ->addFieldToFilter('website_name', $website->getName()); |
| 82 | + $customerWithStoreWebsiteFilter = $customerCollectionWithStoreWebsiteFilter->getItems(); |
| 83 | + $customerWithStoreWebsiteFilter = array_shift($customerWithStoreWebsiteFilter); |
| 84 | + |
| 85 | + $this->assertEquals($website->getName(), $customerWithStoreWebsiteFilter->getWebsiteName()); |
| 86 | + $this->assertEquals($store->getName(), $customerWithStoreWebsiteFilter->getStoreName()); |
| 87 | + } |
53 | 88 | }
|
0 commit comments