- π¨π¦Canada joelpittet Vancouver
The only patch that seemed to have any luck with is #5 #3135550-5: "Warning: session_id(): Cannot change session id" when cron runs to delete abandoned carts β , I tried #14 and #12 and it still failed.
We are using our own custom IPN
https://github.com/ubc-cpsc/commerce_touchnet_upay/I'm going to take #5 and add one method back at time to see where it's helping.
For the record this is what our watchdog log is showing:
RuntimeException: Failed to start the session because headers have already been sent by "" at line 0. in Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage->start() (line 132 of vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php).
The
line 0 sent by ""
is super frustrating to debug... but it's reproducible (somewhat) in staging so hopefully we get to the bottom of it. - π¨π¦Canada joelpittet Vancouver
Ok I just added logging lines to that and after the
onNotify
is complete it runs:deleteCartId
addCartId
Here's are callstack and both calls are coming from
OrderEventSubscriber::finalizeCart
Which for me is anonymous userpublic function finalizeCart(OrderInterface $cart, $save_cart = TRUE) { ... // The cart is anonymous, move it to the 'completed' session. if (!$cart->getCustomerId()) { $this->cartSession->deleteCartId($cart->id(), CartSession::ACTIVE); $this->cartSession->addCartId($cart->id(), CartSession::COMPLETED); ... }
[ { "file": "modules/contrib/commerce/modules/cart/src/CartProvider.php", "line": 123, "function": "addCartId", "class": "Drupal\commerce_cart\CartSession", "object": @, "type": "->", "args": [ "47", "completed" ] }, { "file": "modules/contrib/commerce/modules/cart/src/EventSubscriber/OrderEventSubscriber.php", "line": 47, "function": "finalizeCart", "class": "Drupal\commerce_cart\CartProvider", "object": @, "type": "->", "args": [ @, false ] }, { "function": "finalizeCart", "class": "Drupal\commerce_cart\EventSubscriber\OrderEventSubscriber", "object": @, "type": "->", "args": [ @, "commerce_order.place.pre_transition", @ ] }, { "file": "core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php", "line": 111, "function": "call_user_func", "args": [ [ @, "finalizeCart" ], @, "commerce_order.place.pre_transition", @ ] }, { "file": "modules/contrib/state_machine/src/Plugin/Field/FieldType/StateItem.php", "line": 422, "function": "dispatch", "class": "Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher", "object": @, "type": "->", "args": [ @, "commerce_order.place.pre_transition" ] }, { "file": "modules/contrib/state_machine/src/Plugin/Field/FieldType/StateItem.php", "line": 380, "function": "dispatchTransitionEvent", "class": "Drupal\state_machine\Plugin\Field\FieldType\StateItem", "object": @, "type": "->", "args": [ "pre_transition" ] }, { "file": "core/lib/Drupal/Core/Field/FieldItemList.php", "line": 233, "function": "preSave", "class": "Drupal\state_machine\Plugin\Field\FieldType\StateItem", "object": @, "type": "->", "args": [] }, { "file": "core/lib/Drupal/Core/Field/FieldItemList.php", "line": 191, "function": "delegateMethod", "class": "Drupal\Core\Field\FieldItemList", "object": @, "type": "->", "args": [ "preSave" ] }, { "file": "core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php", "line": 938, "function": "preSave", "class": "Drupal\Core\Field\FieldItemList", "object": @, "type": "->", "args": [] }, { "file": "core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php", "line": 888, "function": "invokeFieldMethod", "class": "Drupal\Core\Entity\ContentEntityStorageBase", "object": @, "type": "->", "args": [ "preSave", @ ] }, { "file": "modules/contrib/commerce/src/CommerceContentEntityStorage.php", "line": 56, "function": "invokeHook", "class": "Drupal\Core\Entity\ContentEntityStorageBase", "object": @, "type": "->", "args": [ "presave", @ ] }, { "file": "modules/contrib/commerce/modules/order/src/OrderStorage.php", "line": 81, "function": "invokeHook", "class": "Drupal\commerce\CommerceContentEntityStorage", "object": @, "type": "->", "args": [ "presave", @ ] }, { "file": "core/lib/Drupal/Core/Entity/EntityStorageBase.php", "line": 529, "function": "invokeHook", "class": "Drupal\commerce_order\OrderStorage", "object": @, "type": "->", "args": [ "presave", @ ] }, { "file": "core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php", "line": 753, "function": "doPreSave", "class": "Drupal\Core\Entity\EntityStorageBase", "object": @, "type": "->", "args": [ @ ] }, { "file": "core/lib/Drupal/Core/Entity/EntityStorageBase.php", "line": 483, "function": "doPreSave", "class": "Drupal\Core\Entity\ContentEntityStorageBase", "object": @, "type": "->", "args": [ @ ] }, { "file": "core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php", "line": 806, "function": "save", "class": "Drupal\Core\Entity\EntityStorageBase", "object": @, "type": "->", "args": [ @ ] }, { "file": "modules/contrib/commerce/modules/order/src/OrderStorage.php", "line": 159, "function": "save", "class": "Drupal\Core\Entity\Sql\SqlContentEntityStorage", "object": @, "type": "->", "args": [ @ ] }, { "file": "core/lib/Drupal/Core/Entity/EntityBase.php", "line": 339, "function": "save", "class": "Drupal\commerce_order\OrderStorage", "object": @, "type": "->", "args": [ @ ] }, { "file": "modules/contrib/commerce/modules/payment/src/PaymentOrderUpdater.php", "line": 101, "function": "save", "class": "Drupal\Core\Entity\EntityBase", "object": @, "type": "->", "args": [] }, { "file": "modules/contrib/commerce/modules/payment/src/PaymentOrderUpdater.php", "line": 59, "function": "updateOrder", "class": "Drupal\commerce_payment\PaymentOrderUpdater", "object": @, "type": "->", "args": [ @, true ] }, { "file": "modules/contrib/commerce/modules/payment/src/PaymentOrderUpdater.php", "line": 112, "function": "updateOrders", "class": "Drupal\commerce_payment\PaymentOrderUpdater", "object": @, "type": "->", "args": [] }, { "file": "core/lib/Drupal/Core/EventSubscriber/KernelDestructionSubscriber.php", "line": 51, "function": "destruct", "class": "Drupal\commerce_payment\PaymentOrderUpdater", "object": @, "type": "->", "args": [] }, { "function": "onKernelTerminate", "class": "Drupal\Core\EventSubscriber\KernelDestructionSubscriber", "object": @, "type": "->", "args": [ @, "kernel.terminate", @ ] }, { "file": "core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php", "line": 111, "function": "call_user_func", "args": [ [ @, "onKernelTerminate" ], @, "kernel.terminate", @ ] }, { "file": "vendor/symfony/http-kernel/HttpKernel.php", "line": 100, "function": "dispatch", "class": "Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher", "object": @, "type": "->", "args": [ @, "kernel.terminate" ] }, { "file": "core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php", "line": 63, "function": "terminate", "class": "Symfony\Component\HttpKernel\HttpKernel", "object": @, "type": "->", "args": [ { "attributes": @, "request": @, "query": @, "server": @, "files": @, "cookies": @, "headers": @ }, { "headers": @ } ] }, { "file": "core/lib/Drupal/Core/DrupalKernel.php", "line": 688, "function": "terminate", "class": "Drupal\Core\StackMiddleware\StackedHttpKernel", "object": @, "type": "->", "args": [ { "attributes": @, "request": @, "query": @, "server": @, "files": @, "cookies": @, "headers": @ }, { "headers": @ } ] }, { "file": "index.php", "line": 22, "function": "terminate", "class": "Drupal\Core\DrupalKernel", "object": @, "type": "->", "args": [ { "attributes": @, "request": @, "query": @, "server": @, "files": @, "cookies": @, "headers": @ }, { "headers": @ } ] } ]
- π¨π¦Canada joelpittet Vancouver
Realizing now this looks like @casey's patch in #14 should solve it for us.
- last update
over 1 year ago 735 pass, 18 fail - π¨π¦Canada joelpittet Vancouver
Here's a very specific solution but hopefully that helps with the cases where this finalization step may be needed. I checked if the cart/order's payment gateway has implemented
OffsitePaymentGatewayInterface
and then compared the current request URL against the one from the gateway'sgetNotifyUrl
method, if it matches then don't mess with the session.Hopefully I didn't make any implicit dependencies on the payment in cart that weren't already there.
I was going to check if a session already started like others before were considering but what if the session needs to be started to do that for the legit user...
- π¨π¦Canada joelpittet Vancouver
I just realized I hijacked this issue for IPN as I re-read the title :( If the maintainers prefer let me know and I'll move my patch to a new issue.