File tree Expand file tree Collapse file tree 3 files changed +11
-1
lines changed
src/Plugin/Commerce/Condition
tests/src/Unit/Plugin/Commerce/Condition Expand file tree Collapse file tree 3 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -134,7 +134,9 @@ protected function getReferencedIds(ProductInterface $product) {
134134 foreach ($ this ->getEntityReferenceFieldMap () as $ field_name => $ field_info ) {
135135 if ($ product ->hasField ($ field_name )) {
136136 $ field = $ product ->get ($ field_name );
137- if (!$ field ->isEmpty ()) {
137+ $ field_definition = $ field ->getFieldDefinition ();
138+ $ target_type = $ field_definition ->getSetting ('target_type ' );
139+ if ($ target_type === 'taxonomy_term ' && !$ field ->isEmpty ()) {
138140 foreach ($ field ->getValue () as $ index => $ field_item ) {
139141 $ ids [] = $ field_item ['target_id ' ];
140142 }
Original file line number Diff line number Diff line change 1010use Drupal \Core \Entity \EntityFieldManagerInterface ;
1111use Drupal \Core \Entity \EntityTypeManagerInterface ;
1212use Drupal \Core \Field \EntityReferenceFieldItemList ;
13+ use Drupal \Core \Field \FieldDefinitionInterface ;
1314use Drupal \Tests \UnitTestCase ;
1415
1516/**
@@ -57,7 +58,10 @@ public function testEvaluate() {
5758 $ this ->assertFalse ($ condition ->evaluate ($ order_item ));
5859
5960 // Product with a non-matching product category.
61+ $ entity_reference_field_definition = $ this ->prophesize (FieldDefinitionInterface::class);
62+ $ entity_reference_field_definition ->getSetting ('target_type ' )->willReturn ('taxonomy_term ' );
6063 $ entity_reference_item_list = $ this ->prophesize (EntityReferenceFieldItemList::class);
64+ $ entity_reference_item_list ->getFieldDefinition ()->willReturn ($ entity_reference_field_definition ->reveal ());
6165 $ entity_reference_item_list ->isEmpty ()->willReturn (FALSE );
6266 $ entity_reference_item_list ->getValue ()->willReturn ([
6367 '1 ' => [
Original file line number Diff line number Diff line change 1111use Drupal \Core \Entity \EntityFieldManagerInterface ;
1212use Drupal \Core \Entity \EntityTypeManagerInterface ;
1313use Drupal \Core \Field \EntityReferenceFieldItemList ;
14+ use Drupal \Core \Field \FieldDefinitionInterface ;
1415use Drupal \Tests \UnitTestCase ;
1516
1617/**
@@ -57,7 +58,10 @@ public function testEvaluate() {
5758 $ first_order_item = $ first_order_item ->reveal ();
5859
5960 // Product with a non-matching product category.
61+ $ entity_reference_field_definition = $ this ->prophesize (FieldDefinitionInterface::class);
62+ $ entity_reference_field_definition ->getSetting ('target_type ' )->willReturn ('taxonomy_term ' );
6063 $ entity_reference_item_list = $ this ->prophesize (EntityReferenceFieldItemList::class);
64+ $ entity_reference_item_list ->getFieldDefinition ()->willReturn ($ entity_reference_field_definition ->reveal ());
6165 $ entity_reference_item_list ->isEmpty ()->willReturn (FALSE );
6266 $ entity_reference_item_list ->getValue ()->willReturn ([
6367 '1 ' => [
You can’t perform that action at this time.
0 commit comments