I want to extend the addProductsToCart mutation because I need to pass some product attributes and get the into cart using $_item->getProduct()->getData('attribute_name');

In my custom module, I created the etc/schema.graphqls file with the following configuration ...

input CartItemInput { attribute_name: String @resolver (class: "\\MyVendor\\MyModule\\Model\\Resolver\\AttributeName") }

Then, inside the AttributeName.php resolver, I have


namespace MyVendor\MyModule\Model\Resolver;

use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\QuoteGraphQl\Model\Cart\GetCartForUser;

class AttributeName implements ResolverInterface
    public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
        return "test";

Inside Magento_Checkout, default.phtml, when I try to get this attribute, it doesn't work.

What's the issue?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.