I am trying to create a module for magento 1.7 which will send a notification mail to admin whenever a new user subscribes to newsletter. I have succeeded so far in getting the mail sent. however, my code is not taking the getEmail and getId values to be displayed in the mail sent to admin. if anyone can throw some light on where i am going wrong, it would be great. here is the code:
app/code/local/Notify/Biju/etc/config.xml
<?xml version="1.0" encoding="utf-8"?>
<config>
<modules>
<Notify_Biju>
<version>0.1.0</version>
</Notify_Biju>
</modules>
<global>
<models>
<Notify_Biju>
<class>Notify_Biju_Model</class>
</Notify_Biju>
</models>
<template>
<email>
<newsletter_alert_template translate="label" module="n">
<label>Newsletter Alert to Admin</label>
<file>newsletter_subscription_notify.html</file>
<type>html</type>
</newsletter_alert_template>
</email>
</template>
</global>
<frontend>
<events>
<newsletter_subscriber_save_after>
<observers>
<Notify_Biju_Model_Observer>
<type>singleton</type>
<class>Notify_Biju_Model_Observer</class>
<method>newsletteralert</method>
</Notify_Biju_Model_Observer>
</observers>
</newsletter_subscriber_save_after>
</events>
</frontend>
</config>
app/code/local/Notify/Biju/Model/Observer.php
<?php
class Notify_Biju_Model_Observer {
const XML_PATH_EMAIL_TEMPLATE = 'newsletter_alert_template';
public function newsletteralert($observer){
$eventname=$observer->getEvent()->getName();
$subscriber=$observer->getEvent()->getSubscriber();
$email=$subscriber->getEmail();
$id=$subscriber->getId();
$emailtemplate=Mage::getModel('core/email_template')->loadDefault(self::XML_PATH_EMAIL_TEMPLATE);
$sender=array();
$sender['name']="admin";
$sender['email']="biju#talkingpebbles.com";
try{
$emailtemplate->sendTransactional(
self::XML_PATH_EMAIL_TEMPLATE,
$sender,
'biju#talkingpebbles.com, allen#compkraft.com', // email id of website/store admin
'admin',
array('subscirber'=>$subscriber)
);
}
catch(Mage_Core_Exception $e){
// echo $e->getMessage();
Mage::log($e->getMessage(),null,'newsletter.log');
}
}
}
app/etc/modules/Notify_Biju.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Notify_Biju>
<active>true</active>
<codePool>local</codePool>
</Notify_Biju>
</modules>
</config>
app/locale/en_US/template/email/newsletter_subscription_notify.html
<!--#subject Newsletter Subscription Alert #-->
<body style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
<div style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td valign="top" style="padding:20px 0 20px 0">
<!-- (header starts here) -->
<table bgcolor="#FFFFFF" cellspacing="0" cellpadding="10" border="0" width="650" style="border:1px solid #E0E0E0;">
<tr>
<td valign="top">
<h3 style="font-size:22px; font-weight:normal; line-height:22px; margin:0 0 11px 0;"></h3>
</td>
</tr>
<tr>
<td valign="top"><h3 style="font-size:22px; font-weight:normal; line-height:22px; margin:0 0 11px 0;">Dear Admin </h3>
<p> Congratulations! A new subscriber has registered for Newsletter. Please login to the admin back-end to manage subscriptions.</p>
<p>Subscriber Email: {{var subscriber.getEmail()}}</p>
<p>Subscriber ID: {{var subscriber.getId()}}</p>
<br>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>
You have a typo:
Search for array('subscirber'=>$subscriber).
You have "subscriber" misspelled as "subscirber"
To get the subscriber email value & id in observer,
$subscriber=$observer->getEvent()->getSubscriber() ;
$email=$subscriber->getSubscriberEmail();
$id=$subscriber->getSubscriberId();
$emailtemplate->sendTransactional(
XML_PATH_EMAIL_TEMPLATE,
Mage::getStoreConfig(XML_PATH_CONFIRM_EMAIL_IDENTITY),
'sample#xyz.in', // email id of website/store admin
'admin',
array(
'subscriber_email' => $email,
'subscriber_id' => $id
)
Then in mail - add the variables like this instead of your lines
<p>Subscriber Email: {{var subscriber_email}}</p>
<p>Subscriber ID: {{var subscriber_id}}</p>
Related
Need to save the selected radio button value into custom object.
enter image description here
`
If I select "Excellent" radio button and click submit button. Need to save Excellent value into custom object. But my code is not save the value into custom object. Below is my code and please suggest where i am doing wrong.
VF Code:
<apex:page controller="RadioBtn_table_Apex" showHeader="false" applyHtmlTag="true" applyBodyTag="false">
<style>
.fswrapper{
width:800px;
margin:0 auto;
border:3CCF4E 30px;
}
.headerTitle
{
font-family:arial,sans-serif;
font-size:16px;
font-weight:600;
color: #fff!important;
text-align:left;
text-transform:UPPERCASE;
background:#4e75a3;
Padding:10px;
display:block;
margin:0;
}
input[type=radio] {margin-left: 40px;}
.radioClass {margin-left: 5%;}
.big {line-height: 2.8;}
</style>
<apex:form styleClass="fswrapper" id="frm">
<head>
<apex:slds />
</head>
<center>
<img src="{!$Resource.ForceDotCom}"/>
</center>
<apex:pageBlock >
<h1 class="headerTitle"> Application Feedback </h1>
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Submit" action="{!savefeedback}" reRender="frm"/>
<apex:commandButton value="Exit" action="{!feedbackexit}" reRender="frm"/>
</apex:pageBlockButtons>
<apex:actionRegion >
<Table width="100%" border="0" cellpadding="0" cellspacing="0" columns="0" >
<tr >
<td colspan="5" class="fieldLabel">
<p style="font-size: 20px;">
<b> How likely are you with our Application </b>
</p>
<!--<apex:selectRadio id="selectRb" value="{!selectedAnswer}" immediate="true"> -->
<apex:selectRadio id="selectRb" value="{!ratobj.Application_Rating__c}">
<apex:selectOption value="{!items}"/>
</apex:selectRadio>
</td>
</tr>
</Table>
</apex:actionRegion>
</apex:pageBlock>
</apex:form>
</apex:page>
APEX Code :
public class RadioBtn_table_Apex
{
public RB_Rating__c ratobj{get;set;}
public string SelectedAnswer {get;set;}
public RadioBtn_table_Apex()
{
ratobj = new RB_Rating__c();
}
public pagereference savefeedback()
{
insert ratobj;
return Auth.SessionManagement.FinishLoginflow('/'+ratobj.Id);
}
public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('Excellent','Excellent'));
options.add(new SelectOption('Great','Great'));
options.add(new SelectOption('Good','Good'));
options.add(new SelectOption('Medium','Medium'));
options.add(new SelectOption('Poor','Poor'));
options.add(new SelectOption('Very Bad','Very Bad'));
return options;
}
public pagereference feedbackexit()
{
return Auth.SessionManagement.FinishLoginflow('/');
}
}
Please suggest and where i am doing wrong.
Thanks
i am trying to save my selected radio button values into custom object
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.
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.
this is div content i want to get from a web page.
<div class="result clearfix table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>Giải thưởng</th>
<th>Trùng khớp</th>
<th>Số lượng giải</th>
<th style="text-align: left; width: 22%;">Giá trị giải (đồng)</th>
</tr>
</thead>
<tbody>
<tr>
<td>Jackpot</td>
<td>Trùng 6 số</td>
<td>0</td>
<td style="text-align: left"><span>27.868.784.500</span></td>
</tr>
<tr>
<td>Giải nhất</td>
<td>Trùng 5 số</td>
<td>18</td>
<td style="text-align: left"><span>10.000.000</span></td>
</tr>
<tr>
<td>Giải nhì</td>
<td>Trùng 4 số</td>
<td>613</td>
<td style="text-align: left"><span>300.000</span></td>
</tr>
<tr>
<td>Giải ba</td>
<td>Trùng 3 số</td>
<td>11047</td>
<td style="text-align: left"><span>30.000</span></td>
</tr>
</tbody>
</table>
<p class="role-result">
<span>Thời hạn lĩnh thưởng của vé trúng thưởng: là 60 (sáu mươi) ngày, kể từ ngày xác định kết quả trúng thưởng hoặc kể từ ngày hết hạn lưu hành của vé xổ số tự chọn số điện toán (nếu có). Quá thời hạn trên, các vé trúng thưởng không còn giá trị lĩnh thưởng.</span>
</p>
<div>
<a class="view-more" href="winning-numbers">Các lần quay trước</a>
</div>
</div>
this is my code to get div content and echo to my site:
$kqxsmega = file_get_contents ("http://vietlott.vn/vi/trung-thuong/ket-qua-trung-thuong/mega-6-45/");
$dom = new DomDocument();
$dom->loadHTML($kqxsmega);
$finder = new DomXPath($dom);
$classname="result clearfix table-responsive";
$divContent = $finder->query("//*[contains(#class, '$classname')]");
My code is running good, and i want to convert $divContent become string and i can echo it.
now to echo $divContent will show nothing
echo $divContent ;
Please help me.
Thank you.
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