Skip to content

Commit 3728f46

Browse files
authored
Merge pull request #1 from storefront-x/feature/PX-1412
PX-1412 added child_skus for AddConfigurableProductToCart method
2 parents 4dd8d09 + bb0bacd commit 3728f46

File tree

6 files changed

+54
-1
lines changed

6 files changed

+54
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea/

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
### Added
33
- created new module.
44

5+
### [1.0.1]
6+
### Added
7+
- extension of Cart type in GQL schema to return child skus on AddConfigurableProductToCart method

Model/Resolver/ChildSkus.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace StorefrontX\CatalogGraphQlExtended\Model\Resolver;
6+
7+
use Magento\Framework\GraphQl\Config\Element\Field;
8+
use Magento\Framework\GraphQl\Query\ResolverInterface;
9+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
10+
use Magento\Quote\Model\Quote;
11+
12+
class ChildSkus implements ResolverInterface
13+
{
14+
15+
/**
16+
* @inheritdoc
17+
*/
18+
public function resolve(
19+
Field $field,
20+
$context,
21+
ResolveInfo $info,
22+
array $value = null,
23+
array $args = null
24+
): array
25+
{
26+
$result = [];
27+
if (!empty($value['model']) && ($value['model'] instanceof Quote)) {
28+
/** @var Quote $cart */
29+
$cart = $value['model'];
30+
$items = $cart->getItems();
31+
32+
foreach ($items as $item) {
33+
$addToResult['cart_item_id'] = $item->getItemId();
34+
$addToResult['sku'] = $item->getSku();
35+
$result[] = $addToResult;
36+
}
37+
}
38+
return $result;
39+
}
40+
}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"require": {
99
"php": ">=7.4",
1010
"magento/framework": "^103.0.2",
11-
"magento/module-graph-ql": "^100.4.2"
11+
"magento/module-graph-ql": "^100.4.2",
12+
"magento/module-configurable-product-graph-ql": "^100.4.2"
1213
},
1314
"license": [
1415
"MIT"

etc/module.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<sequence>
55
<module name="Magento_GraphQl"/>
66
<module name="Magento_Backend"/>
7+
<module name="Magento_ConfigurableProductGraphQl"/>
78
</sequence>
89
</config>
910

etc/schema.graphqls

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,11 @@ type MSIs {
2020
enabled : String @doc(description: "Enabled")
2121
}
2222

23+
type Cart {
24+
child_skus: [ChildSku] @resolver( class: "\\StorefrontX\\CatalogGraphQlExtended\\Model\\Resolver\\ChildSkus") @doc(description: "Configurable sku variant.")
25+
}
2326

27+
type ChildSku {
28+
cart_item_id : Int @doc(description: "Id in cart")
29+
sku : String @doc(description: "Product SKU")
30+
}

0 commit comments

Comments
 (0)