- I have created two extensions and it’s an add fee on Order Total.
Now on adding this fee to Get CustomerOrder Graphql so, we override the default Magento Get CustomerOrder Graphql and it’s working. - But We Enabled both fee extensions and ran Graphql then only one fee show and not showing both extension fee on Get CustomerOrder Graphql.
Below is the Query.
query{
customerOrders {
items {
order_number
id
created_at
grand_total
status
fee1
fee2
}
}
}
when I execute the above query, it will display fee1 but it will not display fee2. If I disable the fee1 extension then fee2 displays on graphql.
Response:
{
“data”: {
“customerOrders”: {
“items”: [
{
“order_number”: “000000004”,
“id”: “4”,
“created_at”: “2023-12-05 11:58:52”,
“grand_total”: 146,
“status”: “pending”,
“fee1”: 5,
“fee2”: null,
}
]
}
}
}
Fee1 Code is here
GraphQL queries File etc/schema.graphqls
type Query { customerOrders: CustomerOrders @resolver(class: "Vendor\Extension\Model\Resolver\Orders") @deprecated(reason: "Use the `customer` query instead.") }
type CustomerOrders @doc(description: "The collection of orders that match the conditions defined in the filter.") { items: [CustomerOrder]! @doc(description: "An array of customer orders.") page_info: SearchResultPageInfo @doc(description: "Contains pagination metadata.") total_count: Int @doc(description: "The total count of customer orders.") }
type CustomerOrder { fee1: Float }
GraphQL Resolver File Model/Resolver/Orders.php
<?php
namespace VendorExtensionModelResolver;
use MagentoFrameworkGraphQlConfigElementField;
use MagentoFrameworkGraphQlExceptionGraphQlAuthorizationException;
use MagentoFrameworkGraphQlQueryResolverInterface;
use MagentoFrameworkGraphQlSchemaTypeResolveInfo;
use MagentoGraphQlModelQueryContextInterface;
use MagentoSalesModelOrder;
use MagentoSalesModelResourceModelOrderCollectionFactoryInterface;
/**
* Orders data reslover
*/
class Orders implements ResolverInterface
{
/**
* @var CollectionFactoryInterface
*/
private $collectionFactory;
/**
* @param CollectionFactoryInterface $collectionFactory
*/
public function __construct(
CollectionFactoryInterface $collectionFactory
) {
$this->collectionFactory = $collectionFactory;
}
/**
* @inheritDoc
*/
public function resolve(
Field $field,
$context,
ResolveInfo $info,
array $value = null,
array $args = null
) {
/** @var ContextInterface $context */
if (false === $context->getExtensionAttributes()->getIsCustomer()) {
throw new GraphQlAuthorizationException(__('The current customer isn't authorized.'));
}
$items = [];
$orders = $this->collectionFactory->create($context->getUserId());
/** @var Order $order */
foreach ($orders as $order) {
$items[] = [
'id' => $order->getId(),
'fee1' => $order->getFee(),
'model' => $order
];
}
return ['items' => $items];
}
}