|
11 | 11 | use Magento\Framework\Api\SearchCriteriaBuilder;
|
12 | 12 | use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Product;
|
13 | 13 | use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Product\FormatterInterface;
|
14 |
| -use Magento\Bundle\Model\Link; |
| 14 | +use Magento\Bundle\Api\Data\LinkInterface; |
15 | 15 | use Magento\Bundle\Model\Option;
|
16 | 16 | use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
|
17 |
| -use Magento\Framework\Exception\RuntimeException; |
18 | 17 | use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
|
19 | 18 | use Magento\Framework\GraphQl\Query\EnumLookup;
|
20 | 19 |
|
21 | 20 | /**
|
22 |
| - * Retrieves simple product data for child products, and formats configurable data |
| 21 | + * Retrieves simple product data for child products, and formats children data |
23 | 22 | */
|
24 | 23 | class BundleProductPostProcessor implements \Magento\Framework\GraphQl\Query\PostFetchProcessorInterface
|
25 | 24 | {
|
@@ -74,24 +73,23 @@ public function __construct(
|
74 | 73 | *
|
75 | 74 | * @param array $resultData
|
76 | 75 | * @return array
|
77 |
| - * @throws RuntimeException |
78 | 76 | */
|
79 | 77 | public function process(array $resultData)
|
80 | 78 | {
|
81 | 79 | $childrenSkus = [];
|
82 | 80 | $bundleMap = [];
|
83 | 81 | foreach ($resultData as $productKey => $product) {
|
84 | 82 | if (isset($product['type_id']) && $product['type_id'] === Bundle::TYPE_CODE) {
|
85 |
| - $resultData[$productKey] = $this->formatBundleAttributes($product); |
86 | 83 | if (isset($product['bundle_product_options'])) {
|
87 | 84 | $bundleMap[$product['sku']] = [];
|
| 85 | + /** @var Option $option */ |
88 | 86 | foreach ($product['bundle_product_options'] as $optionKey => $option) {
|
89 | 87 | $resultData[$productKey]['items'][$optionKey]
|
90 | 88 | = $option->getData();
|
91 |
| - /** @var Link $link */ |
| 89 | + /** @var LinkInterface $link */ |
92 | 90 | foreach ($option['product_links'] as $link) {
|
93 |
| - $bundleMap[$product['sku']][] = $link['sku']; |
94 |
| - $childrenSkus[] = $link['sku']; |
| 91 | + $bundleMap[$product['sku']][] = $link->getSku(); |
| 92 | + $childrenSkus[] = $link->getSku(); |
95 | 93 | $formattedLink = [
|
96 | 94 | 'product' => new GraphQlNoSuchEntityException(
|
97 | 95 | __('Bundled product not found')
|
@@ -157,33 +155,4 @@ private function addChildData(array $childrenProducts, array $resultData, array
|
157 | 155 |
|
158 | 156 | return $resultData;
|
159 | 157 | }
|
160 |
| - |
161 |
| - /** |
162 |
| - * Format bundle specific top level attributes from product |
163 |
| - * |
164 |
| - * @param array $product |
165 |
| - * @return array |
166 |
| - * @throws RuntimeException |
167 |
| - */ |
168 |
| - private function formatBundleAttributes(array $product) |
169 |
| - { |
170 |
| - if (isset($product['price_view'])) { |
171 |
| - $product['price_view'] |
172 |
| - = $this->enumLookup->getEnumValueFromField('PriceViewEnum', $product['price_view']); |
173 |
| - } |
174 |
| - if (isset($product['shipment_type'])) { |
175 |
| - $product['ship_bundle_items'] |
176 |
| - = $this->enumLookup->getEnumValueFromField('ShipBundleItemsEnum', $product['shipment_type']); |
177 |
| - } |
178 |
| - if (isset($product['price_view'])) { |
179 |
| - $product['dynamic_price'] = !(bool)$product['price_type']; |
180 |
| - } |
181 |
| - if (isset($product['sku_type'])) { |
182 |
| - $product['dynamic_sku'] = !(bool)$product['sku_type']; |
183 |
| - } |
184 |
| - if (isset($product['weight_type'])) { |
185 |
| - $product['dynamic_weight'] = !(bool)$product['weight_type']; |
186 |
| - } |
187 |
| - return $product; |
188 |
| - } |
189 | 158 | }
|
0 commit comments