Skip to content

Commit 51d71d9

Browse files
committed
Merge remote-tracking branch 'origin/MC-20638-shipments' into 241-customer-orders
2 parents 00f8a8c + 8e62ca9 commit 51d71d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1582
-562
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\BundleGraphQl\Model\Order\Shipment;
9+
10+
use Magento\Catalog\Model\Product\Type\AbstractType;
11+
use Magento\Sales\Api\Data\ShipmentInterface;
12+
use Magento\Sales\Api\Data\ShipmentItemInterface;
13+
use Magento\SalesGraphQl\Model\Shipment\Item\ShipmentItemFormatter;
14+
use Magento\SalesGraphQl\Model\Shipment\Item\FormatterInterface;
15+
16+
/**
17+
* Format Bundle shipment items for GraphQl output
18+
*/
19+
class BundleShipmentItemFormatter implements FormatterInterface
20+
{
21+
/**
22+
* @var ShipmentItemFormatter
23+
*/
24+
private $itemFormatter;
25+
26+
/**
27+
* @param ShipmentItemFormatter $itemFormatter
28+
*/
29+
public function __construct(ShipmentItemFormatter $itemFormatter)
30+
{
31+
$this->itemFormatter = $itemFormatter;
32+
}
33+
34+
/**
35+
* Format bundle product shipment item
36+
*
37+
* @param ShipmentInterface $shipment
38+
* @param ShipmentItemInterface $item
39+
* @return array|null
40+
*/
41+
public function formatShipmentItem(ShipmentInterface $shipment, ShipmentItemInterface $item): ?array
42+
{
43+
$orderItem = $item->getOrderItem();
44+
$shippingType = $orderItem->getProductOptions()['shipment_type'] ?? null;
45+
if ($shippingType == AbstractType::SHIPMENT_SEPARATELY && !$orderItem->getParentItemId()) {
46+
//When bundle items are shipped separately the children are treated as their own items
47+
return null;
48+
}
49+
return $this->itemFormatter->formatShipmentItem($shipment, $item);
50+
}
51+
}

app/code/Magento/SalesGraphQl/Model/Resolver/BundleOptions.php renamed to app/code/Magento/BundleGraphQl/Model/Resolver/Order/Item/BundleOptions.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\SalesGraphQl\Model\Resolver;
8+
namespace Magento\BundleGraphQl\Model\Resolver\Order\Item;
99

1010
use Magento\Framework\Exception\LocalizedException;
1111
use Magento\Framework\GraphQl\Config\Element\Field;
@@ -15,6 +15,7 @@
1515
use Magento\Framework\Serialize\Serializer\Json;
1616
use Magento\Sales\Api\Data\InvoiceItemInterface;
1717
use Magento\Sales\Api\Data\OrderItemInterface;
18+
use Magento\Sales\Api\Data\ShipmentItemInterface;
1819

1920
/**
2021
* Resolve bundle options items for order item
@@ -59,8 +60,8 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
5960
$item = $value['model'];
6061
return $this->getBundleOptions($item, $value);
6162
}
62-
if ($value['model'] instanceof InvoiceItemInterface) {
63-
/** @var InvoiceItemInterface $item */
63+
if ($value['model'] instanceof InvoiceItemInterface || $value['model'] instanceof ShipmentItemInterface) {
64+
/** @var InvoiceItemInterface|ShipmentItemInterface $item */
6465
$item = $value['model'];
6566
// Have to pass down order and item to map to avoid refetching all data
6667
return $this->getBundleOptions($item->getOrderItem(), $value);

app/code/Magento/BundleGraphQl/composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"magento/module-quote": "*",
1111
"magento/module-quote-graph-ql": "*",
1212
"magento/module-store": "*",
13+
"magento/module-sales": "*",
14+
"magento/module-sales-graph-ql": "*",
1315
"magento/framework": "*"
1416
},
1517
"license": [

app/code/Magento/BundleGraphQl/etc/graphql/di.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,32 @@
6565
</argument>
6666
</arguments>
6767
</type>
68+
<type name="Magento\SalesGraphQl\Model\TypeResolver\OrderItem">
69+
<arguments>
70+
<argument name="productTypeMap" xsi:type="array">
71+
<item name="bundle" xsi:type="string">BundleOrderItem</item>
72+
</argument>
73+
</arguments>
74+
</type>
75+
<type name="Magento\SalesGraphQl\Model\TypeResolver\InvoiceItem">
76+
<arguments>
77+
<argument name="productTypeMap" xsi:type="array">
78+
<item name="bundle" xsi:type="string">BundleInvoiceItem</item>
79+
</argument>
80+
</arguments>
81+
</type>
82+
<type name="Magento\SalesGraphQl\Model\TypeResolver\ShipmentItem">
83+
<arguments>
84+
<argument name="productTypeMap" xsi:type="array">
85+
<item name="bundle" xsi:type="string">BundleShipmentItem</item>
86+
</argument>
87+
</arguments>
88+
</type>
89+
<type name="Magento\SalesGraphQl\Model\Shipment\ItemProvider">
90+
<arguments>
91+
<argument name="formatters" xsi:type="array">
92+
<item name="bundle" xsi:type="object">Magento\BundleGraphQl\Model\Order\Shipment\BundleShipmentItemFormatter\Proxy</item>
93+
</argument>
94+
</arguments>
95+
</type>
6896
</config>

app/code/Magento/BundleGraphQl/etc/schema.graphqls

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,29 @@ enum ShipBundleItemsEnum @doc(description: "This enumeration defines whether bun
8787
TOGETHER
8888
SEPARATELY
8989
}
90+
91+
type BundleOrderItem implements OrderItemInterface {
92+
bundle_options: [ItemSelectedBundleOption] @doc(description: "A list of bundle options that are assigned to the bundle product") @resolver(class: "Magento\\BundleGraphQl\\Model\\Resolver\\Order\\Item\\BundleOptions")
93+
}
94+
95+
type BundleInvoiceItem implements InvoiceItemInterface{
96+
bundle_options: [ItemSelectedBundleOption] @doc(description: "A list of bundle options that are assigned to the bundle product") @resolver(class: "Magento\\BundleGraphQl\\Model\\Resolver\\Order\\Item\\BundleOptions")
97+
}
98+
99+
type BundleShipmentItem implements ShipmentItemInterface {
100+
bundle_options: [ItemSelectedBundleOption] @doc(description: "A list of bundle options that are assigned to the bundle product") @resolver(class: "Magento\\BundleGraphQl\\Model\\Resolver\\Order\\Item\\BundleOptions")
101+
}
102+
103+
type ItemSelectedBundleOption @doc(description: "A list of options of the selected bundle product") {
104+
id: ID! @doc(description: "The unique identifier of the option")
105+
label: String! @doc(description: "The label of the option")
106+
values: [ItemSelectedBundleOptionValue] @doc(description: "A list of products that represent the values of the parent option")
107+
}
108+
109+
type ItemSelectedBundleOptionValue @doc(description: "A list of values for the selected bundle product") {
110+
id: ID! @doc(description: "The unique identifier of the value")
111+
product_name: String! @doc(description: "The name of the child bundle product")
112+
product_sku: String! @doc(description: "The SKU of the child bundle product")
113+
quantity: Float! @doc(description: "Indicates how many of this bundle product were ordered")
114+
price: Money! @doc(description: "The price of the child bundle product")
115+
}

app/code/Magento/SalesGraphQl/Model/InvoiceItemInterfaceTypeResolverComposite.php

Lines changed: 0 additions & 58 deletions
This file was deleted.

app/code/Magento/SalesGraphQl/Model/InvoiceItemTypeResolver.php

Lines changed: 0 additions & 29 deletions
This file was deleted.

app/code/Magento/SalesGraphQl/Model/Resolver/OrderItem/DataProvider.php renamed to app/code/Magento/SalesGraphQl/Model/OrderItem/DataProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\SalesGraphQl\Model\Resolver\OrderItem;
8+
namespace Magento\SalesGraphQl\Model\OrderItem;
99

1010
use Magento\Catalog\Api\Data\ProductInterface;
1111
use Magento\Catalog\Api\ProductRepositoryInterface;

app/code/Magento/SalesGraphQl/Model/Resolver/OrderItem/OptionsProcessor.php renamed to app/code/Magento/SalesGraphQl/Model/OrderItem/OptionsProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\SalesGraphQl\Model\Resolver\OrderItem;
8+
namespace Magento\SalesGraphQl\Model\OrderItem;
99

1010
use Magento\Sales\Api\Data\OrderItemInterface;
1111

app/code/Magento/SalesGraphQl/Model/OrderItemInterfaceTypeResolverComposite.php

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)