1

I have two Commerce order types, order_a and order_b, which I created at /admin/commerce/config/order-types.

I'm using Commerce 2 on Drupal 8.

I want to process them differently in hook_commerce_order_presave().

How can I programmatically get the order type? When I check the entity type, it only has commerce_order, but I want to know what type of commerce order it is. I can't find a method to get the order type specifically.

Here's the code I am using:

function MYMODULE_commerce_order_presave(\Drupal\commerce_order\Entity\OrderInterface $entity) {
  if ($entity->isNew()) {
    kint($entity->getEntityTypeId());
    die();
1
  • 1
    Assuming the type is the bundle (probably is): $entity->bundle()
    – Clive
    Nov 10, 2017 at 18:15

1 Answer 1

3

The order type is the bundle so you can use EntityInterface::bundle() to get that info:

$type = $entity->bundle();

Your Answer

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

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