Hello,

Thank you for the developpement of this great module.

I have an issue when I activate "Business Rules" on a D8 Commerce Website.

When I go on a product page (whith an add to cart form), I have this error:

The website encountered an unexpected error. Please try again later.
Error: Call to undefined method Drupal\Core\Entity\ContentEntityForm::setFormId() in Drupal\commerce_product\ProductLazyBuilders->addToCartForm() (line 87 of modules/contrib/commerce/modules/product/src/ProductLazyBuilders.php).

There is another module with a similar error (https://www.drupal.org/project/form_mode_manager/issues/2907913).

The complete error:

Error : Call to undefined method Drupal\Core\Entity\ContentEntityForm::setFormId() dans Drupal\commerce_product\ProductLazyBuilders->addToCartForm() (/var/www/drupalvm/drupal/web/modules/contrib/commerce/modules/product/src/ProductLazyBuilders.php ligne 87) #0 [internal function]: Drupal\commerce_product\ProductLazyBuilders->addToCartForm('135', 'full', true, 'fr') 
#1 /var/www/drupalvm/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(358): call_user_func_array(Array, Array)
#2 /var/www/drupalvm/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, true)
#3 /var/www/drupalvm/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(151): Drupal\Core\Render\Renderer->render(Array, true)
#4 /var/www/drupalvm/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}()
#5 /var/www/drupalvm/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(152): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) 
#6 /var/www/drupalvm/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(166): Drupal\Core\Render\Renderer->renderPlain(Array) 
#7 /var/www/drupalvm/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(667): Drupal\Core\Render\Renderer->renderPlaceholder('<drupal-render-...', Array) 
#8 /var/www/drupalvm/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(552): Drupal\Core\Render\Renderer->replacePlaceholders(Array) 
#9 /var/www/drupalvm/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, true) 
#10 /var/www/drupalvm/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(139): Drupal\Core\Render\Renderer->render(Array, true) 
#11 /var/www/drupalvm/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}() 
#12 /var/www/drupalvm/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(140): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) 
#13 /var/www/drupalvm/drupal/web/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php(258): Drupal\Core\Render\Renderer->renderRoot(Array) 
#14 /var/www/drupalvm/drupal/web/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php(131): Drupal\Core\Render\HtmlResponseAttachmentsProcessor->renderPlaceholders(Object(Drupal\Core\Render\HtmlResponse)) 
#15 /var/www/drupalvm/drupal/web/core/lib/Drupal/Core/EventSubscriber/HtmlResponseSubscriber.php(45): Drupal\Core\Render\HtmlResponseAttachmentsProcessor->processAttachments(Object(Drupal\Core\Render\HtmlResponse)) 
#16 [internal function]: Drupal\Core\EventSubscriber\HtmlResponseSubscriber->onRespond(Object(Symfony\Component\HttpKernel\Event\FilterResponseEvent), 'kernel.response', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher)) 
#17 /var/www/drupalvm/drupal/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\FilterResponseEvent), 'kernel.response', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher)) 
#18 /var/www/drupalvm/drupal/vendor/symfony/http-kernel/HttpKernel.php(191): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.response', Object(Symfony\Component\HttpKernel\Event\FilterResponseEvent)) 
#19 /var/www/drupalvm/drupal/vendor/symfony/http-kernel/HttpKernel.php(173): Symfony\Component\HttpKernel\HttpKernel->filterResponse(Object(Drupal\Core\Render\HtmlResponse), Object(Symfony\Component\HttpFoundation\Request), 1) 
#20 /var/www/drupalvm/drupal/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) 
#21 /var/www/drupalvm/drupal/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#22 /var/www/drupalvm/drupal/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#23 /var/www/drupalvm/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(99): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#24 /var/www/drupalvm/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(78): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#25 /var/www/drupalvm/drupal/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#26 /var/www/drupalvm/drupal/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#27 /var/www/drupalvm/drupal/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#28 /var/www/drupalvm/drupal/web/core/lib/Drupal/Core/DrupalKernel.php(666): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#29 /var/www/drupalvm/drupal/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) 
#30 {main}.

When i disable "Business Rules", no more issue.

Any ideas ?

Best regards,

Comments

moonparade created an issue. See original summary.

pyxio’s picture

same error for me

idiaz.roncero’s picture

Same here. This makes Business_rules unusable with Commerce.

pyxio’s picture

yes, this module cannot be used on a commerce website. try rules i guess.

bandana’s picture

Same here, however it worked for some time after I had installed it. Have not been able to reproduce whatever made it work in the first place. How frustrating since this module seemed perfect to solve some features I need in combination with Commerce that currently I cannot make work with Rules either.

pyxio’s picture

Version: 8.x-1.0-beta1 » 8.x-1.x-dev
Priority: Major » Critical

this issue means business rules cannot be used on commerce sites. that is a significant issue. are there any plans to look into this?

pyxio’s picture

i tested this on a fresh installation. the page with add to cart does not crash like on my other site however the add to cart button disappears completely. if i uninstall business_rules the button displays again. i checked dblog and here is the full error on a brand new drupal 8.6.3 installation

Error: Call to undefined method Drupal\Core\Entity\ContentEntityForm::setFormId() in Drupal\commerce_product\ProductLazyBuilders->addToCartForm() (line 87 of /var/www/html/beta/web/modules/contrib/commerce/modules/product/src/ProductLazyBuilders.php) #0 [internal function]: Drupal\commerce_product\ProductLazyBuilders->addToCartForm('1', 'full', true, 'en') #1 /var/www/html/beta/web/core/lib/Drupal/Core/Render/Renderer.php(358): call_user_func_array(Array, Array) #2 /var/www/html/beta/web/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, true) #3 /var/www/html/beta/web/core/lib/Drupal/Core/Render/Renderer.php(151): Drupal\Core\Render\Renderer->render(Array, true) #4 /var/www/html/beta/web/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}() #5 /var/www/html/beta/web/core/lib/Drupal/Core/Render/Renderer.php(152): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #6 /var/www/html/beta/web/core/lib/Drupal/Core/Render/Renderer.php(166): Drupal\Core\Render\Renderer->renderPlain(Array) #7 /var/www/html/beta/web/core/modules/big_pipe/src/Render/BigPipe.php(696): Drupal\Core\Render\Renderer->renderPlaceholder('callback=commer...', Array) #8 /var/www/html/beta/web/core/modules/big_pipe/src/Render/BigPipe.php(550): Drupal\big_pipe\Render\BigPipe->renderPlaceholder('callback=commer...', Array) #9 /var/www/html/beta/web/core/modules/big_pipe/src/Render/BigPipe.php(305): Drupal\big_pipe\Render\BigPipe->sendPlaceholders(Array, Array, Object(Drupal\Core\Asset\AttachedAssets)) #10 /var/www/html/beta/web/core/modules/big_pipe/src/Render/BigPipeResponse.php(112): Drupal\big_pipe\Render\BigPipe->sendContent(Object(Drupal\big_pipe\Render\BigPipeResponse)) #11 /var/www/html/beta/vendor/symfony/http-foundation/Response.php(374): Drupal\big_pipe\Render\BigPipeResponse->sendContent() #12 /var/www/html/beta/web/index.php(20): Symfony\Component\HttpFoundation\Response->send() #13 {main}.

pyxio’s picture

perhaps this is a commerce bug and not related to business rules?

bojanz’s picture

Marked #3017380: commerce product display crashes when business_rules enabled as a duplicate.

The bug is caused by this Business Rules code:

/**
 * Implements hook_entity_type_alter().
 */
function business_rules_entity_type_alter(array &$entity_types) {
  $form_modes = \Drupal::service('entity_display.repository')
    ->getAllFormModes();
  foreach ($form_modes as $entity_type => $display_modes) {

    $type = $entity_types[$entity_type];
    foreach ($display_modes as $machine_name => $form_display) {
      if ($machine_name != 'register') {
        $default_handler_class = $type->getHandlerClasses()['form']['default'];
        $type->setFormClass($machine_name, $default_handler_class);
      }
    }
  }
}

This swaps the AddToCartForm with the generic entity form, which can't work.

pyxio’s picture

@bojanz thank you for your time and effort.

marko.romsak’s picture

Status: Active » Needs review
StatusFileSize
new863 bytes

I have done a quick fix patch just for add to cart form by adding the machine name "add_to_cart".
It works for me so it might help someone else as well.

pyxio’s picture

@marko.romsak where is the patch you made? I want to try it. thanks kevin

mrpeanut’s picture

@pyxio -- There is a link to the patch in the original post. It applied for me but did not fix the issue.

marko.romsak’s picture

@pyxio I don't know what happened with my comment and patch. The patch is in the original post, but the comment is missing.

mrpeanut’s picture

Status: Needs review » Needs work
waspper’s picture

I've refactored a bit previous patch, if needed a quick workaround. It would be nice to have a confirmation if taken approach is right.

@MrPeanut: I tried on a fresh installation, and it worked. No more issue. Did you clear cache after applying patch?

waspper’s picture

Status: Needs work » Needs review
pyxio’s picture

#16 works for me. @wassper @marko.romsak thank you guys for fixing this critical issue.

mrpeanut’s picture

@waspper I may not have. Patch from #16 applies and fixes the issue. Thanks to you and @mark.romsak!

Andy-vv’s picture

Hi guys, I am a newbie to drupal and I am not a coder. I try to build my site completely out of the box. I have hit the same "business rules vs. commerce" issue that you have described and solved with the patch. Only trouble for me is that I do not know where to insert the patch! Can someone tell me which file I need to add it into, and if possible where in the file. Many thanks for any help, this issue has blown my development up :(

c.e.a’s picture

Assigned: Unassigned » yseki
mmjvb’s picture

Status: Needs review » Reviewed & tested by the community

Due to #19 set Status to RTBC, a signal to the maintainer to adopt the patch or set back to Needs work when not 100% happy.

When accepting the patch, it should be committed and this issue should set to Fixed and remove the assignment. After two weeks it will be automatically set to Fixed (Closed). In which case it needs a maintainer to change Status and it disappears from the open issue list.

c.e.a’s picture

Assigned: yseki » Unassigned
B1’s picture

Agreed. Great module.
Drupal: 8.7.4
PHP: 7.2.18
Commerce: 8.x-2.13
Business Rules:8.x-1.x-dev

Same issue.
Applied Patch #16: worked for me.
Much appreciated @waspper.

Hope patch gets committed.

Andy-vv’s picture

I wonder if anyone in the patch world can give me a bit of advice. I'e been trying to apply the patch no.16 to the excellent business rules module. I can manage it manually and get the change to my local installation of drupal. Trouble is, my overall installation is built with composer, and so what I have done locally will not commit. I have then tried updating my composer.json with the code below. Unfortunately the patch is not being picked up. I think it's something simple but I don't have the experience to spot it!
Any ideas would be welcome!

},
"extra": {
"patchLevel": {
"drupal/core": "-p2",

"patches":{
"drupal/business_rules":{
"commerce cart patch": "https://www.drupal.org/files/issues/2019-01-23/business_rules-commerce_a..."
},
"installer-paths": {

Andy-vv’s picture

With a hint or two from folks I managed to solve my issue #25. For the benefit of any other newbies who are not great at editing composer.json files I have put an extract of mine below, with the new code in bold . I have included the blocks above and below the new code so that you can see exactly how the formatting must be made.

"scripts": {
"pre-install-cmd": [
"DrupalProject\\composer\\ScriptHandler::checkComposerVersion"
],
"pre-update-cmd": [
"DrupalProject\\composer\\ScriptHandler::checkComposerVersion"
],
"post-install-cmd": [
"DrupalProject\\composer\\ScriptHandler::createRequiredFiles"
],
"post-update-cmd": [
"DrupalProject\\composer\\ScriptHandler::createRequiredFiles"
]
},
"extra": {
"patchLevel": {
"drupal/core": "-p2"
},

"patches":{
"drupal/business_rules":{
"commerce cart patch": "https://www.drupal.org/files/issues/2019-01-23/business_rules-commerce_a..."
}
},

"installer-paths": {
"web/core": ["type:drupal-core"],
"web/libraries/{$name}": ["type:drupal-library"],
"web/modules/contrib/{$name}": ["type:drupal-module"],
"web/profiles/contrib/{$name}": ["type:drupal-profile"],
"web/themes/contrib/{$name}": ["type:drupal-theme"],
"drush/Commands/{$name}": ["type:drupal-drush"]
},

  • colan committed ccb5234 on 8.x-1.x authored by marko.romsak
    Issue #2997487 by waspper, marko.romsak: Look for "add_to_cart" as well...
colan’s picture

Priority: Critical » Normal
Status: Reviewed & tested by the community » Fixed

@pyxio: Please do not abuse the Priority system. This is not Critical as not everyone's using Commerce. Critical means that the module doesn't work at all, for anyone.

Thanks folks.

mmjvb’s picture

@C.E.A. Could you respond to #28. Consider it inappropriate, but my opinion is not relevant. What is your opinion on downgrading the priority?
And what about the reprimand to @pyxio ? Consider it inappropriate coming from @colan. Coming from you I would still consider it strong language. A simple downgrade to `Major` would be ok, considering it conflicts with Commerce. Surprised about the commit as well, wonder how that is possible. But that is off the record.

colan’s picture

rodmarasi’s picture

Chill guys. Its just a correction on the status. Both of you are contributing to this module. Dont let emotion get in the way.

mmjvb’s picture

It is not the correction of the status, that is considered normal. It is the way it was corrected. Wasn't aware of @colan taking over. Don't consider this the correct way to convey a change in policy. Of course maintainers are free to change policy. No idea how @pyxio feels about it, but I completely lost interest now.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

stuhannaford’s picture

The issue appears again when using the module Commerce Product Add-On (PADO), and so have manually updated the code on my site from:

$skip_names = ['register', 'add_to_cart'];

to

$skip_names = ['register', 'add_to_cart', 'pado_add_to_cart'];

in business_rules.module as a work around.