1

I am suppose to:

  1. Load extension attribute when an order is loaded using the OrderRepositoryInterface.

  2. Implement functionality to save extension attribute data when an order is saved using the OrderRepositoryInterface.

I am confused with how to do this. How do I do this the right way?

1
  • 1
    For proper answer, please clarify what are you mean under first question. I think you can use entity repository or load method for load related entity Jun 5, 2022 at 2:56

1 Answer 1

1

For partial save order attribute(s) I suggest to use following logic

<?php
declare(strict_types=1);

namespace Acme\StackExchange\Plugin\Sales\Api;

use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\OrderManagementInterface;
use Magento\Sales\Model\ResourceModel\Order as OrderResource;

class OrderManagementInterfacePlugin
{
    /**
     * @var OrderResource
     */
    protected $orderResource;

    public function __construct(
        OrderResource $orderResource
    ) {
        $this->orderResource = $orderResource;
    }

    public function afterPlace(
        OrderManagementInterface $subject,
        OrderInterface $result,
        OrderInterface $order
    ): OrderInterface {
        $order->setData('some_attribute', 'value');
        $this->orderResource->saveAttribute($order, 'some_attribute');

        return $result;
    }
}

You can use array for list of attributes in saveAttribute method

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.