We intend to use Basic Cart module for a webshop with several suppliers. The customer can select which supplier he wants to use for delivery of the products. When an order is generated, we need to send an email to the selected supplier. This can be done via an ECA rule (https://www.drupal.org/project/eca) with the corresponding condition. But when the token [basic_cart_order:products] is used in an email created by the ECA rule to insert the cart content in the email body, it provides no value. It works fine however, when the token is used in an email notification created by the Basic Cart module itself. But for this notification the recipient cannot be defined conditionally.
I guess so far the [basic_cart_order:products] token is only available for Basic Cart module itself. Can it be made available system-wide so that other modules like ECA can use it as well?
Issue fork basic_cart-3564237
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
norman.lolI think the underlying reason for the token not being available for ECA is that at that moment the local cart got emptied already.
I think the probably most robust solution would be to introduce a token to get the products per order node ID, something like:
[basic_cart_order:123:products]Can with ECA the token be build dynamically? Like
[basic_cart_order:{{ node.id }}:products]?Then we could introduce that token.
Comment #3
norman.lolAh, since Basic Cart orders simply are nodes and the the reference field is named basic_cart_content you should in ECA or anywhere also also be able to just do this:
[node:basic_cart_content]
Can you try, please?
Comment #4
publishing future commentedThank you for your fast reply! Yes, I already tried [node:basic_cart_content], but this only returns the product titles, but not the number of items per product nor the prices.
Building the the token with ECA dynamically like [basic_cart_order:{{ node.id }}:products] is doable. I would be happy to test this.
Comment #6
norman.lolLooked into Tokens
Tokens don't accept arguments, so we can't have
[node:123:products]Tokens simply come with the current node, so we can have
[node:basic_cart_order_products]I added the
[node:basic_cart_order_products]token, please test it and please find somebody to help working on this issue if the code needs more changesComment #7
norman.lolComment #8
norman.lolAny chance you get that tested?
Comment #9
vistree commentedHi @norman.lol, thank your for your work. The patch seems to work. We get the title and count of each product within ECA.
One question: as we need to add additional product infos (custom ISBN field) to the token - can we alter the new tokens?
Comment #10
norman.lolWe could maybe provide another token that displays the product in a certain view mode if exists. And you can make that view mode display any info you need. You would need to take care of the markup yourself then, like stripping unwanted wrappers or lines breaks.
Comment #11
norman.lolComment #12
vistree commented@norman.lol - Everything works fine for me with the current MR. I were able to use the new code to create a custom extended token in a simple hook function.
So for me everythings is perfectly good. Can this be committed?
Comment #13
norman.lolI take that as RTBC. Let's get it out then.
Comment #15
norman.lolReleased. Please update the module and keep testing. Thank you
Comment #17
publishing future commentedI have been able to test the token successfully as well. Thank you for providing this improvement!