Using if else statement in Magento email subject - email

I want to use an if else statement in a Magento transaction mail. Is this possible?
In the content part it works with {{if [var]}}[text]{{/if}. Is there a way to get the same logic running the subject?

yes it should work because it goes through filter of template which process ifDirective pattern.

Related

Resend order confirmation emails for some orders in Shopware 6

Because of an error which is now fixed, our customers did not received order confirmation emails for a while.
Is there a way to resent the order emails for some orders once?
We know about the plugin, but as this is supposed be needed only once, it's kind of overkill to install, test and deploy a plugin.
Are there some code snippets or a bin/console command to accomplish this task?
Or is it even possible via the admin panel?
It is possible to define a flowbuilder flow to send order confirmation mails, but you'd to define an appropriate trigger action of course, that you can trigger yourself for the affected orders. After the oneshot command you could disable/delete the flow.
Not sure if this fits your needs...
You could write your own CLI command to re-fire the event when an order is placed.
// $this->orderRepostitory - DI service `order.repository`
// $this->orderConverter - DI service `Shopware\Core\Checkout\Cart\Order\OrderConverter`
// $this->eventDispatcher - DI service `event_dispatcher`
$criteria = new Criteria();
$criteria
->addAssociation('orderCustomer.customer')
->addAssociation('orderCustomer.salutation')
->addAssociation('deliveries.shippingMethod')
->addAssociation('deliveries.shippingOrderAddress.country')
->addAssociation('deliveries.shippingOrderAddress.countryState')
->addAssociation('transactions.paymentMethod')
->addAssociation('lineItems.cover')
->addAssociation('currency')
->addAssociation('addresses.country')
->addAssociation('addresses.countryState')
->getAssociation('transactions')->addSorting(new FieldSorting('createdAt'));
// add a filter for the orders for which no mail has been sent before
$criteria->addFilter(new RangeFilter('createdAt', [RangeFilter::LTE => (new \DateTime('2020-01-01'))->format(\DATE_ATOM)]));
$orderEntities = $this->orderRepository->search($criteria, $context->getContext())->getEntities();
foreach ($orderEntities as $orderEntity) {
$salesChannelContext = $this->orderConverter->assembleSalesChannelContext($orderEntity, Context::createDefaultContext());
$event = new CheckoutOrderPlacedEvent(
$salesChannelContext->getContext(),
$orderEntity,
$salesChannelContext->getSalesChannel()->getId()
);
$this->eventDispatcher->dispatch($event);
}
This should in theory also trigger the mails to be sent once more. Obviously try this with a test order before mass dispatching events like this. Also you should probably do this in smaller batches to avoid memory issues.

Salesforce send Email by Apex

I'm making by a requirement a code able to send an E-mail to an specific list of E-mails, due the fact that I must to include the attachments of the record I decided to use an apex class instead an e-mail alert. This object (A custom object ) must populate some fields in an email template with some of the record´s fields. I implemented the following code
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(lista);
mail.setTemplateId('00X21000000QR22');
//mail.setWhatId(idMinuta);
mail.setTargetObjectId('005d0000005NMIx');
mail.setSaveAsActivity(false);
List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
for (ContentVersion document: documents)
{
Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
efa.setFileName(document.Title);
efa.setBody(document.VersionData);
fileAttachments.add(efa);
}
mail.setFileAttachments(fileAttachments);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
I understood that to make the fields merge it´s necesary to use the WhatId method. In the related code, I have commented it because It generates an error (INVALID_ID_FIELD, WhatId is not available for sending emails to UserIds.)
My question is, if is it possible to do this with a custom object. I´m a little confuse with salesforce documentation beacuse it looks like the method supports a custom object, or maybe If I am forggeting something to include in the code.
If i keep the WhatID line commented, effectively the email is sent with the attachments and the Template but it is not populated.
I really need this kind of solution because the org have in this object at least 20 email templates, for me will be easier just to pass the Id of the template instead of makig a code with 20 different html codes for each situation
Thanks a lot
Please publish this question at Salesforce StackExcahnge https://salesforce.stackexchange.com/

Email Template AEM CQ5 foreach loop

I need to send an email that lists out product information for multiple products. Is there a way to create a email template with a foreach loop in aem? I have implemented a static email structure where I would replace the string names, for example https://adobe-consulting-services.github.io/acs-aem-commons/features/email-api.html. But I need to loop over data and I am not sure how to do that. Any information or direction on this would be helpful.
Samy,
One possible answer could be, having a server side templating. AEM does support multiple templating methods like Sightly, handlerbars etc.
Here is good doc which could help you.
http://labs.6dglobal.com/blog/2014-05-22/sightly-vs-handlebars-vs-jsp-comparing-scripting-languages/
--
Jitendra

Magento email bouncing back as no email address

I have a 'guest' checkout option on a Magento store, whenever I complete a transaction the "Order Confirmation" email that it sends out is always being returned.
Obviously the email address itself is being saved in the onepage checkout (otherwise the inline validation will display errors).
On the sales_flat_order table I can see the following columns are all NULL after an order has been placed:
customer_email,
customer_firstname,
customer_lastname
The odd thing is on the vagrant box (which should be near enough identical) the 3 columns above all have values in them when I go through the exact same process.
I cannot be sure what is happening, but in a nutshell it would seem that this customer_email for whatever reason isn't be saved to the sales_flat_order table & in turn causing this email to return as undelivered.
Can anyone point me in the right direction of where the logic is for the 'Order Confirmation' email can be found within the Magento system?
I fixed it - there was a core file that had been edited and was setting this customer email value to null...
Order.php from app/code/core/Mage/Sales/Model/ to app/code/local/Mage/Sales/Model/
And
create function getCustomerEmail() and code this function
public function getCustomerEmail() {
if(empty($this->getCustomerEmail())) {
$this->setCustomerEmail($this->getBillingAddress()->getEmail());
} else {
$this->setCustomerEmail($this->getCustomerEmail());
}
}

Drupal: How to automatically send (cck) node content + file attachment via email

I am still quite new to Drupal and have very limited programming skills.
I am trying to build a job board site using cck + views. I have created 2 related content types: a "job post" and a "job application" - both are related using a nodereference field.
The job application node has 4 fields: id of the job post to which the person is applying, email of the applicant, cover letter (body field) and attached cv (cck field that allows users to attach/upload a document).
Question: Once a job application is created I would like the content of the node (including the attached file) to be automatically sent via email to the person who posted the job (destination email address is in a cck field in the related "job post" node).
Thus my requirements are: (1) to automtically "transfer" the destination email address from the "job post" content type to the "job application" content type; and (2) to automatically send all the "job application" node contents + file attachment to the destination email.
Is there any module that can help me achieve this?
Thank you so much for your support.
My email address is: wedge.paul#gmail.com
To give it to you straight: No, there is no module that will do this. Largely because you have already made most content types and it is pretty unique to your project.
Still, you may not have limited programming skill, I would advice learning it when working with drupal. What you are asking is really not that hard to create by writing a custom module. Writing a custom module is really not that hard, and starting to write a custom module in Drupal is really well documented.
I can tell you what to use in the custom module, however it is better if you create it yourself (for future projects).
So you create your custom module:
function mymod_nodeapi{ //here all the action happens when a node is created
switch ($op) {
//if the node is inserted in the database
case 'insert':
//if node is a job application
if($node->type = "jobapplication"){
//using node_load function, you can load other nodes in a variable
$relatednode = node_load($node->nodereference);
//using drupal_mail function, you can mail people
drupal_mail();
}
break;
}
}
This code has not been tested and can't be copy pasted. However node_load and drupal_mail as well as hook_nodeapi... use those functions and you'll get there.
Lullabot's video tutorial "Learning CCK for Drupal" is based on the concept of a job application/posting site as a case study. It may be worth investigating.
no, I'm not connected in any way to Lullabot; just a fellow Drupaler