- 🇮🇹Italy gatiba
Patch #10 seems to have no effect on Commerce 2.36. The new select field "condition" doesn't works.
- Merge request !307Issue #3178165: Add negate and and/or functionality to order product category condition → (Open) created by rhovland
- 🇺🇸United States rhovland Oregon
Added tests for new functionality but they fail for a reason I don't understand.
Drupal\Tests\commerce_product\Unit\Plugin\Commerce\Condition\OrderItemProductCategoryTest::testEvaluate TypeError: array_intersect(): Argument #1 ($array) must be of type array, null given
I'm guessing it's taking issue with
$configuration['terms'] = ['62e428e1-88a6-478c-a8c6-a554ca2332ae', 'a019d89b-c4d9-4ed4-b859-894e4e2e93cf'];
as it says it's supposed to be an array but null was given instead? - 🇨🇭Switzerland Lukas von Blarer
The operators didn't work for me either. I ended up trying to write a custom condition that negates the default one commerce provides. Which turned out to be very easy:
<?php namespace Drupal\MODULE\Plugin\Commerce\Condition; use Drupal\commerce_product\Plugin\Commerce\Condition\OrderItemProductCategory; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; /** * Provides the product category negated condition for order items. * * @CommerceCondition( * id = "order_item_product_category_negated", * label = @Translation("Product category negated"), * display_label = @Translation("Product categories negated"), * category = @Translation("Products"), * entity_type = "commerce_order_item", * ) */ class OrderItemProductCategoryNegated extends OrderItemProductCategory implements ContainerFactoryPluginInterface { /** * {@inheritdoc} */ public function evaluate(EntityInterface $entity) { return !parent::evaluate($entity); } }
Maybe we could even use that for this issue?