Skip to content
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

Field "cart_id" on "Order" is not being resolved when using "setPaymentMethodAndPlaceOrder" #2761

Open
pmzandbergen opened this issue Oct 1, 2024 · 0 comments

Comments

@pmzandbergen
Copy link
Contributor

pmzandbergen commented Oct 1, 2024

Description
The (deprecated) setPaymentMethodAndPlaceOrder mutation is broken: [object] (GraphQL\\Error\\Error(code: 0): Cannot return null for non-nullable field \"Order.cart_id\".

This is caused by:

cart_id: String! @doc(description: "Cart ID.")

This field is not returned by \Magento\QuoteGraphQl\Model\Resolver\SetPaymentAndPlaceOrder.

Fix
You either need to add your own resolver (which could simply be using the input parameters) or use a plugin on the existing (Magento Core) resolver:

etc/graphql/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\QuoteGraphQl\Model\Resolver\SetPaymentAndPlaceOrder">
        <plugin name="Adyen\Payment\Plugin\SetCartIdOnSetPaymentMethodAndPlaceOrderMutation"
                type="Adyen\Payment\Plugin\SetCartIdOnSetPaymentMethodAndPlaceOrderMutation"/>
    </type>
    <!-- ... -->
</config>
<?php

declare(strict_types=1);

namespace Adyen\Payment\Plugin;

use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\QuoteGraphQl\Model\Resolver\SetPaymentAndPlaceOrder;

class SetCartIdOnSetPaymentMethodAndPlaceOrderMutation
{
    public function afterResolve(
        SetPaymentAndPlaceOrder $subject,
        mixed $result,
        Field $field,
        mixed $context,
        ResolveInfo $info,
        array $value = null,
        array $args = null
    ) {
        return isset($args['input']['cart_id']) && is_array($result) ? array_merge_recursive($result, [
            'order' => [
                'cart_id' => $args['input']['cart_id'],
            ],
        ]) : $result;
    }
}

This enables users to use the (deprecated) setPaymentMethodAndPlaceOrder mutation which is a temporary fix for issue #2754

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant