I am using Magento 1.9.2.4 version. I am using SMS module for receiving SMS after placing the order .While selecting option as "Pay Using Credit Card / Debit Card / Net Banking" it is redirecting to payUmoney money page and amount deducting but order placing time error getting like this
Fatal error: Call to a member function getTelephone() on a non-object in model/Observer.php on line 125
My observer code:
public function salesOrderPlace(Varien_Event_Observer $observer)
{
try{
Mage::log("New Order Placed");
$order = Mage::getModel('sales/order');
$incrementId = Mage::getSingleton('checkout/session')->getLastOrderId();
Mage::log("Order ID:".$incrementId);
$order = Mage::getModel('sales/order')->loadByIncrementId($incrementId);
if ($order instanceof Mage_Sales_Model_Order)
{
if($this->getHelper()->issalesOrderPlace())
{
$mobilenumbers = $order->getBillingAddress()->getTelephone();
$message = $this->getHelper()->getOrderMessage($order); //enter Your Message
$customerName = $order->getCustomerName();
//curlApicall : this method will return tru or fale.
$retunValue = $this->getHelper()->curlApiCall($message,$mobilenumbers,$customerName,"New Order");
}
if($this->getHelper()->issalesOrderPlaceForAdmin())
{
$mobilenumbers = $this->getHelper()->getAdminMobileNumber();
$message = $this->getHelper()->getOrderMessageForAdmin($order); //enter Your Message
$customerName = $order->getCustomerName();
//curlApicall : this method will return tru or fale.
$retunValue = $this->getHelper()->curlApiCall($message,$mobilenumbers,$customerName,"New Order");
}
}
//return false;
}catch(Exception $e) {
Mage::log($e->getMessage());
}
}
the problem is here
$order = Mage::getModel('sales/order');
$incrementId = Mage::getSingleton('checkout/session')->getLastOrderId();
Mage::log("Order ID:".$incrementId);
$order = Mage::getModel('sales/order')->loadByIncrementId($incrementId);
increment Id is not the same as order id
use this fix:
$orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
$order = Mage::getModel('sales/order')->load($orderId);
Related
in my website I am trying to make asynchronous calls to my database with jquery ajax function at least 100 times at the same time in a for loop and after some queries (definitely more than 30) I get the error:
SQLSTATE[42000] [1226] User '***' has exceeded the
'max_user_connections' resource (current value: 30)
but I am using a shared hosting and they say I/they cannot change the max_user_connections value to a higher number.
Now, I have no idea how to solve this problem. Is there anyone who knows a way? Thank you.
Edit: I have a website for classification of species/taxonomy and I want to show this in a sunburst chart but there are more than 65K species and it is hard to draw all chart. To achieve this, I made this chart clickable and when an user clicks, new elements are drawn by the response of ajax call.
For simplification, I do not include the lines that I define the variables.
JavaScript:
$.when(info(domain,name)).done((response)=>{
try {
layer_info = jQuery.parseJSON(response)
}catch (error) {
console.log(response)
console.log(error)
}
for (let i = 0; i < layer_info.size; i++) {
$.when(info(child_domain,child_name)).done((resp)=>{
try {
child_info = jQuery.parseJSON(resp)
} catch (e) {
console.log(resp) // I get mentioned error from info.php on console from this line.
console.log(e)
}
})
}
})
Function info makes the ajax call and returns the response.
function info(b,i){
return $.ajax({
url: "info.php",
method:"POST",
data:{domain:b,name:i},
dataType: "text",
})
}
info.php:
try{
$timezone = "+3:00";
$db=new PDO('mysql:host=localhost;port=3306;dbname=***;charset=utf8','***', '***');
$db->exec("SET time_zone = '{$timezone}'");
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}catch(PDOException $e){
echo $e->getMessage(); // this line generates the error
}
try{
$name = $_POST["name"];
$domain = $_POST["domain"];
$count_query = $db->prepare("SELECT COUNT(*) FROM table WHERE $domain=?");
$count_query->execute(array($name));
$count_result = $count_query->fetchColumn();
$query = $db->prepare("SELECT * FROM table WHERE $domain=? GROUP BY $sub");
$query->execute(array($name));
while($results = $query->fetch(PDO::FETCH_ASSOC)){
array_push($nodes,$results);
}
$data['spec_size'] = $count_result;
$data["size"] = count($nodes);
$data["childs"] = $nodes;
echo json_encode($data);
}catch (\Throwable $th) {
echo $th;
}
I am trying to create shipment and adding tracking number after placing an order,but i am getting an error like Cannot create an empty shipment. when i search through google i got one of the reason for this is item quantity is null, but what i used below is returning the exact quantities of products ordered.
$itemQty = $order->getItemsCollection()->count();
I don't know exactly it is only the reason for that error. what i done mistake? anybody knows please help me on this.
public function salesOrderInvoiceShipmentCreate($observer)
{
// $order = $observer->getEvent()->getOrder();
//$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
$order_id = $observer->getData('order_ids');
$order = Mage::getModel('sales/order')->load($order_id);
$token = '3acb6561b04117c6cbe3552c90f1d6815507e257';
$waybill_url = 'https://track.delhivery.com/waybill/api/fetch/json/?token='.$token.'&cl=GEECHOO';
$waybill = file_get_contents($waybill_url);
Mage::log($order, Zend_Log::INFO, 'order.log', true);
if (!$order->getId()) {
Mage::throwException('Order does not exist, for the Shipment process to complete');
}
if ($order->canShip()) {
try {
// $shipment = Mage::getModel('sales/service_order', $order)
// ->prepareShipment($this->_getItemQtys($order));
$itemQty = $order->getItemsCollection()->count();
$shipment = Mage::getModel('sales/service_order', $order)->prepareShipment($itemQty);
$shipmentCarrierCode = '';
$shipmentCarrierTitle = '';
$arrTracking = array(
'carrier_code' => isset($shipmentCarrierCode) ? $shipmentCarrierCode : $order->getShippingCarrier()->getCarrierCode(),
'title' => isset($shipmentCarrierTitle) ? $shipmentCarrierTitle : $order->getShippingCarrier()->getConfigData('title'),
'tracking_number' => $waybill,
);
$track = Mage::getModel('sales/order_shipment_track')->addData($arrTracking);
$shipment->addTrack($track);
// Register Shipment
$shipment->register();
// Save the Shipment
$this->_saveShipment($shipment, $order);
// Finally, Save the Order
$this->_saveOrder($order);
} catch (Exception $e) {
throw $e;
}
}
}
Try this for order item quantity
$quote = Mage::helper('checkout/cart')->getCart()->getQuote();
$value = [];
foreach ($quote->getAllItems() as $item) {
$value[]= array (
'id' => $item->getSku(),
'quantity' => $item->getQty(),
}
I recently bought project management system, I was trying to add new forms but my forms are not working. I think my problem is the model, I am failing to get a session value (project_code) submitted to the database to make sure that the specific entry is visible to the specific project. The system I bought is ekushey available on codecanyon.
Model
function client_invoicing_add($project_code = '') {
//$data['project_code'] = $project_code;
//$data['project_code'] = $this->session->userdata('project_code');
$data['client_payment_milestone'] = $this->input->post('client_payment_milestone');
$data['client_payment_deliverables'] = $this->input->post('client_payment_deliverables');
$data['client_payment_date'] = $this->input->post('client_payment_date');
$data['client_payment_amount'] = $this->input->post('client_payment_amount');
$data['timestamp'] = strtotime($this->input->post('timestamp'));
$data['client_id'] = $this->session->userdata('login_user_id');
$data['project_code'] = $this->db->get_where('project' , array('project_id' => $project_id))->row()->project_code;
//$data['project_id'] = $this->db->get_where('project' , array('project_code' => $project_code))->row()->project_id;
$this->db->insert('client_invoicing' , $data);
}
Controller
// Client invoicing
function client_invoicing($param1 = '' , $param2 = '' , $param3 = '') {
if ($this->session->userdata('client_login') != 1) {
$this->session->set_userdata('last_page', current_url());
redirect(base_url(), 'refresh');
}
if ($param1 == 'add') {
$this->crud_model->client_invoicing_add($param2); // param2 = project code
}
if ($param1 == 'edit') {
$this->crud_model->client_invoicing_edit($param2); // param2 = client payment id
}
if ($param1 == 'delete') {
$this->crud_model->client_invoicing_delete($param2); // param2 = client payment id
}
}
you can use var_dump($this->session->all_userdata()); to print all session objects. and from them you can check if session is already set or not.
Session array is available through the $_SESSION global:
$name = $_SESSION['name'];
// or:
$name = $this->session->name
// or:
$name = $this->session->userdata('name');
If you want to retrieve all of the existing userdata
$_SESSION
// or:
$this->session->userdata();
Note : The userdata() method returns NULL if the item you are trying
to access does not exist.
i have made form by Codeigniter to reset password when i send request it return with tis error
ou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '#hotmail.com' at line 1.
this is my controller
function index()
{
$this->load->model("user_model");
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://abuqir.net';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = 'myuser';
$config['smtp_pass'] = 'mypass';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'text'; // or html
$config['validation'] = TRUE; // bool whether to validate email or not
$email_to = $this->input->get('email');
$pass_message = $this->user_model->get_pass($email_to);
$this->email->initialize($config);
$this->email->from('admin-team#abuqir.net', 'admin team');
$this->email->to($email_to);
$this->email->subject('Reset password');
$this->email->message($pass_message);
$this->email->send();
echo $this->email->print_debugger();
$this->load->view('email_view');
}
and this my model
public function get_pass($user_mail) {
$user_mail = mysqli_real_escape_string($user_mail);
$query = $this->db->query('SELECT password'
. ' from users '
. 'where email = '.$user_mail
);
return $query;
}
In Model
public function get_pass($user_mail)
{
$user_mail = mysqli_real_escape_string($user_mail);
$query = $this->db->query("SELECT password from users where email = '$user_mail'");
$result = $query->result_array();
return $result;
}
In Controller
function index()
{
$email_to = $this->input->post('email'); //check GET otr POST
$pass_message = $this->user_model->get_pass($email_to);
if(!empty($pass_message))
{
$this->load->model("user_model");
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://abuqir.net';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = 'myuser';
$config['smtp_pass'] = 'mypass';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'text'; // or html
$config['validation'] = TRUE; // bool whether to validate email or not
$this->email->initialize($config);
$this->email->from('admin-team#abuqir.net', 'admin team');
$this->email->to($email_to);
$this->email->subject('Reset password');
$this->email->message($pass_message[0]['password']);
if(! $this->email->send())
{
echo $this->email->print_debugger();
}
else
{
//Email sending failed
$this->load->view('email_view');
}
}
else
{
// Successfully sent
echo 'Invalid E-Mail Address'
}
}
Before configure mail check email validity then do rest of code
When you use $this->input->post it will act as mysqli_real_escape_string too. For further you need to secure from XSS use boolean TRUE. ($this->input->post('some_data', TRUE);)
public function get_pass($user_mail) {
$user_mail = mysqli_real_escape_string($user_mail);
$query = $this->db->query('SELECT password'
. ' from users '
. "where email = '".$user_mail ."'"
);
return $query;
}
You forgot to wrapper email in Query within single quotes.
NOTE: I am not sure how we build Parameter query using CodeIgnitor, please use that as this query is seriously unsafe and been a password reset query, it is probably more public code and not recommended.
My New Order email already uses {{var payment_html}} and I already have a custom note for customers who select MoneyGram, Western Union and Money Transfer payment methods. I need to send different information for every single payment method in the email being sent.
you need to override sendNewOrderEmail() in /app/code/core/Mage/Sales/Model/order.php
in this function just check the payment and dynamically pass the value to array.
public function sendNewOrderEmail()
{
$storeId = $this->getStore()->getId();
if (!Mage::helper('sales')->canSendNewOrderEmail($storeId)) {
return $this;
}
// Get the destination email addresses to send copies to
$copyTo = $this->_getEmails(self::XML_PATH_EMAIL_COPY_TO);
$copyMethod = Mage::getStoreConfig(self::XML_PATH_EMAIL_COPY_METHOD, $storeId);
// Start store emulation process
$appEmulation = Mage::getSingleton('core/app_emulation');
$initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
try {
// Retrieve specified view block from appropriate design package (depends on emulated store)
$paymentBlock = Mage::helper('payment')->getInfoBlock($this->getPayment())
->setIsSecureMode(true);
$paymentBlock->getMethod()->setStore($storeId);
$paymentBlockHtml = $paymentBlock->toHtml();
} catch (Exception $exception) {
// Stop store emulation process
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
throw $exception;
}
// Stop store emulation process
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
// Retrieve corresponding email template id and customer name
if ($this->getCustomerIsGuest()) {
$templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_GUEST_TEMPLATE, $storeId);
$customerName = $this->getBillingAddress()->getName();
} else {
$templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $storeId);
$customerName = $this->getCustomerName();
}
$mailer = Mage::getModel('core/email_template_mailer');
$emailInfo = Mage::getModel('core/email_info');
$emailInfo->addTo($this->getCustomerEmail(), $customerName);
if ($copyTo && $copyMethod == 'bcc') {
// Add bcc to customer email
foreach ($copyTo as $email) {
$emailInfo->addBcc($email);
}
}
$mailer->addEmailInfo($emailInfo);
// Email copies are sent as separated emails if their copy method is 'copy'
if ($copyTo && $copyMethod == 'copy') {
foreach ($copyTo as $email) {
$emailInfo = Mage::getModel('core/email_info');
$emailInfo->addTo($email);
$mailer->addEmailInfo($emailInfo);
}
}
// $orde$this->getOrderId();
$order_payment_title = $this->getOrder()->getPayment()->getMethodInstance()->getTitle();
if($order_payment_title=='moneygram'){
$paymentBlockHtml = 'moneygram html'; //custom html
}elseif($order_payment_title=='westernunion'){
$paymentBlockHtml = 'westernunion html'; //custom html
}elseif($order_payment_title=='monyetransfer '){
$paymentBlockHtml = 'monyetransfer html'; //custom html
}
// Set all required params and send emails
$mailer->setSender(Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId));
$mailer->setStoreId($storeId);
$mailer->setTemplateId($templateId);
$mailer->setTemplateParams(array(
'order' => $this,
'billing' => $this->getBillingAddress(),
'payment_html' => $paymentBlockHtml
)
);
$mailer->send();
$this->setEmailSent(true);
$this->_getResource()->saveAttribute($this, 'email_sent');
return $this;
}