Move confirmation JavaScript into a separately callable helper function

Created on 24 September 2024, 7 months ago

Problem/Motivation

Currently all the code in commerce_add_to_cart_confirmation.js is one block, which makes it impossible to use it from outside in special cases.

In our case we have a headless Vue configurator and after adding an item to cart via commerce_api we need to check for the add to cart confirmation.

Calling Drupal.behaviors.commerce_add_to_cart_confirmation.attach(document) from outside is

  • a bit dirty
  • not working due to the once() check

So it would be great, if the inner functionality to check for the confirmation contents and display it, could be moved into a separate function that can also be called from outside.

That should just separate the code parts a bit, but shouldn't have any drawbacks.

I'll prepare a MR and would be grateful if it could be accepted.
Maybe there are similar cases in the future for other users.

PS: Of course we're willing to share our implementation for a Drupal AJAX command to check for Add to cart confirmations and show them even after the page has been loaded using AJAX. Just ping us.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Active

Version

1.0

Component

Code

Created by

🇩🇪Germany Anybody Porta Westfalica

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024