Hey Ryan and all,

Unless I'm mistaken, it appears that the add to cart confirmation message ("%productname added to your cart") is a hard-coded drupal_set_message().

Instead, I'd prefer that this be set up as a default "Show a message on the site" rules action that is triggered by the "After adding a product to the cart" event.

This way, the confirmation message could be easily configurable from the UI. Furthermore, Rules conditions could used to display different custom add to cart confirmation messages depending on the particular product being added.

What do you think?

Thanks,
Ben

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Damien Tournoud’s picture

That makes sense. I'm in support.

rszrama’s picture

Issue tags: +low-hanging fruit

Agreed. This would also address a prior issue where recidive wanted to display a warning when the customer added a product to the cart that was already in the cart (a la Amazon.com). So for this, it seems like we could use an additional Cart-specific action for displaying the default "Add to Cart" message using t() in code. That should simplify things for multilingual sites. Then if someone wanted to customize the message, particularly for a single language site, they could simply remove that action and add their own "Display a message" action.

BenK’s picture

Sounds great. As soon as there is a patch for this, I'm happy to test! :-)

--Ben

rbayliss’s picture

Status: Active » Needs review
FileSize
2.72 KB

I can get used to this rules thing! Less code, more config. Had to add a token for the cart URL. Does this really not exist yet?

BenK’s picture

Status: Needs review » Reviewed & tested by the community

Just tested the patch in #4 and it is working great from a functional perspective. I was able to easily change the message via rules and was able to include various tokens in the message, too. So nice work rbayliss... I'm marking this RTBC.

--Ben

rszrama’s picture

Status: Reviewed & tested by the community » Needs work

There's one regression in this patch pertaining to multilingual usage. Because the message is no longer going through t(), it can't easily be translated. I don't believe Rules supports translating settings like these like Views does.

Additionally, we don't really need a cart URL token since we can just use [site:url]/cart instead. We're also changing our token approach through the solution being hatched to #1181534: Refactor entity handling. I'd say let's just get rid of the token... I'll have to think about the Rules based message, though. What we might need is to have an action in the Cart module that displays a generic "Add to Cart message" using t() as is (with the same TODO in the comments). This action could be used in the default Rule, but it could be easily swapped for a custom "Display a message" action.

rbayliss’s picture

Wait, is there a reason we can't do something like this inside of the hook_default_rules_configuration()?

$rule
    ->event('commerce_cart_product_add')
    ->action('drupal_message', array(
      'message' => t('@title added to <a href="@cart">your cart.</a>', array('@title' => '[product:title]', '@cart' => '[site:url]/cart')),
    ));

Pretty ugly, I know, but it seems like it'd be translatable.

rszrama’s picture

We could do that, but that will really just solve translation the first time it gets set. After that Rules stores the action settings in the database.

liupascal’s picture

Subscribing.
Any plan for this issue ? :-)

luchoh’s picture

Yes, I'd also love to see this addressed.

rszrama’s picture

Status: Needs work » Fixed

Alrighty, went ahead and wrote this at DrupalCamp Indy. It's just an action that displays the same message we have now in a default Rule reacting on the After adding a product to the cart event.

Commit: http://drupalcode.org/project/commerce.git/commitdiff/86d1f64

drupalsteve’s picture

I updated to the 2011-Nov-17 7.x-1.x-dev version of Commerce, ran update.php, and found the new action for the checkout message here: config/workflow/rules/reaction/manage/commerce_cart_add_to_cart_message

When I edit the action, "Display a translatable Add to Cart message," there is no option to change the actual text of the message. How do I actually change the message?

rszrama’s picture

You just remove that action and add your own action to display the message. : )

Status: Fixed » Closed (fixed)

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

Zac_JH’s picture

Hi

Can this issue be re-opened. Having a rule for the adding to cart message is great, but the messages for when a cart is updated or and item removed at the cart page are still hard coded, which is not so great if you need to tailor these too.

rszrama’s picture

Those other messages would be unrelated to this one; I prefer new issues to resuscitating related issues months later. That said, I'm not sure we can make those configurable like the Add to Cart message. We don't have events that correspond to carts being updated or individual cart items being deleted like we do for adding products to the cart. Some messages (like this) will just have to be customized through form alterations.

nigelw’s picture

Status: Closed (fixed) » Active

Ryan, do you mean add your own Commerce > "Display a translatable Add to Cart message" or System "Show a message on the site". If I use the former, I still do not see a way to add my own custom text.

rszrama’s picture

Status: Active » Closed (fixed)

"Show a message on the site."