Move confirmation JavaScript into a separately callable helper function

Created on 24 September 2024, 9 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

  • Issue created by @Anybody
  • 🇩🇪Germany Anybody Porta Westfalica

    I chose Drupal.commerce_add_to_cart_confirmation.check() as name for the method, but of course we can chose a different name. I thought it might fit best, but "showIfPresent()" or something like that might also fit!

    I didn't change any inner code or logic, just moved the code to the separate function.

  • 🇩🇪Germany Anybody Porta Westfalica

    Static patch for composer attached!

  • Pipeline finished with Success
    9 months ago
    Total: 140s
    #291564
  • Pipeline finished with Success
    9 months ago
    Total: 145s
    #291634
  • 🇩🇪Germany Anybody Porta Westfalica

    Updated static patch for the time being.

  • Pipeline finished with Success
    9 months ago
    Total: 179s
    #291986
  • 🇩🇪Germany Grevil

    LGTM! Linting pipeline fails, but it failed before (Code Quality hasn't changed).

  • 🇩🇪Germany Anybody Porta Westfalica

    Yeah no unrelated changes, see changes. Thanks for the review! Would be great to have this merged!

  • Status changed to RTBC 14 days ago
  • 🇩🇪Germany Anybody Porta Westfalica
  • 🇩🇪Germany Anybody Porta Westfalica

    Should now target 2.x - afterwards this should get merged, please.

  • Pipeline finished with Success
    14 days ago
    Total: 131s
    #506604
  • Pipeline finished with Success
    14 days ago
    Total: 130s
    #506611
  • Pipeline finished with Success
    14 days ago
    Total: 140s
    #506646
  • Pipeline finished with Canceled
    14 days ago
    Total: 80s
    #506648
  • Pipeline finished with Success
    14 days ago
    Total: 157s
    #506651
  • Pipeline finished with Success
    14 days ago
    Total: 129s
    #506654
  • 🇩🇪Germany Grevil

    Alright, that's it! Please review!

  • 🇩🇪Germany Anybody Porta Westfalica

    Thanks @grevil. Back to RTBC.

Production build 0.71.5 2024