Skip to content

Added new resolver for getting order status label per store view #33645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 2.4-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/code/Magento/SalesGraphQl/Model/Formatter/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public function format(OrderInterface $orderModel): array
'number' => $orderModel->getIncrementId(),
'order_date' => $orderModel->getCreatedAt(),
'order_number' => $orderModel->getIncrementId(),
'status' => $orderModel->getStatusLabel(),
'shipping_method' => $orderModel->getShippingDescription(),
'shipping_address' => $this->orderAddress->getOrderShippingAddress($orderModel),
'billing_address' => $this->orderAddress->getOrderBillingAddress($orderModel),
Expand Down
59 changes: 59 additions & 0 deletions app/code/Magento/SalesGraphQl/Model/Resolver/OrderStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\SalesGraphQl\Model\Resolver;

use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Model\Order\StatusFactory;

/**
* Resolve order status for store view
*/
class OrderStatus implements ResolverInterface
{
/**
* @var StatusFactory
*/
private $orderStatusFactory;

/**
* Constructor
*
* @param StatusFactory $orderStatusFactory
*/
public function __construct(
StatusFactory $orderStatusFactory
) {
$this->orderStatusFactory = $orderStatusFactory;
}

/**
* @inheritDoc
*/
public function resolve(
Field $field,
$context,
ResolveInfo $info,
array $value = null,
array $args = null
) {
if (!(($value['model'] ?? null) instanceof OrderInterface)) {
throw new LocalizedException(__('"model" value should be specified'));
}

/** @var OrderInterface $order */
$order = $value['model'];
$store = $context->getExtensionAttributes()->getStore();

$status = $this->orderStatusFactory->create()->load($order->getStatus());
return $status->getStoreLabel($store);
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/SalesGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type CustomerOrders @doc(description: "The collection of orders that match the c
type CustomerOrder @doc(description: "Contains details about each of the customer's orders") {
id: ID! @doc(description: "The unique ID for a `CustomerOrder` object")
order_date: String! @doc(description: "The date the order was placed")
status: String! @doc(description: "The current status of the order")
status: String! @doc(description: "The current status of the order") @resolver(class: "Magento\\SalesGraphQl\\Model\\Resolver\\OrderStatus")
number: String! @doc(description: "The order number")
items: [OrderItemInterface] @doc(description: "An array containing the items purchased in this order") @resolver(class: "Magento\\SalesGraphQl\\Model\\Resolver\\OrderItems")
total: OrderTotal @doc(description: "Contains details about the calculated totals for this order") @resolver(class: "Magento\\SalesGraphQl\\Model\\Resolver\\OrderTotal")
Expand Down