Discussions

newsletter and drupal commerce

i have a problem i am using a newsletter module and when 3 products are created with commerce it sends a newsletter the problem is that i cant make the tokens to appear in the email that has beeing sent. example product-price, product image etc. i figured out that in the function drupal_mail() of the newsletter module i have to replace the $params to something so that the tokens appear.

Posted: Feb 3, 2012

Comments

frizi on February 4, 2012

I'm just curious if you are taking those tokens from the suggestions list or from somewhere else? Is there also rules module involved?
I would track back the whole process and print_r or dvm the variables to find the bug.

pit_zavra on February 4, 2012

ok here is the full story,First of all i am a newbie and i am setting up a e-shop with drupal commerce, and i am trying to send email newsletters with the newsletter module.I have my base fields in commerce product, not in product display
(i know this is not the write thing to do, but i had compatibility problems with other modules that could only see product display fields like now with newsletter module).

The default newsletter module is sending email's with drupal's node information (fields). The newsletter module ask you to input those fields with tokens.
The first problem was that i couldn't see the commerce tokens (example price sku category ect) with the help of the creator of newsletter module, i succeeded to make the commerce tokens appear, so i can choose them.

Now although i can choose them, when the email is sent, the tokens of the commerce product do not appear in the email.

So the creator of this module told me that the email doesn't know from which product to take the data, and that i must give it with the variable $params of the drupal_mail () function.

I don't think rules are involved, because newsletter module has an option to send the newsletter every time a node or more has being created (it has a text box to choose how many nodes), with a certain taxonomy term.

That's the story
Thanks for replying

frizi on February 4, 2012

So this means that you have to make a hook_mail action on your mail send function. At this you have to input the values from the fields. Question is if you have access to them? Just try to printout the hook_mail variables. Then you have to process these values from the variable array or class.
I assume that this would require some coding.

pit_zavra on February 4, 2012

"Just try to printout the hook_mail variables"

Can you pleeeease tell me how to print those variables and in which page do i have to write the code?

Is it like "print hook_mail"?

Thanks again!!

frizi on February 4, 2012

Not print the hook_mail() as a variable but call it from your custom (enabled) module (http://api.drupal.org/api/drupal/modules--system--system.api.php/functio...).

function yourModuleName_mail($key, &$message, $params) {
drupal_set_message(print_r($message,TRUE));
drupal_set_message(print_r($params,TRUE));
}

After sending any email, you should see an array with the message and params. Then you can change this $message + $params as you wish.

Sorry but I'm not going to explain how to write a module aso. Google that please.

Good luck