Magento SOAP API v2: Get currently logged in customer email address - magento

Is it possible to get the currently logged in customer's email address using the SOAP API?
I will NOT have the CustomerID.
I will be calling this from our ExpressionEngine installation.

This change in /code/core/Mage/Customer/Model/Customer/Api.php should return the currently logged in customer with all their info. I cannot currently test because I don't have SOAP installed in my PHP 5.2.14 installation.
public function info($customerId, $attributes = null)
{
// if we didn't pass a $customerId
if (!$customerId) {
// get current customer session
$custsess = Mage::getSingleton('customer/session');
// if the customer is logged in
if($custsess->isLoggedIn() == true) {
// get their ID to load below
$customerId = $custsess->getId();
unset($custsess);
}
}
$customer = Mage::getModel('customer/customer')->load($customerId);
if (!$customer->getId()) {
$this->_fault('not_exists');
}
if (!is_null($attributes) && !is_array($attributes)) {
$attributes = array($attributes);
}
$result = array();
foreach ($this->_mapAttributes as $attributeAlias=>$attributeCode) {
$result[$attributeAlias] = $customer->getData($attributeCode);
}
foreach ($this->getAllowedAttributes($customer, $attributes) as $attributeCode=>$attribute) {
$result[$attributeCode] = $customer->getData($attributeCode);
}
return $result;
}

Related

How to stay on previous page after signin in codeigniter framework

Hii guys i'm new in stackoverflow , if this question is very long please pardon me, This is a Consumer complain website here is a view page called separate_user_admin_reply2.php in this page i want to apply a functionality, If a user without login click on the replay button then Signin.php view page will appear then after login the user come back to the previous page, the previous page link is : http://localhost/A2Zcomplainboard/index.php/Complain/Separate_single_complain_user/COMP008
So what i can do ..please help me (thanks in advance)
The controller is :
public function Separate_single_complain_user($cid)
{
//$cid = $this->input->get('compid');
$this->load->model('Complain_model');
$res = $this->Complain_model->getSingleComplain($cid);
$this->load->model('Replay_Model');
$res1 = $this->Replay_Model->Separate_single_complain_replay($cid);
if($res){
$this->load->view('separate_user_admin_reply2',['res'=>$res,'res1'=>$res1]);
}
}
The model is:
public function getSingleComplain($cid)
{
$complain = $this->db->query("SELECT comp_id,comp_title,comp_description,post_datetime,status,publish_status,comp_catagory,posted_by,id,first_name,email FROM log_tbl l INNER JOIN comp_tbl c ON l.id = c.posted_by WHERE comp_id = '$cid'");
$res = $complain->result_array();
if($res)
return $res;
else
return false;
}
public function Separate_single_complain_replay($cid){
$rep = $this->db->query("SELECT first_name,rep_id,rep_description,rep_datetime,rep_by,rep_against,rep_flag,rating FROM log_tbl l INNER JOIN reply_tbl r ON l.id = r.rep_by WHERE r.rep_against = '$cid 'AND rep_flag = '1'");
$res = $rep->result_array();
if($res)
return $res;
else
return false;
}
enter image description here
This is the view page image
separate_user_admin_reply2.php
And the signin controller is :
public function index()
{
$email = $this->input->post('email');
$password = $this->input->post('password');
$this->load->model('Login_Model');
$data = $this->Login_Model->isvalidate($email,$password);
if($data)
{
$this->load->library('session');
$this->session->set_userdata('email',$data['email']);
$this->session->set_userdata('type',$data['type']);
$this->session->set_userdata('id',$data['id']);
if($data['type']=='User' ){
return redirect('User/index');
}
else
{
return redirect('Admin/adminDashboard');
}
}else{
echo "<script>alert('Details not matched')</script>";
header("refresh:1");
return redirect('Complain/login');
}
}
model:-
public function isvalidate($email,$password)
{
$q = $this->db->where(['email'=>$email,'password'=>$password])
->get('log_tbl');
if($q->num_rows()){
$x = $q->row()->email;
$y = $q->row()->type;
$z = $q->row()->id;
$userData = array('email' => $x, 'type' => $y, 'id' => $z);
return $userData;
}else{
return false;
}
}
signin view page image:
Store the previous page url in session data. You can find a detailed description of how to do that in the codeigniter documentation. When the user successfully logged in, check if the previous page data is set, if so flush it and redirect to it.

What to Show some data On my view but there is a Error In Laravel

Here I am trying to add, Add Comment feature and it's causing a problem to show data.
public function store(Request $request)
{
$chatterreply = new Chatterreply;
$chatterreply->reply = $request->body;
$chatterreply->chatter_post_id = $request->chatter_post_id;
$chatterreply->chatter_discussion_id = $request->chatter_discussion_id;
$chatterreply->save();
$chatterreplies = Chatterreply::where('chatter_post_id',$request->chatter_post_id)->get();
$chatter_editor = config('chatter.editor');
if ($chatter_editor == 'simplemde') {
// Dynamically register markdown service provider
\App::register('GrahamCampbell\Markdown\MarkdownServiceProvider');
}
echo "<pre>"; print_r($chatterreplies); die;
return view('chatter::discussion', compact('chatterreplies','chatter_editor'))->with('chatter_alert','Add Comment Successfully');
}
And Here Is Where I am passing the variable
$chatter = session()->pull('chatter');
return view('chatter::discussion', compact('discussion', 'posts', 'chatter_editor'))->with('chatterreplies',$chatter);

How to create a codeigniter class to store all emails to a table

How can I create a helper class in codeigniter to store all email which sends and receives in my website. I need to call that class with all email functions
$this->load->library('myclass');
If I call this class then this function should store $to,time, body and subject of the email to a table (table1). How it is possible?
Create a library with the name of "myemail" and place that in application/libraries.
application/libraries/myemail.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class CI_Myemail
{
public function __construct()
{
$this->CI =& get_instance();
}
public function saveEmail($to,$body,$subject)
{
$this->CI->load->model("table_model");
$this->table_model->save(array("to"=>$to,"body"=>$body,"subject"=>$subject,"mail_sent_time"=>date("Y-m-d H:i:s")));
}
}
Then you have to create table_model and write function to save the data into data.
In controller, you have to load this library as
$this->load->library('myemail');
In controller, you have to call as
$this->myemail->saveEmail($this->to,$body,$subject);// Here, $this->do is controller variable as you mentioned in comment
You can easily do this by having a helper function to send an email. Where ever you need to send the email call that function. Inside the function save the data to a table before calling the method to send the email. Also you can save the emails without sending with status pending and send it by a cronjob to improve user experience. I am doing same thing in my website.
The helper function as I am using it below. You can tune it for your needs. The data array should have all the details when called from a controller.
function sendEmail($data, $immediate=FALSE) {
$subject = $data['subject'];
$to = $data['to'];
$viewName = $data['template'];
$CI = & get_instance();
$CI->config->load("thephpcode.com");
$from = $CI->config->item('Sender');
$fromName = $CI->config->item('SenderName');
$priority = $CI->config->item('Priority');
if (isset($data['from'])) {
$from = $data['from'];
$fromName = $data['fromName'];
}
if (isset($data['priority']))
$priority = $data['priority'];
$body = $CI->load->view($viewName, $data, TRUE);
if ($from == "") {
log_message('error', 'From value is not set in Email helper for sending email');
return;
}
$bcc = '';
if (isset($data['bcc'])) {
$bcc = $data['bcc'];
}
/*
$replyto ='';
if (isset($data['reply_to'])) {
$replyto = $data['reply_to'];
$replytoname = $data['reply_to_name'];
}
*/
$status = 'Pending';
if ($immediate)
{
$status = 'Sent';
}
$dbdata = array();
$dbdata['from'] = $from;
$dbdata['fromName'] = $fromName;
if (isset($data['reply_to'])) {
$dbdata['replyto'] = $data['reply_to'];
$dbdata['replytoname'] = $data['reply_to_name'];
}
$dbdata['to'] = $to;
$dbdata['subject'] = $subject;
$dbdata['body'] = $body;
$dbdata['bcc'] = $bcc;
$dbdata['status'] = $status;
$dbdata['priority'] = $priority;
$CI->load->model('email_model', 'email_model');
$CI->email_model->insert($dbdata, 'email_queue');
if (!$immediate)
{
return TRUE;
}
//Send the email
$CI->load->library('email');
$CI->email->initialize($CI->config->item('email_config'));
$CI->email->from($from, $fromName);
$CI->email->to($to);
if (isset($data['bcc']))
{
$CI->email->bcc($data['bcc']);
}
if (isset($data['reply_to']))
{
$CI->email->reply_to($data['reply_to'],$data['reply_to_name']);
}
$CI->email->subject($subject);
$CI->email->message($body);
$CI->email->send();
return;
}

Send shipment email programmatically for the completed orders in magento

I am using magento default shipment from the admin side.
so its working fine and sending email to the customers perfectly.
I want to create one script that can send email with the shipment details for all the completed orders in magento. This will be only for certain orders coming through CSV.
My script working fine when we are using the order_id of the processing orders but its not working for the completed orders . and not sending the Order items details in the email
please suggest me any solution for it..
Thanks a lot.
I am using the below script to do so :
function completeShipment($orderIncrementId,$shipmentTrackingNumber,$shipmentCarrierCode){
$shipmentCarrierTitle = $shipmentCarrierCode;
$customerEmailComments = '';
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
if (!$order->getId()) {
Mage::throwException("Order does not exist, for the Shipment process to complete");
}
try {
$shipment = Mage::getModel('sales/service_order', $order)->prepareShipment(_getItemQtys($order));
$arrTracking = array(
'carrier_code' => isset($shipmentCarrierCode) ? $shipmentCarrierCode : $order->getShippingCarrier()->getCarrierCode(),
'title' => isset($shipmentCarrierTitle) ? $shipmentCarrierTitle : $order->getShippingCarrier()->getConfigData('title'),
'number' => $shipmentTrackingNumber,
);
$track = Mage::getModel('sales/order_shipment_track')->addData($arrTracking);
$shipment->addTrack($track);
$shipment->register();
_saveShipment($shipment, $order, $customerEmailComments);
}catch (Exception $e) {
throw $e;
}
return $save;
}
function _getItemQtys(Mage_Sales_Model_Order $order){
$qty = array();
foreach ($order->getAllItems() as $_eachItem) {
if ($_eachItem->getParentItemId()) {
$qty[$_eachItem->getParentItemId()] = $_eachItem->getQtyOrdered();
} else {
$qty[$_eachItem->getId()] = $_eachItem->getQtyOrdered();
}
}
return $qty;
}
function _saveShipment(Mage_Sales_Model_Order_Shipment $shipment, Mage_Sales_Model_Order $order, $customerEmailComments = ''){
$shipment->getOrder()->setIsInProcess(true);
$transactionSave = Mage::getModel('core/resource_transaction')
->addObject($shipment)->addObject($order)->save();
//$emailSentStatus = $shipment->getData('email_sent');
$ship_data = $shipment->getOrder()->getData();
$customerEmail = $ship_data['customer_email'];
$emailSentStatus = $ship_data['email_sent'];
if (!is_null($customerEmail)) {
$shipment->sendEmail(true, $customerEmailComments);
$shipment->setEmailSent(true);
}
return $this;
}
Thanks a lot dagfr...! the below code works for me to get done my task:
function completeShipment($orderIncrementId,$shipmentIncreamentId){
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
$ship_data = $order->getData();
$customerEmail = $ship_data['customer_email'];
$shipment = Mage::getModel('sales/order_shipment')->loadByIncrementId($shipmentIncreamentId);
$customerEmailComments = '';
$sent = 0;
if (!is_null($customerEmail)) {
$sent = $shipment->sendEmail(true, $customerEmailComments);
$shipment->setEmailSent(true);
}
return $sent;
}
Your script tries to create the shipment then send the email.
For completed orders the shipment is already created and you can't create it again, so your try fails before the email sending.
Just before :
try {
$shipment = Mage::getModel('sales/service_order', $order)->prepareShipment(_getItemQtys($order));
Check the status of the order, if it's complete, just need to get the shipment and send the mail
$shipment->sendEmail(true, $customerEmailComments);
$shipment->setEmailSent(true);
Else you can perform your script.
I found success using the order_shipment_api instead of the service_order model.
If you want to include the tracking number in the shipment email, make sure you add the tracking first and then use Mage::getModel('sales/order_shipment_api')->sendInfo($shipmentIncrementId).
Code Snippet:
$shipmentApi = Mage::getModel('sales/order_shipment_api');
//pass false for email, unless you want Magento to send the shipment email without any tracking info
//could also be written as $shipmentIncrementId = $shipmentApi->create($order->getIncrementId());
$shipmentIncrementId = $shipmentApi->create($order->getIncrementId(), array(), '' , false, 0);
//add tracking info ($shippingCarrier is case sensitive)
$shipmentApi->addTrack($shipmentIncrementId, $shippingCarrier, $shippingTitle, $trackingNumber);
//send shipment email with tracking info
$shipmentApi->sendInfo($shipmentIncrementId);
See app\code\core\Mage\Sales\Model\Order\Shipment\Api.php for all methods.
You can(should) also perform checks first:
//check for existing shipments if you want
if ($order->getShipmentsCollection()->count() == 0){
}
// and/or
if($order->canShip()){
}

Get Full Billing Address for Paypal Express [Magento]

The paypal module tries to map the billing information that is returned (usually nothing) from Paypal over the billing information entered by the user during the checkout process. I've fond the code that does this in NVP.php model.
/**
* Create billing and shipping addresses basing on response data
* #param array $data
*/
protected function _exportAddressses($data)
{
$address = new Varien_Object();
Varien_Object_Mapper::accumulateByMap($data, $address, $this->_billingAddressMap);
$address->setExportedKeys(array_values($this->_billingAddressMap));
$this->_applyStreetAndRegionWorkarounds($address);
$this->setExportedBillingAddress($address);
// assume there is shipping address if there is at least one field specific to shipping
if (isset($data['SHIPTONAME'])) {
$shippingAddress = clone $address;
Varien_Object_Mapper::accumulateByMap($data, $shippingAddress, $this->_shippingAddressMap);
$this->_applyStreetAndRegionWorkarounds($shippingAddress);
// PayPal doesn't provide detailed shipping name fields, so the name will be overwritten
$shippingAddress->addData(array(
'prefix' => null,
'firstname' => $data['SHIPTONAME'],
'middlename' => null,
'lastname' => null,
'suffix' => null,
));
$this->setExportedShippingAddress($shippingAddress);
}
}
/**
* Adopt specified address object to be compatible with Magento
*
* #param Varien_Object $address
*/
protected function _applyStreetAndRegionWorkarounds(Varien_Object $address)
{
// merge street addresses into 1
if ($address->hasStreet2()) {
$address->setStreet(implode("\n", array($address->getStreet(), $address->getStreet2())));
$address->unsStreet2();
}
// attempt to fetch region_id from directory
if ($address->getCountryId() && $address->getRegion()) {
$regions = Mage::getModel('directory/country')->loadByCode($address->getCountryId())->getRegionCollection()
->addRegionCodeFilter($address->getRegion())
->setPageSize(1)
;
foreach ($regions as $region) {
$address->setRegionId($region->getId());
$address->setExportedKeys(array_merge($address->getExportedKeys(), array('region_id')));
break;
}
}
}
Has anyone had any success modifying this process to get back fuller billing information. We need to be able to send "Paid" invoices to customers who pay with Paypal, so we need to capture this information.
i have hacked a workaround for that problem. It is not the cleanest way but i can save the billing address data in the order after paying with PayPal. I spent 2 days working on it and at the end i coded only a few lines. I marked my workaround with the comment #103.
Override method of class Mage_Paypal_Model_Api_Nvp:
protected function _importAddresses(array $to)
{
// Original Code
//$billingAddress = ($this->getBillingAddress()) ? $this->getBillingAddress() : $this->getAddress();
// Workaround #103
if ($this->getBillingAddress())
{
$billingAddress = $this->getBillingAddress();
}
else
{
$chkout = Mage::getSingleton('checkout/session');
$quote = $chkout->getQuote();
$billingAddress = $quote->getBillingAddress();
$billingAddress->setData($billingAddress->getOrigData());
$session = Mage::getSingleton("core/session", array("name"=>"frontend"));
$session->setData("syn_paypal_original_billing_address", serialize($billingAddress->getOrigData()));
}
$shippingAddress = $this->getAddress();
$to = Varien_Object_Mapper::accumulateByMap($billingAddress, $to, array_flip($this->_billingAddressMap));
if ($regionCode = $this->_lookupRegionCodeFromAddress($billingAddress)) {
$to['STATE'] = $regionCode;
}
if (!$this->getSuppressShipping()) {
$to = Varien_Object_Mapper::accumulateByMap($shippingAddress, $to, array_flip($this->_shippingAddressMap));
if ($regionCode = $this->_lookupRegionCodeFromAddress($shippingAddress)) {
$to['SHIPTOSTATE'] = $regionCode;
}
$this->_importStreetFromAddress($shippingAddress, $to, 'SHIPTOSTREET', 'SHIPTOSTREET2');
$this->_importStreetFromAddress($billingAddress, $to, 'STREET', 'STREET2');
$to['SHIPTONAME'] = $shippingAddress->getName();
}
$this->_applyCountryWorkarounds($to);
return $to;
}
And override method in Mage_Paypal_Model_Express_Checkout:
public function returnFromPaypal($token)
{
$this->_getApi();
$this->_api->setToken($token)
->callGetExpressCheckoutDetails();
// import billing address
$billingAddress = $this->_quote->getBillingAddress();
$exportedBillingAddress = $this->_api->getExportedBillingAddress();
// Workaround #103
$session = Mage::getSingleton("core/session", array("name"=>"frontend"));
$dataOrg = unserialize($session->getData("syn_paypal_original_billing_address"));
if (true === is_object($billingAddress))
{
foreach ($exportedBillingAddress->getExportedKeys() as $key) {
if (array_key_exists($key, $dataOrg))
{
$billingAddress->setData($key, $dataOrg[$key]);
}
}
$this->_quote->setBillingAddress($billingAddress);
}
// import shipping address
$exportedShippingAddress = $this->_api->getExportedShippingAddress();
if (!$this->_quote->getIsVirtual()) {
$shippingAddress = $this->_quote->getShippingAddress();
if ($shippingAddress) {
if ($exportedShippingAddress) {
foreach ($exportedShippingAddress->getExportedKeys() as $key) {
$shippingAddress->setDataUsingMethod($key, $exportedShippingAddress->getData($key));
}
$shippingAddress->setCollectShippingRates(true);
}
// import shipping method
$code = '';
if ($this->_api->getShippingRateCode()) {
if ($code = $this->_matchShippingMethodCode($shippingAddress, $this->_api->getShippingRateCode())) {
// possible bug of double collecting rates :-/
$shippingAddress->setShippingMethod($code)->setCollectShippingRates(true);
}
}
$this->_quote->getPayment()->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_SHIPPING_METHOD, $code);
}
}
$this->_ignoreAddressValidation();
// import payment info
$payment = $this->_quote->getPayment();
$payment->setMethod($this->_methodType);
Mage::getSingleton('paypal/info')->importToPayment($this->_api, $payment);
$payment->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_PAYER_ID, $this->_api->getPayerId())
->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_TOKEN, $token)
;
$this->_quote->collectTotals()->save();
}

Resources