Add negate and and/or functionality to order product category condition

Created on 21 October 2020, about 4 years ago
Updated 16 August 2024, 4 months ago

With the inactivity in creating a general solution for negating conditions Create an option to negate conditions Active , patches are required to do so for any project that needs the functionality. After creating a patch for the product condition in #3039905: Add negate and and/or functionality to order product condition , I was asked to create one for the Order Product Category conditions. I will provide a patch that additionally adds a choice of operator (and/or) and combines the operator and negation into select options, for better UX/understanding of non-technical users, as in #3039905: Add negate and and/or functionality to order product condition .

Feature request
Status

Needs work

Version

2.0

Component

Product

Created by

🇬🇷Greece s.messaris

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇹Italy gatiba

    Patch #10 seems to have no effect on Commerce 2.36. The new select field "condition" doesn't works.

  • Pipeline finished with Failed
    4 months ago
    Total: 769s
    #256304
  • 🇺🇸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?

  • Pipeline finished with Skipped
    23 days ago
    #354089
  • Pipeline finished with Success
    19 days ago
    Total: 154s
    #357694
  • Pipeline finished with Failed
    19 days ago
    Total: 150s
    #357699
  • Pipeline finished with Success
    19 days ago
    Total: 162s
    #357703
  • Pipeline finished with Failed
    6 days ago
    Total: 36s
    #369795
  • Pipeline finished with Failed
    5 days ago
    Total: 71s
    #370899
  • Pipeline finished with Failed
    5 days ago
    Total: 46s
    #370900
  • Pipeline finished with Failed
    5 days ago
    Total: 30s
    #370902
  • Pipeline finished with Success
    5 days ago
    Total: 299s
    #370922
Production build 0.71.5 2024