0

My content type (product) has a date field named Expired Date. All I want is like this:

check value of expired date field from content type product. If value equal to 7 days from now, send mail with list of node title and node url.

How to do this with Rules? or any suggestion modules?

1

3 Answers 3

0

Yes you could do this through rules granted the product expiration date is a field.

  1. Create a new rule to run on cron maintenance tasks

  2. Condition--> has field name

  3. Pick your field name

  4. Action--> execute custom PHP.

I don't know what your level of PHP experience is so I'll hold off on putting any code down, but the next step would be to write a short snippet of PHP that takes the sites current datetime and checks the values of your chosen field for values that are 7 days away from expiration (rules should give you tokens for both items).

  1. Then in that same custom PHP area use rules_action_mail() to send the email out with the results (for reference: https://drupal.org/node/322834).

You could also do this with a SQL query in the PHP area: http://www.barnettech.com/content/dbquery-drupal-creating-sql-queries-drupal-way . Just run through your field in the database and check for the values you need, then return the results in the mail message.

If I were to do something like this, I would implement hook_cron() in a custom module: https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_cron/7 vs. using Rules since it would require less steps.

Edit: As requested:

See here to make a Drupal 7 module: https://drupal.org/node/1074360

Using hook_cron would go something like:

function mymodule_cron(){
 myfunctions(); 
} 

function myfunctions(){
//do cool stuff
}

As far as what would go into "myfunctions", it would probably be a query on the database, returning those results, then sending those results in an email with mail(). That would be it.

2
  • Thank you for your suggestion. I will try it soon and let you know. Can you please give me an idea about using hook_cron() with this situation..? I'm interested want to use custom module.. since my php level also good. :)
    – Dieyy
    Commented Jul 16, 2013 at 20:27
  • See my edit above :-)! Commented Jul 16, 2013 at 22:01
0

yes, it's posible only with rules and one more module, first you have to calculate in days the difference betwen date fields, here the solution, then, with rules-conditional module add an if, add a condition: your diff value calculated is > than 7, send your email.

0

I've saved this(Someone's else answer I can't remember) earlier because its the best way to do publish/unpublish content based on a date feild (which you can replace it with Send Mail) using Rules and sub-module (Rules Scheduler)

After you enable them follow these steps:

  • at /admin/config/workflow/rules/components/add
  • Create a ruleset (name it "Unpublish Content")
  • In the Settings/Variables:
  • Data type = "Node"
  • Label = "node"
  • Machine name = "node"
  • Save
  • ...next screen...Add rule
  • 
Name = "Unpublish Content Rule"
  • Save Conditions:
  • Content is published
  • 
Data selector = node
  • Save
  • 
Content is of type = node
  • Value = your-content type
  • Save Actions: 
- Unpublish content
  • Data selector = node
  • Save at /admin/config/workflow/rules
  • Create a rule (name it "Unpublish Rule" 
- React on event = After saving new content
  • Save Conditions:
  • Content is of type
  • Data selector = node
  • Value = your-content-type
  • Save Actions: 
- Schedule component evaluation 
- Component Value = Unpublish Content 
- Data selector = node:field-your-node-date-field
  • Identifier value = unpublish [node:nid] 
- node Data selector = node
  • Save

Good luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.