Error: Call to a member function getTimestamp() on int in Drupal\commerce_license\EventSubscriber\LicenseRenewalCartEventSubscriber->onCartEntityAdd() (line 123 of /code/web/modules/contrib/commerce_license/src/EventSubscriber/LicenseRenewalCartEventSubsc

Created on 20 October 2024, about 1 month ago

Problem/Motivation

I encountered the error when try to add product to the cart on a specific product. I have been using commerce_license with commerce_recurring. when customer purchase a subscription for a product at first time then the module is not reporting the error, however, when customer try to rebuy the same product again then the module throws this error.

here is the full error:

#0 [internal function]: Drupal\commerce_license\EventSubscriber\LicenseRenewalCartEventSubscriber->onCartEntityAdd(Object(Drupal\commerce_cart\Event\CartEntityAddEvent), 'commerce_cart.e...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#1 /code/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Drupal\commerce_cart\Event\CartEntityAddEvent), 'commerce_cart.e...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#2 /code/web/modules/contrib/commerce/modules/cart/src/CartManager.php(126): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Drupal\commerce_cart\Event\CartEntityAddEvent), 'commerce_cart.e...')
#3 /code/web/modules/contrib/commerce/modules/cart/src/Form/AddToCartForm.php(218): Drupal\commerce_cart\CartManager->addOrderItem(Object(Drupal\commerce_order\Entity\Order), Object(Drupal\commerce_xquantity\Entity\XquantityOrderItem), false)
#4 /code/web/modules/contrib/commerce_xquantity/src/Form/XquantityAddTocartForm.php(121): Drupal\commerce_cart\Form\AddToCartForm->submitForm(Array, Object(Drupal\Core\Form\FormState))
#5 [internal function]: Drupal\commerce_xquantity\Form\XquantityAddTocartForm->submitForm(Array, Object(Drupal\Core\Form\FormState))
#6 /code/web/core/lib/Drupal/Core/Form/FormSubmitter.php(129): call_user_func_array(Array, Array)
#7 /code/web/core/lib/Drupal/Core/Form/FormSubmitter.php(67): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object(Drupal\Core\Form\FormState))
#8 /code/web/core/lib/Drupal/Core/Form/FormBuilder.php(597): Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object(Drupal\Core\Form\FormState))
#9 /code/web/core/lib/Drupal/Core/Form/FormBuilder.php(326): Drupal\Core\Form\FormBuilder->processForm('commerce_order_...', Array, Object(Drupal\Core\Form\FormState))
#10 /code/web/modules/contrib/commerce/modules/product/src/ProductLazyBuilders.php(97): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\commerce_xquantity\Form\XquantityAddTocartForm), Object(Drupal\Core\Form\FormState))
#11 [internal function]: Drupal\commerce_product\ProductLazyBuilders->addToCartForm('3', 'default', false, 'en')
#12 /code/web/core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php(113): call_user_func_array(Array, Array)
#13 /code/web/core/lib/Drupal/Core/Render/Renderer.php(870): Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #lazy_bu...', 'exception', 'Drupal\\Core\\Ren...')
#14 /code/web/core/lib/Drupal/Core/Render/Renderer.php(411): Drupal\Core\Render\Renderer->doCallback('#lazy_builder', 'commerce_produc...', Array)
#15 /code/web/core/lib/Drupal/Core/Render/Renderer.php(504): Drupal\Core\Render\Renderer->doRender(Array)
#16 /code/web/core/lib/Drupal/Core/Render/Renderer.php(248): Drupal\Core\Render\Renderer->doRender(Array, false)
#17 /code/web/core/lib/Drupal/Core/Template/TwigExtension.php(475): Drupal\Core\Render\Renderer->render(Array)
#18 /code/vendor/twig/twig/src/Environment.php(391) : eval()'d code(73): Drupal\Core\Template\TwigExtension->escapeFilter(Object(Drupal\Core\Template\TwigEnvironment), Array, 'html', NULL, true)
#19 /code/vendor/twig/twig/src/Template.php(393): __TwigTemplate_f7aa37fa2a80aee1994e3f130de003a8->doDisplay(Array, Array)
#20 /code/vendor/twig/twig/src/Template.php(349): Twig\Template->yield(Array, Array)
#21 /code/vendor/twig/twig/src/Template.php(364): Twig\Template->display(Array)
#22 /code/vendor/twig/twig/src/TemplateWrapper.php(35): Twig\Template->render(Array)
#23 /code/web/core/themes/engines/twig/twig.engine(33): Twig\TemplateWrapper->render(Array)
#24 /code/web/core/lib/Drupal/Core/Theme/ThemeManager.php(348): twig_render_template('core/themes/oli...', Array)
#25 /code/web/core/lib/Drupal/Core/Render/Renderer.php(491): Drupal\Core\Theme\ThemeManager->render('field', Array)
#26 /code/web/core/lib/Drupal/Core/Render/Renderer.php(504): Drupal\Core\Render\Renderer->doRender(Array)
#27 /code/web/core/lib/Drupal/Core/Render/Renderer.php(248): Drupal\Core\Render\Renderer->doRender(Array, false)
#28 /code/web/core/lib/Drupal/Core/Template/TwigExtension.php(475): Drupal\Core\Render\Renderer->render(Array)
#29 /code/vendor/twig/twig/src/Environment.php(391) : eval()'d code(100): Drupal\Core\Template\TwigExtension->escapeFilter(Object(Drupal\Core\Template\TwigEnvironment), Array, 'html', NULL, true)
#30 /code/vendor/twig/twig/src/Template.php(437): __TwigTemplate_b82426ff6a05058c34e979e87df5fc5e->block_content(Array, Array)
#31 /code/vendor/twig/twig/src/Environment.php(391) : eval()'d code(79): Twig\Template->yieldBlock('content', Array, Array)
#32 /code/vendor/twig/twig/src/Template.php(393): __TwigTemplate_b82426ff6a05058c34e979e87df5fc5e->doDisplay(Array, Array)
#33 /code/vendor/twig/twig/src/Template.php(349): Twig\Template->yield(Array, Array)
#34 /code/vendor/twig/twig/src/Template.php(364): Twig\Template->display(Array)
#35 /code/vendor/twig/twig/src/TemplateWrapper.php(35): Twig\Template->render(Array)
#36 /code/web/core/themes/engines/twig/twig.engine(33): Twig\TemplateWrapper->render(Array)
#37 /code/web/core/lib/Drupal/Core/Theme/ThemeManager.php(348): twig_render_template('core/themes/oli...', Array)
#38 /code/web/core/lib/Drupal/Core/Render/Renderer.php(491): Drupal\Core\Theme\ThemeManager->render('block', Array)
#39 /code/web/core/lib/Drupal/Core/Render/Renderer.php(504): Drupal\Core\Render\Renderer->doRender(Array)
#40 /code/web/core/lib/Drupal/Core/Render/Renderer.php(248): Drupal\Core\Render\Renderer->doRender(Array, false)
#41 /code/web/core/lib/Drupal/Core/Template/TwigExtension.php(475): Drupal\Core\Render\Renderer->render(Array)
#42 /code/vendor/twig/twig/src/Environment.php(391) : eval()'d code(89): Drupal\Core\Template\TwigExtension->escapeFilter(Object(Drupal\Core\Template\TwigEnvironment), Array, 'html', NULL, true)
#43 /code/vendor/twig/twig/src/Template.php(393): __TwigTemplate_fb0734ebc5b0bd8a946d2f03b8013842->doDisplay(Array, Array)
#44 /code/vendor/twig/twig/src/Template.php(349): Twig\Template->yield(Array, Array)
#45 /code/vendor/twig/twig/src/Template.php(364): Twig\Template->display(Array)
#46 /code/vendor/twig/twig/src/TemplateWrapper.php(35): Twig\Template->render(Array)
#47 /code/web/core/themes/engines/twig/twig.engine(33): Twig\TemplateWrapper->render(Array)
#48 /code/web/core/lib/Drupal/Core/Theme/ThemeManager.php(348): twig_render_template('modules/contrib...', Array)
#49 /code/web/core/lib/Drupal/Core/Render/Renderer.php(491): Drupal\Core\Theme\ThemeManager->render('ds_2col_stacked', Array)
#50 /code/web/core/lib/Drupal/Core/Render/Renderer.php(504): Drupal\Core\Render\Renderer->doRender(Array)
#51 /code/web/core/lib/Drupal/Core/Render/Renderer.php(504): Drupal\Core\Render\Renderer->doRender(Array)
#52 /code/web/core/lib/Drupal/Core/Render/Renderer.php(248): Drupal\Core\Render\Renderer->doRender(Array, false)
#53 /code/web/core/lib/Drupal/Core/Template/TwigExtension.php(475): Drupal\Core\Render\Renderer->render(Array)
#54 /code/vendor/twig/twig/src/Environment.php(391) : eval()'d code(55): Drupal\Core\Template\TwigExtension->escapeFilter(Object(Drupal\Core\Template\TwigEnvironment), Array, 'html', NULL, true)
#55 /code/vendor/twig/twig/src/Template.php(393): __TwigTemplate_6583f21026a46850e10c4667508146f1->doDisplay(Array, Array)
#56 /code/vendor/twig/twig/src/Template.php(349): Twig\Template->yield(Array, Array)
#57 /code/vendor/twig/twig/src/Template.php(364): Twig\Template->display(Array)
#58 /code/vendor/twig/twig/src/TemplateWrapper.php(35): Twig\Template->render(Array)
#59 /code/web/core/themes/engines/twig/twig.engine(33): Twig\TemplateWrapper->render(Array)
#60 /code/web/core/lib/Drupal/Core/Theme/ThemeManager.php(348): twig_render_template('modules/contrib...', Array)
#61 /code/web/core/lib/Drupal/Core/Render/Renderer.php(491): Drupal\Core\Theme\ThemeManager->render('commerce_produc...', Array)
#62 /code/web/core/lib/Drupal/Core/Render/Renderer.php(248): Drupal\Core\Render\Renderer->doRender(Array, false)
#63 /code/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(238): Drupal\Core\Render\Renderer->render(Array, false)
#64 /code/web/core/lib/Drupal/Core/Render/Renderer.php(638): Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}()
#65 /code/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(231): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#66 /code/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(128): Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\CurrentRouteMatch))
#67 /code/web/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php(90): Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\CurrentRouteMatch))
#68 [internal function]: Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object(Symfony\Component\HttpKernel\Event\ViewEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#69 /code/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\ViewEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#70 /code/vendor/symfony/http-kernel/HttpKernel.php(186): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Symfony\Component\HttpKernel\Event\ViewEvent), 'kernel.view')
#71 /code/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#72 /code/web/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#73 /code/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#74 /code/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#75 /code/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#76 /code/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#77 /code/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#78 /code/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#79 /code/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#80 /code/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#81 /code/web/core/lib/Drupal/Core/DrupalKernel.php(741): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#82 /code/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#83 {main}
🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇵🇰Pakistan Qaiser iqbal

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

Merge Requests

Comments & Activities

  • Issue created by @Qaiser iqbal
  • 🇮🇹Italy roberto.musa

    It is not a complete solution but it allows you to bypass error since it is not in the getTimeStamp() usage but it is the extendedDateTime that is set to NULL

    File: /modules/commerce_license/src/EventSubscriber/LicenseRenewalCartEventSubscriber.php line 123

    - '@extended-date' => $this->dateFormatter->format($extendedDatetime->getTimestamp()),
    + '@extended-date' => ($extendedDatetime == NULL) ? 0 : $this->dateFormatter->format($extendedDatetime->getTimestamp()),

  • 🇮🇱Israel jsacksick

    Seems the problem is $extendedDateTime which can be returned as an int... Let's see if the attached patch helps.

  • thank you for the patch. fixes the use for me!

  • 🇮🇱Israel jsacksick

    but had License Expiration=unlimited

    yeah that indeed explains it.

  • right now, I am running a test with rolling intervall of 2 minutes.
    but the license stays active as the 2 minutes went by...

  • 🇮🇱Israel jsacksick

    @nojj: How is this related to that? That sounds like a cron problem? Do you have cron setup correctly? Licenses don't magically expire.

  • @jsacksick: just wanted to help testing the patch.
    I did run cron manual and noticed that the license is still active for the first time, as normally we use only unlimited licenses.

  • First commit to issue fork.
  • 🇺🇸United States TomTech

    We actually shouldn't even get to this code path, as an existing license that is unlimited should not return TRUE for canRenew().

    MR incoming that cleans up a few details in the logic.

    • fd7fd8d5 committed on 3.0.x
      Issue #3482013 by jsacksick, tomtech, nojj, qaiser iqbal, roberto.musa:...
  • 🇺🇸United States TomTech

    Presuming this is using a license type other than the built-in role license, as that license implements ExistingRightsFromConfigurationCheckingInterface, which precludes this scenario.

    This also does not occur if the product variation type does not enable renewals.

    With this change, this error should no longer occur when a customer attempts to add a product that does NOT implement ExistingRightsFromConfigurationCheckingInterface, that is a product variation type that enabled renewals, and the customer has an existing license. They should now properly receive a message that they already have the license, and prevent it from being added to the cart.

Production build 0.71.5 2024