Does not work with promotion offers

Created on 24 September 2021, over 3 years ago
Updated 7 September 2023, over 1 year ago

Problem/Motivation

/**
 * Implements hook_element_plugin_alter().
 */
function commerce_conditions_plus_element_plugin_alter(array &$definitions) {
  // @note cannot do this, as it breaks when embedded in promotion offers.
  // $definitions['commerce_conditions']['class'] = ConditionsTableElement::class;
}

The conditions table does not play well inside of a Promotion form. We currently only support payment gateways and shipping methods. Resolve whatever is wrong on Promotions (AJAX woes.)

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States mglaman WI, USA

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

Comments & Activities

Not all content is available!

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

  • πŸ‡¬πŸ‡§United Kingdom Rob-PS

    I have tried option using OR to test if the negate is picking up

    customer buys 1
    set to product
    product A (the cart product(s) )

    custiomer gets 1
    set to product
    product B (the cart add-on product(s) )
    add on is set to "100% off" so is Free.

    ------- I use in the 'plus' select block --------
    product variation = "product X within A" --> Negate
    (There is nothing here to place "OR")
    -----------------------------------------
    The result should be "not a free add-on". But the result is a free add-on.

    ------- I use in the 'plus' select block --------
    product variation = "product Z within A"
    -----------------------------------------
    The result is "not a free add-on", which is correct.

    So negate fails.

  • πŸ‡¬πŸ‡§United Kingdom Rob-PS

    Would it be possible to use an attribute to select on?
    Then negating things is not always needed (still has to be solved for case like "not dollar currency".

    ------- the 'plus' select block --------------
    attribute = "free product"
    -----------------------------------------
    Hence if a product attribute is set to "Charged" then the product is not free.

  • πŸ‡¬πŸ‡§United Kingdom Rob-PS

    Imagines there are 500 shirt products with the same discount. Only 2 have a different offer.
    You don't to create 498 variation entries, and then new promotions for the other two.

    I tested creating a promo with order group x "discount all" then give 2 poducts of that group a different discount. That does not work, the result is always all get discounted.

    Proposal:

    Add the option to add AND / OR between the offers to create a combined offer like this.

    OFFER 1 --- discount all products
    OR if
    OFFER 2 --- discount this separate (of that product group in OFFER 1)
    OR if
    OFFER 3 --- discount this separate (of that product group in OFFER 1)
    -----------------------------------------
    Create AND/OR and drag to position

    -------standard condition block -------------
    conditions with AND / OR options
    all conditions must pass or only one <--- this seems to apply only to the condition area.
    -----------------------------------------

    Would be helpful if also the offers groups can be dragged to reorder.

  • Please do not hijack this issue. Thank you.

  • πŸ‡¬πŸ‡§United Kingdom Rob-PS

    Thanks for the response, apologies for "hyjacking" the issue.

    Is there still work done on the 'negate' issue not working in the condition interface or temporary delayed?
    I tried several ways using "Order contains specific product variations" with the OR option to see if that works. I need this and what ever I try nothing works, in all cases the negate is ignored.

    In the interface I have something set which should NOT be applied when there is an item in the condition interface like 1 Product variation, this to create an exception.

    Thanks!

  • It doesn't work at all with promotions at this point.

  • πŸ‡ΊπŸ‡ΈUnited States nicxvan

    Ok I've installed and applied this patch, it seems to work for adding negated conditions to promotions. I'll test further if it actually works, but the form interface seems clean to me.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    6 pass
  • @nicxvan opened merge request.
  • Status changed to RTBC over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States nicxvan

    I've tested this with roles and everything works!

    I've also converted it to an MR and removed some unused code.

  • Status changed to Needs work over 1 year ago
  • For this to work, the conditions need to be able to be nested under the AND and OR conditions.

    As it is right now they do work with out nesting, they don't work with nesting. To reproduce, put whatever conditions you are checking nested under an AND condition, and they don't work.

    Also noticed in removing the added AND operator and and resaving the promotion, I get the following error:

    The website encountered an unexpected error. Please try again later.
    
    TypeError: Drupal\commerce_conditions_plus\ConditionsEvaluator::evaluateConditionGroup(): Argument #2 ($operator) must be of type string, null given, called in /var/www/html/web/modules/contrib/commerce_conditions_plus/src/ConditionsEvaluator.php on line 65 in Drupal\commerce_conditions_plus\ConditionsEvaluator->evaluateConditionGroup() (line 86 of modules/contrib/commerce_conditions_plus/src/ConditionsEvaluator.php).
    Drupal\commerce_conditions_plus\ConditionsEvaluator->execute(Array, 'AND', Array) (Line: 39)
    Drupal\commerce_conditions_plus\Entity\Promotion->applies(Object) (Line: 131)
    Drupal\commerce_promotion\PromotionOrderProcessor->process(Object) (Line: 189)
    Drupal\commerce_order\OrderRefresh->refresh(Object) (Line: 113)
    Drupal\commerce_order\OrderStorage->doOrderPreSave(Object) (Line: 78)
    Drupal\commerce_order\OrderStorage->invokeHook('presave', Object) (Line: 529)
    Drupal\Core\Entity\EntityStorageBase->doPreSave(Object) (Line: 753)
    Drupal\Core\Entity\ContentEntityStorageBase->doPreSave(Object) (Line: 483)
    Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 806)
    Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object) (Line: 159)
    Drupal\commerce_order\OrderStorage->save(Object) (Line: 339)
    Drupal\Core\Entity\EntityBase->save() (Line: 280)
    Drupal\commerce_cart\Plugin\views\field\EditQuantity->viewsFormSubmit(Array, Object) (Line: 183)
    Drupal\views\Form\ViewsFormMainForm->submitForm(Array, Object) (Line: 190)
    Drupal\views\Form\ViewsForm->submitForm(Array, Object)
    call_user_func_array(Array, Array) (Line: 114)
    Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 52)
    Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 597)
    Drupal\Core\Form\FormBuilder->processForm('views_form_commerce_cart_form_default_8997', Array, Object) (Line: 325)
    Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 224)
    Drupal\Core\Form\FormBuilder->getForm(Object, Object, Array) (Line: 2269)
    Drupal\views\Plugin\views\display\DisplayPluginBase->elementPreRender(Array)
    call_user_func_array(Array, Array) (Line: 111)
    Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 788)
    Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 377)
    Drupal\Core\Render\Renderer->doRender(Array) (Line: 449)
    Drupal\Core\Render\Renderer->doRender(Array) (Line: 449)
    Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
    Drupal\Core\Render\Renderer->render(Array, ) (Line: 238)
    Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 583)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 231)
    Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 128)
    Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
    Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
    call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
    Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 187)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 50)
    Drupal\ban\BanMiddleware->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Production build 0.71.5 2024