Magento 2 : Change email content based on shipping method in email template - magento2

I need to change the email content based on shipping method. there are two type of shipping method one is in store pickup and one is delivery to user location.
For both case content of email template is like :
Thank you for your order from XYZ. Once your package ships we will send you a tracking number. You can check the status of your order by logging into your account.
I don't want this line "Once your package ships we will send you a tracking number." for in store pickup and change this line with some other info.
My Email template sample like :
{{template config_path="design/email/header_template"}}
<table>
<tr class="email-intro">
<td>
<p class="greeting">{{trans "%customer_name," customer_name=$order_data.customer_name}}</p>
<p>
{{trans "Thank you for your order from %store_name." store_name=$store.frontend_name}}
{{trans "Once your package ships we will send you a tracking number."}}
{{trans 'You can check the status of your order by logging into your account.' account_url=$this.getUrl($store,'customer/account/',[_nosid:1]) |raw}}
</p>
<p>
{{trans 'If you have questions about your order, you can email us at %store_email' store_email=$store_email |raw}}{{depend store_phone}} {{trans 'or call us at %store_phone' store_phone=$store_phone |raw}}{{/depend}}.
{{depend store_hours}}
{{trans 'Our hours are <span class="no-link">%store_hours</span>.' store_hours=$store_hours |raw}}
{{/depend}}
</p>
</td>
</tr>
<tr class="email-summary">
<td>
<h1>{{trans 'Your Order <span class="no-link">#%increment_id</span>' increment_id=$order.increment_id |raw}}</h1>
<p>{{trans 'Placed on <span class="no-link">%created_at</span>' created_at=$created_at_formatted |raw}}</p>
</td>
</tr>
<tr class="email-information">
<td>
{{depend order_data.email_customer_note}}
<table class="message-info">
<tr>
<td>
{{var order_data.email_customer_note|escape|nl2br}}
</td>
</tr>
</table>
{{/depend}}
<table class="order-details">
<tr>
<td class="address-details">
<h3>{{trans "Billing Info"}}</h3>
<p>{{var formattedBillingAddress|raw}}</p>
</td>
{{depend order_data.is_not_virtual}}
<td class="address-details">
<h3>{{trans "Shipping Info"}}</h3>
<p>{{var formattedShippingAddress|raw}}</p>
</td>
{{/depend}}
</tr>
<tr>
<td class="method-info">
<h3>{{trans "Payment Method"}}</h3>
{{var payment_html|raw}}
</td>
{{depend order_data.is_not_virtual}}
<td class="method-info">
<h3>{{trans "Shipping Method"}}</h3>
<p>{{var order.shipping_description}}</p>
{{if shipping_msg}}
<p>{{var shipping_msg}}</p>
{{/if}}
</td>
{{/depend}}
</tr>
</table>
{{layout handle="sales_email_order_items" order_id=$order_id area="frontend"}}
</td>
</tr>
</table>
{{template config_path="design/email/footer_template"}}
I see the email for In store Pickup {{var order.shipping_description}} value is like "In-Store Pickup Delivery - "
And For Second One Value is like "Flat Rate - Fixed".
Please help like which condition i need to put for the content changes.
Thanks

You can achieve this by adding your logic to an observer.
Create basic module
registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Vendor_Module',
__DIR__
);
module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vendor_Module" setup_version="1.0.0"/>
</config>
Register an observer for when email templates are loaded
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="email_order_set_template_vars_before">
<observer name="name_of_observer" instance="Vendor\Module\Observer\AddVariable" />
</event>
</config>
In your Observer app\code\Vendor\Module\Observer\AddVariable.php
<?php
namespace Vendor\Module\Observer;
use Magento\Sales\Model\Order;
use Magento\Framework\Event\ObserverInterface;
class AddVariable implements ObserverInterface
{
protected $order;
public function __construct(
Order $order
) {
$this->order= $order;
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
/** #var \Magento\Framework\App\Action\Action $controller */
$transport = $observer->getEvent()->getTransport();
if($transport->getOrder() != null)
{
$order = $this->order->load($transport->getOrder()->getId());
$shipping_method = $order->getShippingAddress()->getShippingMethod();
$transport['variable'] = /*some logic ... */
}
}
}
$transport['variable'] adds the variable to your data. You can call it like any other variable from your template and assign as many as you like.

Related

Clear the filled data of form in Phalcon Framework

I am new to phalcon and trying to learn this framework. I have created a simple form. Now, When I fill up the form, I am able to store the data in database. After submitting the form I want to be on the same page. Now the issue is, form is still have the filled data it is not clearing up. I have googled and found the clear() method to clear the form data but it seems that its not working. What to do?
Here is my code
//Controller
use Phalcon\Mvc\Controller;
class ProfileController extends Controller
{
public function indexAction()
{
// Add some local CSS resources
$this->assets->addCss("css/styles.css");
$this->assets->addCss("css/bootstrap.min.css");
// And some local JavaScript resources
$this->assets->addJs("js/jquery.js");
$this->assets->addJs("js/bootstrap.min.js");
}
public function createAction(){
//create object of model class
$profile = new Tbl_profile();
$profile->fname= $this->request->getPost('firstname');
$profile->lname= $this->request->getPost('lastname');
$profile->email= $this->request->getPost('email');
$success=$profile->save();
if($success) {
$this->flash->success("Profile created!");
//redirect to same page.
$this->dispatcher->forward(['action' => 'index']);
}else {
}
}
}
//views
<html>
<head>
<title>Title</title>
<?php $this->assets->outputCss(); ?>
</head>
<body>
<h4 class="ml-5 mt-2"> Create Profile</h4>
<?php echo $this->getContent(); ?>
<?php echo $this->tag->form("profile/create") ?>
<table class="table">
<tbody>
<tr scope="row">
<td>First Name</td>
<td><?php echo $this->tag->textField("firstname"); ?></td>
</tr>
<tr scope="row">
<td>Last Name</td>
<td><?php echo $this->tag->textField("lastname"); ?></td>
</tr>
<tr scope="row">
<td>Email</td>
<td><?php echo $this->tag->textField("email"); ?></td>
</tr>
<tr scope="row">
<td></td>
<td><?php echo $this->tag->submitButton("Create");?></td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
Once you save the data to database, redirect to the controller instead of forwarding the request because forwarding the request won't reload the page.
$this->request->redirect('profile/index');
Read this what's the difference between redirect and dispatch in phalcon? for more information
You must create form class to have ability using $form->clear() method.
See the doc https://docs.phalconphp.com/cs/3.4/forms

Why Does My FAMILY Query Fail?

Please have a look at the following code wherein I have a method that searches by family name and another that searches by system. Following the code I have provided the results that were produced by invoking each of these two methods. You can see that the system search returned three patients, the third one having the family name Vaessen. But, when I search for the family name Vaessen a timeout results. Would someone please help me to understand why this is happening?
Note: As you can see from the timeout exception, I am querying the public fhir server http://fhirtest.uhn.ca/baseDstu3
public void findPatientsInFamily(String family) {
System.out.printf("\n\nFinding patients in family %s\n", family);
findPatients(Patient.FAMILY.matches().value(family));
}
public void findPatientsInSystem(String system) {
System.out.printf("\n\nFinding patients in system %s\n", system);
findPatients(Patient.IDENTIFIER.hasSystemWithAnyCode(system));
}
#SuppressWarnings("rawtypes")
public void findPatients(ICriterion criterion) {
try {
Bundle bundle = client.search().forResource(Patient.class).where(criterion).returnBundle(Bundle.class).execute();
for (BundleEntryComponent entry : bundle.getEntry()) {
if (entry.getResource().getResourceType() == ResourceType.Patient) {
Patient patient = (Patient) entry.getResource();
System.out.printf("%s\n", parser.encodeResourceToString(patient));
}
}
}
catch(Exception e) {
System.out.printf("Cannot find patients\n%s\n", e.getMessage());
}
}
Results for the findPatientsInSystem(String system) method:
Finding patients in system http://dmw.levy.com/mrn
<Patient xmlns="http://hl7.org/fhir">
<id value="4172808"></id>
<meta>
<versionId value="1"></versionId>
<lastUpdated value="2018-06-07T14:10:52.336+00:00"></lastUpdated>
</meta>
<text>
<status value="generated"></status>
<div xmlns="http://www.w3.org/1999/xhtml">
<div class="hapiHeaderText">Rachael
<b>LANEHART </b>
</div>
<table class="hapiPropertyTable">
<tbody>
<tr>
<td>Identifier</td>
<td>12345</td>
</tr>
<tr>
<td>Date of birth</td>
<td>
<span>30 December 1985</span>
</td>
</tr>
</tbody>
</table>
</div>
</text>
<identifier>
<system value="http://dmw.levy.com/mrn"></system>
<value value="12345"></value>
</identifier>
<name>
<family value="Lanehart"></family>
<given value="Rachael"></given>
</name>
<gender value="female"></gender>
<birthDate value="1985-12-30"></birthDate>
</Patient>
<Patient xmlns="http://hl7.org/fhir">
<id value="4149602"></id>
<meta>
<versionId value="1"></versionId>
<lastUpdated value="2018-06-06T20:52:11.831+00:00"></lastUpdated>
</meta>
<text>
<status value="generated"></status>
<div xmlns="http://www.w3.org/1999/xhtml">
<div class="hapiHeaderText">Ravi
<b>THAKKAR </b>
</div>
<table class="hapiPropertyTable">
<tbody>
<tr>
<td>Identifier</td>
<td>12345</td>
</tr>
<tr>
<td>Date of birth</td>
<td>
<span>14 April 1962</span>
</td>
</tr>
</tbody>
</table>
</div>
</text>
<identifier>
<system value="http://dmw.levy.com/mrn"></system>
<value value="12345"></value>
</identifier>
<name>
<family value="Thakkar"></family>
<given value="Ravi"></given>
</name>
<gender value="male"></gender>
<birthDate value="1962-04-14"></birthDate>
</Patient>
<Patient xmlns="http://hl7.org/fhir">
<id value="4013201"></id>
<meta>
<versionId value="1"></versionId>
<lastUpdated value="2018-06-01T18:30:23.902+00:00"></lastUpdated>
</meta>
<text>
<status value="generated"></status>
<div xmlns="http://www.w3.org/1999/xhtml">
<div class="hapiHeaderText">Robert Jozef
<b>VAESSEN </b>
</div>
<table class="hapiPropertyTable">
<tbody>
<tr>
<td>Identifier</td>
<td>12345</td>
</tr>
<tr>
<td>Date of birth</td>
<td>
<span>30 January 1954</span>
</td>
</tr>
</tbody>
</table>
</div>
</text>
<identifier>
<system value="http://dmw.levy.com/mrn"></system>
<value value="12345"></value>
</identifier>
<name>
<family value="Vaessen"></family>
<given value="Robert"></given>
<given value="Jozef"></given>
</name>
<gender value="male"></gender>
<birthDate value="1954-01-30"></birthDate>
</Patient>
Results for the findPatientsInFamily(String family) method:
Finding patients in family Vaessen
Cannot find patients
Failed to parse response from server when performing GET to URL http://fhirtest.uhn.ca/baseDstu3/Patient?family=Vaessen - java.net.SocketTimeoutException: Read timed out
The way in which your code queries the FHIR Server should be fine for a Patient search by system or family name.
I tried the public test server through the UI at http://fhirtest.uhn.ca/ and everything appears to be down currently. Every request returns an error. There is already an issue posted here on GIT https://github.com/jamesagnew/hapi-fhir/issues/998.
It is also possible that when the server is back up, there may be so much patient data that your request will still error unless a large connection timeout is set, or more filter criteria is provided.

Footable table timeout when row count is over 1000

I have tried to implement footable pluglin on an MVC application and it currently has 3000+ users which fail to load and the browser page times out. For the User Admin section I have created the following View:
#model IEnumerable<MyBudgetWeb.Models.ApplicationUser>
#{
ViewBag.Title = "Index";
}
<script src="~/Scripts/jquery-1.10.2.js"></script>
<script type="text/javascript">
$(function () {
$('.footable').footable();
});
</script>
<br /><br />
<h2>Bill Pay Users</h2>
<input id="filter" type="text" placeholder="Filter" />
<br /><br />
#if (Model.Count() > 0)
{
<table class="table" data-filter="#filter" data-page-size="50">
<thead>
<tr>
<th data-type="numeric">Customer Number</th>
<th data-type="numeric">Account Name</th>
<th data-type="numeric" data-hide="phone">Go Live Date</th>
<th data-type="numeric" data-hide="phone">Online Live Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
#foreach (var item in Model)
{
<tr>
<td>#item.CustomerNumber</td>
<td>#item.AccountName</td>
<td>#item.GoLiveDate</td>
<td>#item.OnlineCreationTimestamp</td>
<td>
#Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
#Html.ActionLink("Details", "Details", new { id = item.Id }) |
#*#Html.ActionLink("Delete", "Delete", new { id = item.Id })*#
</td>
</tr>
}
</tbody>
<tfoot class="hide-if-no-paging">
<tr>
<td colspan="12" class="text-center">
<ul class="pagination"></ul>
</td>
</tr>
</tfoot>
</table>
}
else
{
<h2>You are still awaiting users to be added. All users will be displayed here.</h2>
}
My controller looks as follows:
public async Task<ActionResult> Index()
{
return View(await UserManager.Users.ToListAsync());
}
Is there any way workarounds to prevent this?
there are 2 option to solve:
1. PHP Side script, by setting the time limit of execution. Use this code on top your PHP script:
set_time_limit(0);
Use Footable AJAX what describe here:
http://fooplugins.github.io/FooTable/

Selenium Webdriver_Not able to click on link given into column

I'm a beginner and I'm trying to write a Selenium web driver. I'm using eclipse and trying to locate a link available in next column. In each row I have different link. For example in my employee data table I have 2 columns and 10 rows in one page. The first column contains the name of person and second column contains its employee ID (ID is a hyperlink). I'm trying to select the hyperlink of any employee but I'm not able to do it.
I have below the HTML code and sample script.
<span id="37">
<div class="clear"></div>
<div id="FC_Schema.1021.WIP" type="DataCheckingList" name="FC_Schema.1021.WIP">
<input id="baseurl" type="hidden" value="/Web/" name="baseurl">
<input id="hdnDcCnt" type="hidden" value="13" name="hdnDcCnt">
<input id="PageNo" type="hidden" value="1" name="PageNo">
<meta content="width=device-width" name="viewport">
<style type="text/css">
<div id="DataCheckingLoad">
<div id="SupplyChainTabs">
<div id="gbo" class="InnerAlertsTabs">
<table id="one" class="draggable" width="100%">
<thead>
<tbody>
<tr>
<td valign="top" align="center">
<td valign="top">
<td valign="top">
<a onclick="return ButtonClick(this,'TxnyD.Communities.2.1','Org.2000476_Product.THQS|SMS|Questionnaire.WIP_Questionnaire_TxnyD.Communities.2.1_THQS_TxnyD.Operationaloffice.1.2');" href="#f">Axiom
Process LLC</a>
<div class="country-name">
<div class="CompanyInfoContactLinks">
</td>
<td valign="top">
THQS
<div class="clear"> </div>
<a id="Org.2000476_Product.THQS|SMS|Questionnaire.WIP_Questionnaire_TxnyD.Communities.2.1_THQS_TxnyD.Operationaloffice.1.2" onclick="RedirectToQuestionnairePage(id)" href="#">THQS</a>
<div class="clear"> </div>
</td>
In the above code first column contains company name i.e "Axiom
Process LLC" and second column contains company subcription name i.e."THQS". I have to select the THQS link of company "Axiom Process LLC"
Selenium script designed for it as below
public static void main(String[] args) throws Exception {
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://XXX.XXX.XXX.XXX/Web");
Thread.sleep(1000);
driver.findElement(By.xpath("//input[#id='UserName']")).sendKeys("Gbouser.1");
driver.findElement(By.xpath("//input[#id='Password']")).sendKeys("****");
driver.findElement(By.xpath("//input[#name='Login']")).click();
driver.findElement(By.xpath("//a[contains(text(),'Task')]")).click();
driver.findElement(By.xpath("//a[contains(text(),'Data Checking')]")).click();
driver.findElement(By.partialLinkText("Axiom")).findElement(By.xpath("//a[contains(text(),'THQS')]")).click();
}
So basically these are dynamic tables and each time it will have different records. How can select the link available in column?
I also tried below script as well:
driver.findElement(By.name("*[id^='CLS'][id$='Demolition Limited']")).findElement(By.xpath("//a[contains(text(),'THQS')])[3]")).click();
welcome to Stackoverflow. Before answering your question, just a few pointers. Think that you had a downvote 'cause you didn't format your question well. Otherwise a perfectly legal question, and you would receive help much earlier.
Secondly, don't ever put the real Web site address, username and password :). I was able to login, and understand exactly what you need, but a malicious guy could do bad wonders there.
To answer your question, instead of the line that is causing you problems, try this
Thread.sleep(3000);
TablePageObject tablePageObject = PageFactory.initElements(driver, TablePageObject.class);
tablePageObject.clickLink("Axiom");
Where TablePageObject is
public class TablePageObject {
private WebDriver driver;
#FindBy(css = "table tr")
private List<WebElement> allTableRows; // find all the rows of the table
public TablePageObject(WebDriver driver) {
this.driver = driver;
}
public void clickLink(String companyName) {
for(WebElement row : allTableRows) {
List<WebElement> links = row.findElements(By.cssSelector("a"));
// the first link by row is the company name, the second is link to be clicked
if (links.get(0).getText().contains(companyName)) {
links.get(3).click();
}
}
}
}
An explanation, TablePageObject class will be your programmatic handle for the dynamic table you're trying to control. It follows a page factory pattern of selenium, which I heartly recommend, and you can learn more here https://code.google.com/p/selenium/wiki/PageFactory
It basically keeps a collection of rows of your table, which more or less looks like:
<tr>
<td valign="top" align="center">
// irelevant
</td>
<td valign="top">
// irelevant
</td>
<td valign="top">
<a>Axiom Process LLC</a>
<a>company details</a>
<a>web details</a>
</td>
<td valign="top">
<a>THQS</a>
</td>
<td valign="top" align="center" style="display: none">
// irelevant
</td>
<td valign="top">
//irelevant
</td>
<td valign="top">
// irelevant
</td>
<td valign="top">
</td>
<td>
</td>
</tr>
You collect all the links from the table, check the company name against the first link, and if matched, click the fourth link,
Hope it helps, best,
by the way, I've masked your password in the question

diacritic in jsp form

we have problem with diacritic in jsp form in school project. We use Spring 3.0. In JSP form we have inputs which can contains words with diacritic (czech language,f.e "šáříěá"). When I start project and write diacritic words into these inputs and send form, immediately in controller are wrong values. Diacritic letters has strange form, for example "Ä???Ä".
Following code is our form.
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%#taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Nový prostor</title>
</head>
<body>
<h1>Nový prostor</h1>
<form:form method="POST" commandName="PLACE" >
<fieldset>
<legend>Adresa prostoru</legend>
<table>
<tr>
<td><form:label path="name">Název prostoru</form:label></td>
<td><form:input path="name" /></td>
</tr>
<tr>
<td><form:label path="street">Ulice a č.p.</form:label></td>
<td><form:input path="street" /></td>
</tr>
<tr>
<td><form:label path="zip_code">PSČ</form:label></td>
<td><form:input path="zip_code" /></td>
</tr>
<tr>
<td><form:label path="city">Město</form:label></td>
<td><form:input path="city" /></td>
</tr>
</table>
</fieldset>
<fieldset>
<legend>Parametry prostoru</legend>
<table>
<tr>
<td><form:label path="rows">Počet řad</form:label></td>
<td><form:input path="rows" /></td>
</tr>
<tr>
<td><form:label path="columns">Počet sedaček v řadě</form:label></td>
<td><form:input path="columns" /></td>
</tr>
<tr>
<td><form:label path="note">Poznámky</form:label></td>
<td><form:textarea path="note" /></td>
</tr>
</table>
</fieldset>
<input type="submit" value="Vytvořit">
</form:form>
</body>
And this is conroller:
#Controller
#RequestMapping("/newPlace")
public class NewPlaceController {
#Autowired
private PlaceService placeService;
/**
* Pri pozadavku typu get vrati nazev jsp ktere se ma renderovat, nabinduje Complex place do formualre
* #param model
* #return
*/
#RequestMapping(method=RequestMethod.GET)
public String showNewPlaceForm(Model model){
model.addAttribute("PLACE", new ComplexPlace());
return "newPlaceForm";
}
/**
*Pri pozadavku POST ulozi data z formulare do DB
*
* #param place
* #param result
* #return
*/
#RequestMapping(method=RequestMethod.POST)
public String createNewPlace(#ModelAttribute(value="PLACE") ComplexPlace place, BindingResult result){
System.out.println(place.getName());
placeService.buildPlaceService(place);
placeService.PersistNewPlace();
return "/index";
}
}
System.out.println write strange value on console. Know somebody where is problem? I want remark, that we have small expirience with Java web programming.
Thanks
you can't use any other language other then standard english.if you want to do this then u have to use any standard free unicode converter.convert your character and put their unicode character at run time it is converted in your original language...i hope it works for you.