InvalidArgumentException: Invalid interval unit provided.

Created on 16 December 2023, about 1 year ago
Updated 18 December 2023, about 1 year ago

I have installed configuration Commerce + Commerce License + Commerce License Access Control to sell access to certain pages. My web site is multilingual.

Everything works fine except the following situation:
- user has a valid license (not expired)
- the site is switched to other than default language
- user clicks "Add to cart" button on the license product

The error message on web site:

The website encountered an unexpected error. Try again later.

Error: Call to a member function set() on null in Drupal\dynamic_page_cache\EventSubscriber\DynamicPageCacheSubscriber->onRequest() (line 145 of core/modules/dynamic_page_cache/src/EventSubscriber/DynamicPageCacheSubscriber.php).

The error message in logs:
InvalidArgumentException: Invalid interval unit "mesiace" provided. in Drupal\commerce\Interval->__construct() (line 39 of /home/website/public_html/web/modules/contrib/commerce/src/Interval.php).

Unit "mesiace" here is "months" translated.

When I switch the site back to English (default language), everything works fine again. The product can be added to cart or the status message is displayed that I can not renew my license yet.

I am not a coder so I am not able to track-down the underlying error, sorry...

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇸🇰Slovakia sketman

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

Comments & Activities

  • Issue created by @sketman
  • 🇮🇱Israel jsacksick

    Sounds like a commerce_license issue, not Commerce. Commerce refuses an invalid interval specified which is "valid". Would be great if you could post the backtrace so we can figure out what code is instantiating the interval.

  • 🇸🇰Slovakia sketman

    @jsacksick Thank you for response
    Please find below the backtrace logs:

    #0 /home/website/public_html/web/modules/contrib/commerce_license/src/Entity/License.php(550): Drupal\commerce\Interval->__construct()
    #1 /home/website/public_html/web/modules/contrib/commerce_license/src/EventSubscriber/LicenseRenewalCartEventSubscriber.php(105): Drupal\commerce_license\Entity\License->canRenew()
    #2 [internal function]: Drupal\commerce_license\EventSubscriber\LicenseRenewalCartEventSubscriber->onCartEntityAdd()
    #3 /home/website/public_html/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func()
    #4 /home/website/public_html/web/modules/contrib/commerce/modules/cart/src/CartManager.php(126): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch()
    #5 /home/website/public_html/web/modules/contrib/commerce_add_to_cart_link/src/Controller/AddToCartController.php(168): Drupal\commerce_cart\CartManager->addOrderItem()
    #6 [internal function]: Drupal\commerce_add_to_cart_link\Controller\AddToCartController->action()
    #7 /home/website/public_html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
    #8 /home/website/public_html/web/core/lib/Drupal/Core/Render/Renderer.php(627): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #9 /home/website/public_html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext()
    #10 /home/website/public_html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
    #11 /home/website/public_html/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #12 /home/website/public_html/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
    #13 /home/website/public_html/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle()
    #14 /home/website/public_html/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
    #15 /home/website/public_html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
    #16 /home/website/public_html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
    #17 /home/website/public_html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle()
    #18 /home/website/public_html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
    #19 /home/website/public_html/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
    #20 /home/website/public_html/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle()
    #21 /home/website/public_html/web/core/lib/Drupal/Core/DrupalKernel.php(704): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
    #22 /home/website/public_html/web/index.php(19): Drupal\Core\DrupalKernel->handle()
    #23 {main}
    
    The website encountered an unexpected error. Try again later.
    
    InvalidArgumentException: Invalid interval unit "mesiace" provided. in Drupal\commerce\Interval->__construct() (line 39 of modules/contrib/commerce/src/Interval.php).
    Drupal\commerce_license\Entity\License->canRenew() (Line: 105)
    Drupal\commerce_license\EventSubscriber\LicenseRenewalCartEventSubscriber->onCartEntityAdd()
    call_user_func() (Line: 111)
    Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 126)
    Drupal\commerce_cart\CartManager->addOrderItem() (Line: 168)
    Drupal\commerce_add_to_cart_link\Controller\AddToCartController->action()
    call_user_func_array() (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
    Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 124)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
    Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 704)
    Drupal\Core\DrupalKernel->handle() (Line: 19)
    
  • 🇮🇱Israel jsacksick

    Hard to say if Commerce license or Commerce is to blame here actually...
    Could be the Interval element...

    Could you check what the following returns?

        $intervals = \Drupal::service('plugin.manager.interval.intervals')->getDefinitions();
    

    This is invoked from the Interval element. See Drupal\interval\Element\Interval::process()

  • 🇸🇰Slovakia sketman

    @jsacksick, how to run this code please?
    Sorry once again for my ignorance, I am not a coder...

Production build 0.71.5 2024