Skip to content

Commit

Permalink
Merge pull request #1 from storefront-x/feature/PX-1412
Browse files Browse the repository at this point in the history
PX-1412 added child_skus for AddConfigurableProductToCart method
  • Loading branch information
bogdanwalek authored Nov 22, 2022
2 parents 4dd8d09 + bb0bacd commit 3728f46
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea/
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
### Added
- created new module.

### [1.0.1]
### Added
- extension of Cart type in GQL schema to return child skus on AddConfigurableProductToCart method
40 changes: 40 additions & 0 deletions Model/Resolver/ChildSkus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace StorefrontX\CatalogGraphQlExtended\Model\Resolver;

use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Quote\Model\Quote;

class ChildSkus implements ResolverInterface
{

/**
* @inheritdoc
*/
public function resolve(
Field $field,
$context,
ResolveInfo $info,
array $value = null,
array $args = null
): array
{
$result = [];
if (!empty($value['model']) && ($value['model'] instanceof Quote)) {
/** @var Quote $cart */
$cart = $value['model'];
$items = $cart->getItems();

foreach ($items as $item) {
$addToResult['cart_item_id'] = $item->getItemId();
$addToResult['sku'] = $item->getSku();
$result[] = $addToResult;
}
}
return $result;
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"require": {
"php": ">=7.4",
"magento/framework": "^103.0.2",
"magento/module-graph-ql": "^100.4.2"
"magento/module-graph-ql": "^100.4.2",
"magento/module-configurable-product-graph-ql": "^100.4.2"
},
"license": [
"MIT"
Expand Down
1 change: 1 addition & 0 deletions etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<sequence>
<module name="Magento_GraphQl"/>
<module name="Magento_Backend"/>
<module name="Magento_ConfigurableProductGraphQl"/>
</sequence>
</config>

7 changes: 7 additions & 0 deletions etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ type MSIs {
enabled : String @doc(description: "Enabled")
}

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

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

0 comments on commit 3728f46

Please sign in to comment.