Add ability to apply custom logic for order item cloning and availability checking.

Created on 14 April 2023, about 2 years ago

Problem/Motivation

We are using the stock module, and we want to be able to restrict adding of some products to the cart. We can just override the controller and copy-paste everything, but I don't like it.

Another thing is that we are using commerce_vado module. It adds a lot of complexity. It extensively uses data field in order_items. Hence we need to somehow clean up the order item cloning. It could be done in ORDER_CLONED, but as for me, it should be triggered only once and not in the loop.

Proposed resolution

Add two more events to be able to react on order item cloning and order item availability check.

πŸ“Œ Task
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine dinazaur

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

Merge Requests

Comments & Activities

  • Issue created by @dinazaur
  • Issue was unassigned.
  • Status changed to Needs review about 2 years ago
  • Status changed to Needs work 14 days ago
  • πŸ‡ΊπŸ‡ΈUnited States seanr

    This patch causes a fatal error on 2.4 in Drupal 10:

    TypeError: Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher::dispatch(): Argument #1 ($event) must be of type object, string given, called in /var/www/html/web/modules/contrib/commerce_repeat_order/src/Controller/CommerceRepeatOrder.php on line 125 in Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (line 89 of core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php).
    
    Drupal\commerce_repeat_order\Controller\CommerceRepeatOrder->repeatOrder(Object)
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 638)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 121)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 53)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
    Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 116)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 90)
    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: 36)
    Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 741)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
    
  • πŸ‡ΊπŸ‡ΈUnited States seanr

    Dispatcher argument order switched at some point. Latest commit to the MR fixes.

Production build 0.71.5 2024