OrderRepository
:1
2
3
use Magento\Sales\Model\OrderRepository;
$order = $objectManager->create(OrderRepository::class)->get($orderId);
Here, $orderId
is the ID of the order for which you want to set the custom attribute.
EntityResolver
. There are two ways to resolve the entity:By Order Object:
1
2
3
4
use Amasty\Orderattr\Model\Entity\EntityResolver;
$entityResolver = $objectManager->create(EntityResolver::class);
$entity = $entityResolver->getEntityByOrder($order);
By Order ID:
$entity = $entityResolver->getEntityByOrderId($orderId);
Choose the method that best fits your scenario.
setCustomAttribute
method. This method updates the attribute with the specified value using the following code:1
2
3
4
$attributeCode = 'your_custom_attribute_code'; // Replace with your actual attribute code
$attributeValue = 'your_desired_value'; // Replace with the value you want to set
$entity->setCustomAttribute($attributeCode, $attributeValue);