When trying to create an order as an admin, I'm getting this error:

The website encountered an unexpected error. Please try again later.
Recoverable fatal error: Object of class Drupal\commerce_order\Entity\Order could not be converted to string in Drupal\Core\Entity\EntityStorageBase->buildCacheId() (line 131 of core/lib/Drupal/Core/Entity/EntityStorageBase.php).
Drupal\Core\Entity\EntityStorageBase->buildCacheId(Object) (Line: 171)
Drupal\Core\Entity\EntityStorageBase->getFromStaticCache(Array) (Line: 269)
Drupal\Core\Entity\EntityStorageBase->loadMultiple(Array) (Line: 250)
Drupal\Core\Entity\EntityStorageBase->load(Object) (Line: 531)
Drupal\Core\Entity\EntityBase::load(Object) (Line: 280)
Drupal\commerce_currency_resolver\CurrencyHelper->adminOrderRoutes() (Line: 265)
Drupal\commerce_currency_resolver\CurrencyHelper->isAdminOrder() (Line: 123)
Drupal\commerce_currency_resolver\CurrentCurrency->getCurrency() (Line: 76)
Drupal\commerce_currency_resolver\CurrencyOrderProcessor->process(Object) (Line: 156)
Drupal\commerce_order\OrderRefresh->refresh(Object) (Line: 127)
Drupal\commerce_order\OrderStorage->doOrderPreSave(Object) (Line: 108)
Drupal\commerce_order\OrderStorage->invokeHook('presave', Object) (Line: 492)
Drupal\Core\Entity\EntityStorageBase->doPreSave(Object) (Line: 692)
Drupal\Core\Entity\ContentEntityStorageBase->doPreSave(Object) (Line: 446)
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 838)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object) (Line: 394)
Drupal\Core\Entity\EntityBase->save() (Line: 165)
Drupal\commerce_order\Form\OrderForm->save(Array, Object)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 590)
Drupal\Core\Form\FormBuilder->processForm('commerce_order_default_edit_form', Array, Object) (Line: 319)
Drupal\Core\Form\FormBuilder->buildForm('commerce_order_default_edit_form', Object) (Line: 93)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 693)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Disabling the module gets it working.
I'm using Cookie as currency mapping, Combo Mode, and Fixer.io with two enabled currencies.
I've also disabled page_cache.

Comments

Yasser Samman created an issue. See original summary.

yassersamman’s picture

Issue summary: View changes
Deithso’s picture

Thank you @Yasser Samman,

I'm facing the same issue, creating orders as admin, disabling the module fixed it,

daveiano’s picture

Issue tags: +Needs tests
StatusFileSize
new718 bytes

I debugged this down to line 279 in CurrencyHelper.php:

if ($order_id = $this->routeMatch->getParameter('commerce_order')) {
  if ($order = Order::load($order_id)) {

getParameter already returns the loaded order, not only the order id. The patch should fix this issue, but the module still leaks test coverage for creating an order via the admin ui.

Deithso’s picture

Hello @daveiano

I just digged into the bug and found the same thing, the order_id is already a loaded order object not the id as excpected so i made a little fix,

Waiting for an update

<?php
protected function adminOrderRoutes() {
    $order_id = $this->routeMatch->getParameter('commerce_order');
    if (is_numeric($order_id)) {
      $order = Order::load($order_id);
    } else {
      $order = $order_id;
    }
   //for a reason the getTotalPrice is null 
    if (!is_null($order) && !is_null($order->getTotalPrice())) {
      return $order->getTotalPrice()->getCurrencyCode();
    }

    return NULL;
  }
?>

  • valic committed 6d1ee7c on 8.x-1.x authored by daveiano
    Issue #3099944 by daveiano: Unable to create admin order
    
yassersamman’s picture

zaporylie’s picture

Status: Active » Fixed

Marking as fixed as it has been committed and pushed to 8.x-1.x

Status: Fixed » Closed (fixed)

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