I'd like to have an Action that unmarks all the nodes having a particular flag, and send the Teasers of them via email. This would be used the My bookmarks view.

I'm implementing a kind of product catalog, where the user can flag the nodes he/she interested in, and ask more info via email. The email should contain the products and the flags should be removed after sending the mail. Any suggestions?

Comments

mooffie’s picture

Status: Active » Fixed

I'd like to have an Action that unmarks all

The *proposed* Rules support has a "Trim" action, which can unmark all nodes.

(BTW, I'd hate it if a site deleted my "I'm interested in" list.)

and send the Teasers of them via email.

Use e.g. the 'insert_view' module to embed the view in a piece of text you'll then send by email. If Rules doesn't allow you to set the "Input Format" of the text, this won't work, so code this in PHP instead. (Or file a feature request against Rules.)

have an Action that unmarks all the nodes having a particular flag, and send the Teasers of them via email

You really expected to have an action that does *both*? If we wanted to provide an action for every combination of whims, we'd need to provide an infinite number of actions.

and send the Teasers of them via email

Ditto. If every module provided a "send by mail all nodes I'm conerned with", we'd end up with *lots* of actions, each having its own set of cute little bugs. That's why having a "send a view by email" functionality is better.

tian’s picture

Well, I'd not hate it if I'm doing a kind-of-shopping in this product catalog. Removing flag is necessary because the e-mail is kind of a order/inquiriy about the selected items. Next time the user will ask for information/prices about other/new products.

I'm afraid I have to code this functionality myself...

On sending emails, I'll try out insert_view module, and also viewfield seems to be worth a look, the Send module might be able to send them...

Thanks.

mooffie’s picture

Please let us know the modules/code you'll eventually use. It could be a starting point for a handbook page.

mooffie’s picture

If Rules doesn't allow you to set the "Input Format" of the text, this won't work, so code this in PHP instead.

Perhaps I was misunderstood. I meant that Rules makes it possible to use PHP to construct the body of the email. You could use a PHP snippet to embed the "all 'interested in' nodes of the current user" view.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

tian’s picture

Well, finally I had to switch do D5, but I think the solution can be easily adopted to D6 too. I created a custom module (my first one) with a new node operation in it:


function mymodule_node_operations() {
  global $user;

  $operations = array(
    'unflag_n_mail' => array(
      'label' => t('Request for quotation'),
      'callback' => 'unflag_n_mail',
    ),
  );
  return $operations;
}

function unflag_n_mail($nodes) {
  global $user;

  // loading user profile data
  $user = user_load(array('uid' => $user->uid));
  // the user to send the mail to
  $assistant = user_load(array('name' => 'assistant'));

  // mail body with personal data of the user, who is requesting for prices
  $body = "$user->profile_contact requests for quotation on the following products.\n\n" .
          "Customer data:\n=====\n\nCompany:  $user->profile_company\nE-mail:  $user->mail\n" .
          "Phone: $user->profile_phone\nAddress:\n$user->profile_address\n\n" .
          "Products:\n========\n\n";

  foreach ($nodes as $nid) {
    $node = node_load($nid);

    // I used the 'cart' flag for the quotation cart
    flag('unflag', 'cart', $nid);
    // appending product to mail body
    $body .= $node->title. "\n";
    // some logging
    watchdog('operation', t('Flags removed from node %nodetitle', array('%nodetitle' => $node->title)));
  }
  drupal_mail('mymodule', $assistant->mail , 'Request for quotation', $body, $user->mail);
}
// this last tag is not in the module, only in this post, for proper formatting

I enabled my module, then I installed the Views Bulk Operations module. I created a new view with the type of "Bulk Operations View" (for further settings see My bookmarks view), and on the Operations tab I checked my operation "Request for quotation" (D6/Views2 works slightly different, see the instructions on Bulk Operations project.)

In the view My cart I have to check all the products first to request for quotation, and press "Request for quotation" button. The nodes are unflagged and sent by mail to the assistant.

Now I'm working on having all of the products in the Quotation cart checked by default (to improve user experience).

tian’s picture

My first solution for having all the checkboxes checked is a javascript hack. This is not perfect, as one may turn it off in his browser, but better than nothing:

I put this into the header of my view (php code):

drupal_add_js("$(document).ready(function() {
  $('input[@type=checkbox]').attr('checked', 'true');
})", 'inline');