Ejemplo n.º 1
0
 public function sendConfirmation($orderId)
 {
     $order = ORM::factory('order', $orderId);
     $db = new Database();
     $res = $db->query('SELECT oa.* FROM orders_addresses oa JOIN orders o ON (oa.id = o.orders_address_id) WHERE o.id="' . $orderId . '"');
     // call autoresponder handlers
     $shippingInfo = $res[0]->shipping_first_name . ' ' . $res[0]->shipping_last_name . '<br/>' . $res[0]->shipping_address1 . '<br/>' . $res[0]->shipping_address2 . '<br/>' . $res[0]->shipping_city . ' ' . $res[0]->shipping_state . '<br/>' . $res[0]->shipping_zip . '<br/>' . $res[0]->shipping_country;
     $billingInfo = $res[0]->billing_first_name . ' ' . $res[0]->billing_last_name . '<br/>' . $res[0]->billing_address1 . '<br/>' . $res[0]->billing_address2 . '<br/>' . $res[0]->billing_city . ' ' . $res[0]->billing_state . '<br/>' . $res[0]->billing_zip . '<br/>' . $res[0]->billing_country;
     $dateTime = date('Y-m-d H:i:s');
     $res = $db->query('SELECT p.name, ob.qty, ob.subtotal FROM products p JOIN orders_baskets ob ON (ob.product_id=p.id) WHERE ob.order_id="' . $orderId . '"');
     $order_basket = new Orders_basket_Model();
     $description = '';
     $subtotal = 0;
     foreach ($res as $item) {
         $description .= $item->name . '  ' . $item->qty . ' x ' . format::dollar($item->subtotal) . '<br/>';
         $subtotal += $item->subtotal;
     }
     if (!empty($order->comment)) {
         $description .= 'Comment:' . $order->comment . '<br/>';
     }
     $total = 'Subtotal: ' . format::dollar($subtotal) . '<br/>Shipping:' . format::dollar($order->shipping_total);
     $total .= '<br/>Total:' . format::dollar($order->payment_total);
     Autoresponder::sendEmail('order.confirmation', $order->email, $order, array('shipping_info' => $shippingInfo, 'billing_info' => $billingInfo, 'date_time' => $dateTime, 'description' => $description, 'total' => $total));
 }
Ejemplo n.º 2
0
 public function forgot_password()
 {
     if (User_Model::logged_in()) {
         url::redirect('/customers/my_account');
         return;
     }
     $this->template->content = new View('customers/forgot_password');
     $this->template->content->email = '';
     $this->template->content->errors = '';
     if (request::method() == 'post') {
         $post = new Validation($_POST);
         $post->add_rules('email', 'required');
         $this->template->content->email = $post->email;
         if ($post->validate()) {
             $user = ORM::factory('user')->where('email', $post->email)->find();
             if ($user->id != 0) {
                 $user->password_recovery_hash = md5((string) $user);
                 $user->save();
                 $this->template->content->email_sent = TRUE;
                 $url = 'http://' . $_SERVER['SERVER_NAME'] . '/customers/new_password?hash=' . $user->password_recovery_hash;
                 Autoresponder::sendEmail('user.forgot_password', $user->email, $user, array('here_link' => '<a href="' . $url . '">here</a>', 'url' => $url));
             } else {
                 $this->template->content->errors = 'The email doesn\'t exists in our database.';
             }
         } else {
             $this->template->content->errors = 'Email is required.';
         }
     }
     $this->template->metaDescription = $this->description;
     $this->template->metaKeywords = $this->keywords;
     $this->template->metaTitle = $this->title;
     $this->template->title = $this->title;
 }
Ejemplo n.º 3
0
 public function paypal_ok()
 {
     $trans_id = $this->input->get('token');
     // In Kohana, all views are loaded and treated as objects.
     $this->template->content = new View('paypal_status');
     $postvars = $_POST;
     $db = new Database();
     $result = $db->query('SELECT * FROM orders WHERE trans_id = \'' . $trans_id . '\'');
     $order = $result[0];
     $this->template->content->_order = ORM::factory('order', $order->id);
     //CREATE PAYMENT
     $result = $db->query('INSERT INTO payments (transaction_number, statusID, transaction_date) VALUES (\'' . $trans_id . '\', 3, ' . time() . ')');
     $paymentid = mysql_insert_id();
     //CREATE Order ID Entry
     $_res = $db->query('SELECT id FROM order_ids WHERE order_id="' . $order->id . '"');
     if (!$_res[0] || !$_res[0]->id) {
         //CREATE Order ID Entry
         $_res = $db->query('INSERT INTO order_ids (order_id) VALUES (' . $order->id . ')');
         $new_order_id = mysql_insert_id();
     } else {
         $new_order_id = $_res[0]->id;
     }
     //UPDATE THE ORDER TABLE
     $result = $db->query('UPDATE orders SET paymentID = ' . $paymentid . ', payment_method = "PayPal", statusID = 2, order_total= ' . $order->subtotal . ', shipping_total = ' . $order->shipping_total . ', order_date = \'' . date("Y-m-d H:i:s", time()) . '\', date_modified = ' . time() . ' WHERE id = ' . $order->id . '');
     $result = $db->query('SELECT orders.*, users.email, user_billing_infos.firstname as billfname, user_billing_infos.lastname as billlname, user_billing_infos.address1 as billaddress, user_billing_infos.city as billcity, user_billing_infos.state as billstate, user_billing_infos.zip as billzip, user_billing_infos.country as billcountry, user_billing_infos.phone1 as billphone, user_shipping_infos.firstname as shipfname, user_shipping_infos.lastname as shiplname, user_shipping_infos.address1 as shipaddress, user_shipping_infos.city as shipcity, user_shipping_infos.state as shipstate, user_shipping_infos.zip as shipzip, user_shipping_infos.country as shipcountry FROM orders LEFT JOIN user_billing_infos ON orders.billingID = user_billing_infos.id LEFT JOIN user_shipping_infos ON orders.shippingID = user_shipping_infos.id LEFT JOIN users ON orders.user_id = users.id WHERE orders.id = ' . $order->id . '');
     $order = $result[0];
     $shippingInfo = $order->shipfname . ' ' . $order->shiplname . '<br/>' . $order->shipaddress . '<br/>' . $order->shipcity . ' ' . $order->shipstate . '<br/>' . $order->shipzip . '<br/>' . $order->shipcountry;
     $billingInfo = $order->billfname . ' ' . $order->billlname . '<br/>' . $order->billaddress . '<br/>' . $order->billcity . ' ' . $order->billstate . '<br/>' . $order->billzip . '<br/>' . $order->billcountry;
     $dateTime = date('Y-m-d H:i:s');
     $res = $db->query('SELECT p.name, ob.qty, ob.subtotal, ob.id as ob_id FROM products p JOIN orders_baskets ob ON (ob.product_id=p.id) WHERE ob.order_id="' . $order->id . '"');
     $description = '';
     $subtotal = 0;
     foreach ($res as $item) {
         $basket = ORM::factory('orders_basket', $item->ob_id);
         $product_name = $item->name;
         if ($basket->packaging_id != 0) {
             $product_name .= ' - ' . $basket->packaging->name;
         }
         $description .= '' . $item->qty . ' x ' . $product_name . ' = ' . money_format('%.2n', $item->subtotal) . '<br/>';
         $subtotal += $item->subtotal;
     }
     if (!empty($order->comment)) {
         $description .= 'Comment:' . $order->comment . '<br/>';
     }
     $total = 'Subtotal: ' . money_format('%.2n', $subtotal) . '<br/>Shipping:' . money_format('%.2n', $order->shipping_total);
     $total .= '<br/>Total:' . money_format('%.2n', $order->order_total);
     $emailAddr = $order->email;
     $res = $db->query('SELECT id FROM order_ids WHERE order_id = ' . $order->id . '');
     $orderid = $res[0]->id;
     $order->id = $orderid;
     $new_order_id = 'MCH' . $orderid;
     $to = array($emailAddr, '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**');
     foreach ($to as $address) {
         Autoresponder::sendEmail('order.status.changed', $address, $order, array('shipping_info' => $shippingInfo, 'billing_info' => $billingInfo, 'date_time' => $dateTime, 'description' => $description, 'total' => $total, 'order_id' => $new_order_id));
     }
     $this->template->content->status = 'Your paypal paymeny was successful!';
     $this->template->content->trans_id = $trans_id;
     $this->template->content->order_id = $order->id;
     $user_id = FALSE;
     if (User_Model::logged_in()) {
         $user_id = User_Model::logged_user()->id;
     }
     Session::instance()->regenerate();
     if ($user_id) {
         ORM::factory('user')->find($user_id)->forceLogin();
     }
     // Meta Description and Meta Keywords for individual pages are, at this point, hard coded.
     $this->template->metaDescription = $this->description;
     $this->template->metaKeywords = $this->keywords;
     $this->template->metaTitle = $this->title;
     // You can assign anything variable to a view by using standard OOP
     // methods. In my welcome view, the $title variable will be assigned
     // the value I give it here.
     $this->template->title = $this->title;
 }
Ejemplo n.º 4
0
 public function test()
 {
     $id = $this->uri->segment(3);
     $order = ORM::factory('order')->find($id);
     // call autoresponder handler
     $order_address = ORM::factory('orders_address')->find($order->orders_address_id);
     $shippingInfo = $order_address->shipping_first_name . ' ' . $order_address->shipping_last_name . '<br/>' . $order_address->shipping_address1 . '<br/>' . $order_address->shipping_city . ' ' . $order_address->shipping_state . '<br/>' . $order_address->shipping_zip . '<br/>' . $order_address->shipping_country;
     $billingInfo = $order_address->billing_first_name . ' ' . $order_address->billing_last_name . '<br/>' . $order_address->billing_address1 . '<br/>' . $order_address->billing_city . ' ' . $order_address->billing_state . '<br/>' . $order_address->billing_zip . '<br/>' . $order_address->billing_country;
     $dateTime = date('Y-m-d H:i:s');
     $db = new Database();
     $res = $db->query('SELECT p.name, ob.qty FROM products p JOIN orders_baskets ob ON (ob.product_id=p.id) WHERE ob.order_id="' . $order->id . '"');
     $order_basket = new Orders_basket_Model();
     $description = '';
     foreach ($res as $item) {
         $description .= $item->name . ' x ' . $item->qty . '<br/>';
     }
     Autoresponder::sendEmail('order.status.changed', '*****@*****.**', $order, array('shipping_info' => $shippingInfo, 'billing_info' => $billingInfo, 'date_time' => $dateTime, 'description' => $description, 'total' => format::dollar($order->payment_total)));
 }