|
7 | 7 |
|
8 | 8 | namespace Magento\CustomerGraphQl\Model; |
9 | 9 |
|
| 10 | +use Magento\Customer\Api\Data\CustomerInterface; |
| 11 | +use Magento\Customer\Model\Config\Share; |
10 | 12 | use Magento\Framework\Api\SearchCriteriaBuilder; |
| 13 | +use Magento\Framework\App\Config\ScopeConfigInterface; |
11 | 14 | use Magento\Sales\Api\OrderRepositoryInterface; |
12 | 15 | use Magento\Sales\Api\Data\OrderSearchResultInterface; |
13 | 16 |
|
14 | 17 | class GetGuestOrdersByEmail |
15 | 18 | { |
16 | 19 | /** |
17 | 20 | * @param OrderRepositoryInterface $orderRepository |
| 21 | + * @param ScopeConfigInterface $scopeConfig |
18 | 22 | * @param SearchCriteriaBuilder $searchCriteriaBuilder |
19 | 23 | */ |
20 | 24 | public function __construct( |
21 | 25 | private readonly OrderRepositoryInterface $orderRepository, |
22 | | - private SearchCriteriaBuilder $searchCriteriaBuilder |
| 26 | + private readonly ScopeConfigInterface $scopeConfig, |
| 27 | + private readonly SearchCriteriaBuilder $searchCriteriaBuilder |
23 | 28 | ) { |
24 | 29 | } |
25 | 30 |
|
26 | 31 | /** |
27 | 32 | * Retrieve customer orders collection |
28 | 33 | * |
29 | | - * @param string $email |
| 34 | + * @param CustomerInterface $customer |
30 | 35 | * @return OrderSearchResultInterface |
31 | 36 | */ |
32 | | - public function execute(string $email): OrderSearchResultInterface |
| 37 | + public function execute(CustomerInterface $customer): OrderSearchResultInterface |
33 | 38 | { |
34 | | - $this->searchCriteriaBuilder->addFilter( |
35 | | - 'customer_email', |
36 | | - $email, |
37 | | - 'eq' |
38 | | - )->addFilter( |
39 | | - 'customer_is_guest', |
40 | | - 1, |
41 | | - 'eq' |
| 39 | + $this->searchCriteriaBuilder |
| 40 | + ->addFilter('customer_email', $customer->getEmail()) |
| 41 | + ->addFilter('customer_is_guest', 1); |
| 42 | + |
| 43 | + $customerAccountShareScope = (int)$this->scopeConfig->getValue( |
| 44 | + Share::XML_PATH_CUSTOMER_ACCOUNT_SHARE, |
| 45 | + ScopeConfigInterface::SCOPE_TYPE_DEFAULT |
42 | 46 | ); |
| 47 | + |
| 48 | + if ($customerAccountShareScope === Share::SHARE_WEBSITE) { |
| 49 | + $this->searchCriteriaBuilder->addFilter( |
| 50 | + 'store_id', |
| 51 | + $customer->getStoreId() |
| 52 | + ); |
| 53 | + } |
| 54 | + |
43 | 55 | return $this->orderRepository->getList($this->searchCriteriaBuilder->create()); |
44 | 56 | } |
45 | 57 | } |
0 commit comments