|
11 | 11 | use Magento\Customer\Api\CustomerRepositoryInterface as CustomerRepository;
|
12 | 12 | use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
|
13 | 13 | use Magento\Framework\Api\SearchCriteriaInterface;
|
| 14 | +use Magento\Framework\App\ResourceConnection; |
| 15 | +use Magento\GroupedProduct\Model\ResourceModel\Product\Link; |
14 | 16 | use Magento\Sales\Model\ResourceModel\Order\Collection;
|
15 | 17 | use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
|
16 | 18 | use Magento\Sales\Model\Order as OrderModel;
|
@@ -48,20 +50,28 @@ class Order
|
48 | 50 | * @var CollectionProcessorInterface
|
49 | 51 | */
|
50 | 52 | private $collectionProcessor;
|
| 53 | + /** |
| 54 | + * @var ResourceConnection |
| 55 | + */ |
| 56 | + private $resourceConnection; |
51 | 57 |
|
52 | 58 | /**
|
53 |
| - * Product constructor. |
| 59 | + * Order constructor. |
54 | 60 | * @param CollectionFactory $orderCollectionFactory
|
55 | 61 | * @param CustomerRepository $customerRepository
|
| 62 | + * @param CollectionProcessorInterface $collectionProcessor |
| 63 | + * @param ResourceConnection $resourceConnection |
56 | 64 | */
|
57 | 65 | public function __construct(
|
58 | 66 | CollectionFactory $orderCollectionFactory,
|
59 | 67 | CustomerRepository $customerRepository,
|
60 |
| - CollectionProcessorInterface $collectionProcessor |
| 68 | + CollectionProcessorInterface $collectionProcessor, |
| 69 | + ResourceConnection $resourceConnection |
61 | 70 | ) {
|
62 | 71 | $this->orderCollectionFactory = $orderCollectionFactory;
|
63 | 72 | $this->customerRepository = $customerRepository;
|
64 | 73 | $this->collectionProcessor = $collectionProcessor;
|
| 74 | + $this->resourceConnection = $resourceConnection; |
65 | 75 | }
|
66 | 76 |
|
67 | 77 | /**
|
@@ -182,6 +192,23 @@ private function getProducts(OrderModel $order): array
|
182 | 192 | $item->getParentItem()->getProductType() == Type::TYPE_BUNDLE) {
|
183 | 193 | $orderedProduct['parent_id'] = $item->getParentItem()->getProductId();
|
184 | 194 | }
|
| 195 | + |
| 196 | + if ($item->getProductType() == 'grouped') { |
| 197 | + $connection = $this->resourceConnection->getConnection(); |
| 198 | + $parentProduct = $connection->select()->from( |
| 199 | + $this->resourceConnection->getTableName('catalog_product_link'), |
| 200 | + ['product_id'] |
| 201 | + )->where( |
| 202 | + 'link_type_id = ?', |
| 203 | + Link::LINK_TYPE_GROUPED |
| 204 | + )->where( |
| 205 | + 'linked_product_id = ?', |
| 206 | + $item->getProductId() |
| 207 | + ); |
| 208 | + $orderedProduct['id'] = $connection->fetchOne($parentProduct); |
| 209 | + $orderedProduct['variant_id'] = $item->getProductId(); |
| 210 | + } |
| 211 | + |
185 | 212 | $orderedProducts[] = $orderedProduct;
|
186 | 213 | }
|
187 | 214 |
|
|
0 commit comments