I’m using:
- Drupal 9.1.7
- Commerce 2.24
I’m trying to create my custom condition (based on https://docs.drupalcommerce.org/commerce2/developer-guide/core/conditions). However parent entity is always NULL. Seems like parent entity is only working when I specify commerce_order
as entity_type
only, but I need commerce_order_item
. ParentEntityAwareInterface
and ParentEntityAwareTrait
are in use. Debugging show that:
public function evaluate(EntityInterface $entity) {
$this->assertEntity($entity);
/** @var Drupalcommerce_orderEntityOrderItemInterface $order_item */
$order_item = $entity;
/** @var Drupalcommerce_promotionEntityPromotionInterface $promotion */
$promotion = $this->parentEntity;
//$promotion is NULL
// rest of the code
}
$promotion
is always null.
Annotation:
* @CommerceCondition(
* id = "myproj_product_condition",
* label = @Translation("Product chooser"),
* category = @Translation("Product chooser"),
* entity_type = "commerce_order_item",
* parent_entity_type = "commerce_promotion",
* weight = 9,
* )