Problem/Motivation

Attempt to create a new order inside a Group results in fatal error.

Steps to reproduce

1. On clean Drupal install:
commerce_demo 2.x branch
commerceg_b2b
commerceg_b2b_order

2. Enable "default" and "physical" order types for Group
3. on the page: http://commerce.site/group/2/orders
in the block "Group operations" choose "Create default"
4. Get fatal error

Stack trace:

Error: Call to a member function toLink() on null in Drupal\commerce_order\Form\OrderForm->form() (line 115 of /var/www/html/modules/contrib/commerce/modules/order/src/Form/OrderForm.php)

#0 /var/www/html/core/lib/Drupal/Core/Entity/EntityForm.php(106): Drupal\commerce_order\Form\OrderForm->form(Array, Object(Drupal\Core\Form\FormState))
#1 [internal function]: Drupal\Core\Entity\EntityForm->buildForm(Array, Object(Drupal\Core\Form\FormState))
#2 /var/www/html/core/lib/Drupal/Core/Form/FormBuilder.php(532): call_user_func_array(Array, Array)
#3 /var/www/html/core/lib/Drupal/Core/Form/FormBuilder.php(278): Drupal\Core\Form\FormBuilder->retrieveForm('commerce_order_...', Object(Drupal\Core\Form\FormState))
#4 /var/www/html/core/lib/Drupal/Core/Entity/EntityFormBuilder.php(48): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\commerce_order\Form\OrderForm), Object(Drupal\Core\Form\FormState))
#5 /var/www/html/modules/contrib/group/src/Entity/Controller/GroupContentController.php(361): Drupal\Core\Entity\EntityFormBuilder->getForm(Object(Drupal\commerce_order\Entity\Order), 'add', Array)
#6 [internal function]: Drupal\group\Entity\Controller\GroupContentController->createForm(Object(Drupal\group\Entity\Group), 'commerceg_order...')
#7 /var/www/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#8 /var/www/html/core/lib/Drupal/Core/Render/Renderer.php(573): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#9 /var/www/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#10 /var/www/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#11 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(158): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#12 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#13 /var/www/html/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#14 /var/www/html/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#15 /var/www/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#16 /var/www/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#17 /var/www/html/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#18 /var/www/html/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#19 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#20 /var/www/html/core/lib/Drupal/Core/DrupalKernel.php(706): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#21 /var/www/html/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#22 {main}

Comments

Soul88 created an issue. See original summary.

soul88’s picture

Issue summary: View changes
krystalcode’s picture

Hi Soul88, I don't have the same setup with you but I understand you are trying to create a new order. Right now there are two ways for this:

- Through the cart/checkout process.
- Through creating an order via the Drupal UI as store admin and then associating it with a group.

The form for adding a new order is a bit more complicated as it has 2 steps and I haven't worked on it yet. Not sure when I will be able to work on it, if you are a developer I can provide directions to create an MR.

Meanwhile you can be creating orders in the standard Drupal Commerce way (not through group operations), then going to the Group/Orders page and associating it with the organization.

krystalcode’s picture

Even though looking at the code, the error thrown means that the order does not have a store associated so it may not be related with group functionality. Are you able to create orders via the default commerce UI?

soul88’s picture

Hey krystalcode, thank you for all your work on this module and for your quick response!

Yes, I'm able to create an order via usual process and then link this order to the group. I'm just not sure if this UI element should work: