OpenCart order tracking without login - opencart
i'm using opencart 1.5.6.3, i'm trying to display a page with 2 field. 1 field will be use for Email and another field for Order ID. So client can see their order status directly without login.
thanks in advance.
After so much try, I got solution.
Add new file to
catalog> controller> account> guest.php
<?php class ControllerAccountGuest extends Controller {
private $error = array();
public function index() {
$this->language->load('account/guest');
$this->document->setTitle($this->language->get('heading_title'));
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_account'),
'href' => $this->url->link('account/account', '', 'SSL'),
'separator' => $this->language->get('text_separator')
);
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['entry_email'] = $this->language->get('entry_email');
$this->data['entry_ip'] = $this->language->get('entry_ip');
$this->data['entry_order_id'] = $this->language->get('entry_order_id');
$this->data['text_err'] = $this->language->get('text_err');
$this->data['text_ip'] = $this->language->get('text_ip');
$this->data['text_order_id'] = $this->language->get('text_order_id');
$this->data['button_continue'] = $this->language->get('button_continue');
$this->data['action'] = $this->url->link('account/guest/info', '', 'SSL');
$this->data['continue'] = $this->url->link('account/guest', '', 'SSL');
if (isset($this->request->get['email'])) {
$this->data['email'] = $this->request->get['email'];
} else {
$this->data['email'] = '';
}
if (isset($this->request->get['ip'])) {
$this->data['ip'] = $this->request->get['ip'];
} else {
$this->data['ip'] = '';
}
if (isset($this->request->get['order_id'])) {
$this->data['order_id'] = $this->request->get['order_id'];
} else {
$this->data['order_id'] = '';
}
// Nacteni chybovych hlaseni
$err = array(
'email' => false,
'ip' => false,
'order_id' => false,
);
if (isset($this->request->get['err'])) {
$err_temp = explode('|', $this->request->get['err']);
foreach ($err_temp as $value) {
$err[$value] = true;
} // foreach
}
$this->data['err'] = $err;
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/guest_login.tpl')) {
$this->template = $this->config->get('config_template') . '/template/account/guest_login.tpl';
} else {
$this->template = 'default/template/account/guest_login.tpl';
}
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
}
public function info() {
$err = false;
$url = '';
if ( isset($this->request->post['email']) AND strlen($this->request->post['email']) > 4 ) {
$email = $this->request->post['email'];
$url .= '&email=' . $this->request->post['email'];
} else {
$email = '';
$err = ( $err ? $err . '|' . 'email' : 'email' );
}
/*
if (isset($this->request->post['ip'])) {
$ip = $this->request->post['ip'];
$url .= '&ip=' . $this->request->post['ip'];
} else {
$ip = '0';
$err = ( $err ? $err . '|' . 'ip' : 'ip' );
}
*/
if ( isset($this->request->post['order_id']) AND is_numeric($this->request->post['order_id']) ) {
$order_id = $this->request->post['order_id'];
$url .= '&order_id=' . $this->request->post['order_id'];
} else {
$order_id = '0';
$err = ( $err ? $err . '|' . 'order_id' : 'order_id' );
}
if ($err) {
$url .= '&err=' . $err;
$this->redirect($this->url->link('account/guest', 'token=' . $this->session->data['token'] . $url, 'SSL'));
}
$this->language->load('account/guest_history');
$this->load->model('account/guest');
//$order_info = $this->model_account_guest->getOrder($order_id, $email, $ip);
$order_info = $this->model_account_guest->getOrder($order_id, $email);
if ($order_info) {
$this->document->setTitle($this->language->get('text_order'));
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_account'),
'href' => $this->url->link('account/account', '', 'SSL'),
'separator' => $this->language->get('text_separator')
);
$this->data['heading_title'] = $this->language->get('text_order');
$this->data['text_order_detail'] = $this->language->get('text_order_detail');
$this->data['text_invoice_no'] = $this->language->get('text_invoice_no');
$this->data['text_order_id'] = $this->language->get('text_order_id');
$this->data['text_date_added'] = $this->language->get('text_date_added');
$this->data['text_shipping_method'] = $this->language->get('text_shipping_method');
$this->data['text_shipping_address'] = $this->language->get('text_shipping_address');
$this->data['text_payment_method'] = $this->language->get('text_payment_method');
$this->data['text_payment_address'] = $this->language->get('text_payment_address');
$this->data['text_history'] = $this->language->get('text_history');
$this->data['text_comment'] = $this->language->get('text_comment');
$this->data['text_action'] = $this->language->get('text_action');
$this->data['text_selected'] = $this->language->get('text_selected');
$this->data['text_reorder'] = $this->language->get('text_reorder');
$this->data['text_return'] = $this->language->get('text_return');
$this->data['column_name'] = $this->language->get('column_name');
$this->data['column_model'] = $this->language->get('column_model');
$this->data['column_quantity'] = $this->language->get('column_quantity');
$this->data['column_price'] = $this->language->get('column_price');
$this->data['column_total'] = $this->language->get('column_total');
$this->data['column_date_added'] = $this->language->get('column_date_added');
$this->data['column_status'] = $this->language->get('column_status');
$this->data['column_comment'] = $this->language->get('column_comment');
$this->data['button_continue'] = $this->language->get('button_continue');
$this->data['action'] = $this->url->link('account/order/info', 'order_id=' . $order_id , 'SSL');
if ($order_info['invoice_no']) {
$this->data['invoice_no'] = $order_info['invoice_prefix'] . $order_info['invoice_no'];
} else {
$this->data['invoice_no'] = '';
}
$this->data['order_id'] = $order_id ;
$this->data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added']));
if ($order_info['shipping_address_format']) {
$format = $order_info['shipping_address_format'];
} else {
$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
}
$find = array(
'{firstname}',
'{lastname}',
'{company}',
'{address_1}',
'{address_2}',
'{city}',
'{postcode}',
'{zone}',
'{zone_code}',
'{country}'
);
$replace = array(
'firstname' => $order_info['shipping_firstname'],
'lastname' => $order_info['shipping_lastname'],
'company' => $order_info['shipping_company'],
'address_1' => $order_info['shipping_address_1'],
'address_2' => $order_info['shipping_address_2'],
'city' => $order_info['shipping_city'],
'postcode' => $order_info['shipping_postcode'],
'zone' => $order_info['shipping_zone'],
'zone_code' => $order_info['shipping_zone_code'],
'country' => $order_info['shipping_country']
);
$this->data['shipping_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
$this->data['shipping_method'] = $order_info['shipping_method'];
if ($order_info['payment_address_format']) {
$format = $order_info['payment_address_format'];
} else {
$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
}
$find = array(
'{firstname}',
'{lastname}',
'{company}',
'{address_1}',
'{address_2}',
'{city}',
'{postcode}',
'{zone}',
'{zone_code}',
'{country}'
);
$replace = array(
'firstname' => $order_info['payment_firstname'],
'lastname' => $order_info['payment_lastname'],
'company' => $order_info['payment_company'],
'address_1' => $order_info['payment_address_1'],
'address_2' => $order_info['payment_address_2'],
'city' => $order_info['payment_city'],
'postcode' => $order_info['payment_postcode'],
'zone' => $order_info['payment_zone'],
'zone_code' => $order_info['payment_zone_code'],
'country' => $order_info['payment_country']
);
$this->data['payment_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
$this->data['payment_method'] = $order_info['payment_method'];
$this->data['products'] = array();
$products = $this->model_account_guest->getOrderProducts($order_id );
foreach ($products as $product) {
$option_data = array();
$options = $this->model_account_guest->getOrderOptions($order_id , $product['order_product_id']);
foreach ($options as $option) {
if ($option['type'] != 'file') {
$option_data[] = array(
'name' => $option['name'],
'value' => (strlen($option['value']) > 20 ? substr($option['value'], 0, 20) . '..' : $option['value']),
);
} else {
$filename = substr($option['value'], 0, strrpos($option['value'], '.'));
$option_data[] = array(
'name' => $option['name'],
'value' => (strlen($filename) > 20 ? substr($filename, 0, 20) . '..' : $filename)
);
}
} // foreach
$this->data['products'][] = array(
'order_product_id' => $product['order_product_id'],
'name' => $product['name'],
'model' => $product['model'],
'option' => $option_data,
'quantity' => $product['quantity'],
'price' => $this->currency->format($product['price'], $order_info['currency_code'], $order_info['currency_value']),
'total' => $this->currency->format($product['total'], $order_info['currency_code'], $order_info['currency_value']),
'selected' => isset($this->request->post['selected']) && in_array($result['order_product_id'], $this->request->post['selected'])
);
}
$this->data['totals'] = $this->model_account_guest->getOrderTotals($order_id );
$this->data['comment'] = $order_info['comment'];
$this->data['histories'] = array();
$results = $this->model_account_guest->getOrderHistories($order_id );
foreach ($results as $result) {
$this->data['histories'][] = array(
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
'status' => $result['status'],
'comment' => nl2br($result['comment'])
);
} // foreach
$this->data['continue'] = $this->url->link('account/order', '', 'SSL');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/guest_history.tpl')) {
$this->template = $this->config->get('config_template') . '/template/account/guest_history.tpl';
} else {
$this->template = 'default/template/account/guest_history.tpl';
}
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
} else {
$this->document->setTitle($this->language->get('text_order'));
$this->data['heading_title'] = $this->language->get('text_order');
$this->data['text_error'] = $this->language->get('text_error');
$this->data['button_continue'] = $this->language->get('button_continue');
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_account'),
'href' => $this->url->link('account/account', '', 'SSL'),
'separator' => $this->language->get('text_separator')
);
$this->data['continue'] = $this->url->link('account/order', '', 'SSL');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
$this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
} else {
$this->template = 'default/template/error/not_found.tpl';
}
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
}} // info
private function validate() {
if (!isset($this->request->post['selected']) || !isset($this->request->post['action']) || !$this->request->post['action']) {
$this->error['warning'] = $this->language->get('error_warning');
}
if (!$this->error) {
return true;
} else {
return false;
}
} // validate } ?>
Add another new file to catalog> model> account> guest.php
<?php class ModelAccountGuest extends Model { //public function getOrder($order_id, $email, $ip) { public function getOrder($order_id, $email) {
$order_query = $this->db->query("
SELECT *
FROM `" . DB_PREFIX . "order`
WHERE order_id = '" . (int)$order_id . "'
AND email = '" . $this->db->escape($email) . "'
AND order_status_id > '0'
"); // AND ip = '" . $this->db->escape($ip) . "'
if ($order_query->num_rows) {
$country_query = $this->db->query("
SELECT *
FROM `" . DB_PREFIX . "country`
WHERE country_id = '" . (int)$order_query->row['shipping_country_id'] . "'
");
if ($country_query->num_rows) {
$shipping_iso_code_2 = $country_query->row['iso_code_2'];
$shipping_iso_code_3 = $country_query->row['iso_code_3'];
} else {
$shipping_iso_code_2 = '';
$shipping_iso_code_3 = '';
}
$zone_query = $this->db->query("
SELECT *
FROM `" . DB_PREFIX . "zone`
WHERE zone_id = '" . (int)$order_query->row['shipping_zone_id'] . "'
");
if ($zone_query->num_rows) {
$shipping_zone_code = $zone_query->row['code'];
} else {
$shipping_zone_code = '';
}
$country_query = $this->db->query("
SELECT *
FROM `" . DB_PREFIX . "country`
WHERE country_id = '" . (int)$order_query->row['payment_country_id'] . "'
");
if ($country_query->num_rows) {
$payment_iso_code_2 = $country_query->row['iso_code_2'];
$payment_iso_code_3 = $country_query->row['iso_code_3'];
} else {
$payment_iso_code_2 = '';
$payment_iso_code_3 = '';
}
$zone_query = $this->db->query("
SELECT *
FROM `" . DB_PREFIX . "zone`
WHERE zone_id = '" . (int)$order_query->row['payment_zone_id'] . "'
");
if ($zone_query->num_rows) {
$payment_zone_code = $zone_query->row['code'];
} else {
$payment_zone_code = '';
}
return array(
'order_id' => $order_query->row['order_id'],
'invoice_no' => $order_query->row['invoice_no'],
'invoice_prefix' => $order_query->row['invoice_prefix'],
'store_id' => $order_query->row['store_id'],
'store_name' => $order_query->row['store_name'],
'store_url' => $order_query->row['store_url'],
'customer_id' => $order_query->row['customer_id'],
'firstname' => $order_query->row['firstname'],
'lastname' => $order_query->row['lastname'],
'telephone' => $order_query->row['telephone'],
'fax' => $order_query->row['fax'],
'email' => $order_query->row['email'],
'shipping_firstname' => $order_query->row['shipping_firstname'],
'shipping_lastname' => $order_query->row['shipping_lastname'],
'shipping_company' => $order_query->row['shipping_company'],
'shipping_address_1' => $order_query->row['shipping_address_1'],
'shipping_address_2' => $order_query->row['shipping_address_2'],
'shipping_postcode' => $order_query->row['shipping_postcode'],
'shipping_city' => $order_query->row['shipping_city'],
'shipping_zone_id' => $order_query->row['shipping_zone_id'],
'shipping_zone' => $order_query->row['shipping_zone'],
'shipping_zone_code' => $shipping_zone_code,
'shipping_country_id' => $order_query->row['shipping_country_id'],
'shipping_country' => $order_query->row['shipping_country'],
'shipping_iso_code_2' => $shipping_iso_code_2,
'shipping_iso_code_3' => $shipping_iso_code_3,
'shipping_address_format' => $order_query->row['shipping_address_format'],
'shipping_method' => $order_query->row['shipping_method'],
'payment_firstname' => $order_query->row['payment_firstname'],
'payment_lastname' => $order_query->row['payment_lastname'],
'payment_company' => $order_query->row['payment_company'],
'payment_address_1' => $order_query->row['payment_address_1'],
'payment_address_2' => $order_query->row['payment_address_2'],
'payment_postcode' => $order_query->row['payment_postcode'],
'payment_city' => $order_query->row['payment_city'],
'payment_zone_id' => $order_query->row['payment_zone_id'],
'payment_zone' => $order_query->row['payment_zone'],
'payment_zone_code' => $payment_zone_code,
'payment_country_id' => $order_query->row['payment_country_id'],
'payment_country' => $order_query->row['payment_country'],
'payment_iso_code_2' => $payment_iso_code_2,
'payment_iso_code_3' => $payment_iso_code_3,
'payment_address_format' => $order_query->row['payment_address_format'],
'payment_method' => $order_query->row['payment_method'],
'comment' => $order_query->row['comment'],
'total' => $order_query->row['total'],
'order_status_id' => $order_query->row['order_status_id'],
'language_id' => $order_query->row['language_id'],
'currency_id' => $order_query->row['currency_id'],
'currency_code' => $order_query->row['currency_code'],
'currency_value' => $order_query->row['currency_value'],
'date_modified' => $order_query->row['date_modified'],
'date_added' => $order_query->row['date_added'],
'ip' => $order_query->row['ip']
);
} else {
return false;
}
} // getOrder
public function getOrderProducts($order_id) {
$query = $this->db->query("
SELECT *
FROM " . DB_PREFIX . "order_product
WHERE order_id = '" . (int)$order_id . "'
");
return $query->rows;
} // getOrderProducts
public function getOrderOptions($order_id, $order_product_id) {
$query = $this->db->query("
SELECT *
FROM " . DB_PREFIX . "order_option
WHERE order_id = '" . (int)$order_id . "' AND order_product_id = '" . (int)$order_product_id . "'
");
return $query->rows;
} // getOrderOptions
public function getOrderTotals($order_id) {
$query = $this->db->query("
SELECT *
FROM " . DB_PREFIX . "order_total
WHERE order_id = '" . (int)$order_id . "'
ORDER BY sort_order
");
return $query->rows;
} // getOrderTotals
public function getOrderHistories($order_id) {
$query = $this->db->query("
SELECT date_added, os.name AS status, oh.comment, oh.notify
FROM " . DB_PREFIX . "order_history oh
LEFT JOIN " . DB_PREFIX . "order_status os ON oh.order_status_id = os.order_status_id
WHERE oh.order_id = '" . (int)$order_id . "'
AND os.language_id = '" . (int)$this->config->get('config_language_id') . "'
ORDER BY oh.date_added
"); // AND oh.notify = '1'
return $query->rows;
} // getOrderHistories
public function getOrderDownloads($order_id) {
$query = $this->db->query("
SELECT *
FROM " . DB_PREFIX . "order_download
WHERE order_id = '" . (int)$order_id . "'
ORDER BY name
");
return $query->rows;
} // getOrderDownloads
public function getTotalOrders() {
$query = $this->db->query("
SELECT COUNT(*) AS total
FROM `" . DB_PREFIX . "order`
WHERE customer_id = '" . (int)$this->customer->getId() . "' AND order_status_id > '0'
");
return $query->row['total'];
} // getTotalOrders
public function getTotalOrderProductsByOrderId($order_id) {
$query = $this->db->query("
SELECT COUNT(*) AS total
FROM " . DB_PREFIX . "order_product
WHERE order_id = '" . (int)$order_id . "'
");
return $query->row['total'];
} // getTotalOrderProductsByOrderId } // class ?>
Now add language file to catalog> language> english> account>
<?php // Heading $_['heading_title'] = 'Order Tracking'; // Text $_['text_account'] = 'Account'; // Entry $_['entry_email'] = 'E-Mail Address:'; $_['entry_ip'] = 'IP Address:'; $_['entry_order_id'] = 'Order Number:'; $_['text_err'] = '<span style="color:red;"> <<< </span>'; $_['text_ip'] = 'eg. 123.345.456.678 - Find this on you order email in the \'Order Details\' section:'; $_['text_order_id'] = 'eg. 123 - Find this on you order email in the \'Order Details\' section:'; // Error $_['error_login'] = 'Warning: No match for E-Mail Address and/or Order Number.'; ?>
Now add tlp file to catalog> view> theme> default> template> account> guest_login.tlp with form action and submit button then add this java script:
<script type="text/javascript"><!-- $('#login input').keydown(function(e) {
if (e.keyCode == 13) {
$('#login').submit();
} }); //--></script>
Now add another file to show result. Catalog> view> theme> default> template> account> guest_history.tlp
Checked in OpenCart 1.5.6.3 with custom theme.
Related
Opencart module_id not appending in admin link
I am developing a Opencart module (Version 4.0.0.0). Created the module with height and status. Installed the same in the Opencart application. But the problem is when I tried to save the value to the db, it is creating a new row inside "oc_module" table. While checking I just found that "module_id" is not appending the URL from the module listing page's edit button. The testimonial module link looks like http://localhost/op4/admin/index.php?route=extension/testimonials/module/testimonials&user_token=2e7a4d8fad2e1c4339e9c01bc83d707a extensions --> testimonial --> admin --> controller --> module --> testimonials.php <?php namespace Opencart\Admin\Controller\Extension\Testimonials\Module; class Testimonials extends \Opencart\System\Engine\Controller { public function index(): void { $this->load->language('extension/testimonials/module/testimonials'); $this->document->setTitle($this->language->get('heading_title')); $this->load->model('setting/setting'); $data['breadcrumbs'] = []; $data['breadcrumbs'][] = [ 'text' => $this->language->get('text_home'), 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token']) ]; $data['breadcrumbs'][] = [ 'text' => $this->language->get('text_extension'), 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module') ]; if (!isset($this->request->get['module_id'])) { $data['breadcrumbs'][] = [ 'text' => $this->language->get('heading_title'), 'href' => $this->url->link('extension/testimonials/module/testimonials', 'user_token=' . $this->session->data['user_token']) ]; } else { $data['breadcrumbs'][] = [ 'text' => $this->language->get('heading_title'), 'href' => $this->url->link('extension/testimonials/module/testimonials', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id']) ]; } if (!isset($this->request->get['module_id'])) { $data['save'] = $this->url->link('extension/testimonials/module/testimonials|save', 'user_token=' . $this->session->data['user_token']); } else { $data['save'] = $this->url->link('extension/testimonials/module/testimonials|save', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id']); } $data['back'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module'); if (isset($this->request->get['module_id'])) { $this->load->model('setting/module'); $module_info = $this->model_setting_module->getModule($this->request->get['module_id']); print_r($module_info); } if (isset($module_info['name'])) { $data['name'] = $module_info['name']; } else { $data['name'] = ''; } if (isset($module_info['height'])) { $data['height'] = $module_info['height']; } else { $data['height'] = 200; } if (isset($module_info['status'])) { $data['status'] = $module_info['status']; } else { $data['status'] = ''; } $data['header'] = $this->load->controller('common/header'); $data['column_left'] = $this->load->controller('common/column_left'); $data['footer'] = $this->load->controller('common/footer'); $this->response->setOutput($this->load->view('extension/testimonials/module/testimonials', $data)); } public function save(): void { $this->load->language('extension/testimonials/module/testimonials'); $json = []; if (!$this->user->hasPermission('modify', 'extension/testimonials/module/testimonials')) { $json['error']['warning'] = $this->language->get('error_permission'); } if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) { $json['error']['name'] = $this->language->get('error_name'); } if (!$this->request->post['height']) { $json['error']['height'] = $this->language->get('error_height'); } if (!$json) { $this->load->model('setting/module'); if (!isset($this->request->get['module_id'])) { $this->model_setting_module->addModule('module_testimonials', $this->request->post); } else { $this->model_setting_module->editModule($this->request->get['module_id'], $this->request->post); } $json['success'] = $this->language->get('text_success'); } $this->response->addHeader('Content-Type: application/json'); $this->response->setOutput(json_encode($json)); } }
You have error in your save function. You need to change: $this->model_setting_module->addModule('module_testimonials', $this->request->post); to: $this->model_setting_module->addModule('testimonials.testimonials', $this->request->post);
OpenCart syntax error, unexpected T_VARIABLE, expecting T_FUNCTION
I get this error when someone try to go to checkout in my opencart store: Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in /public_html/vqmod/vqcache/vq2-catalog_model_checkout_order.php on line 197 Here is the like 197 from vq2-catalog_model_checkout_order.php file $order_query = $this->db->query("SELECT *, (SELECT os.name FROM `" . DB_PREFIX . "order_status` os WHERE os.order_status_id = o.order_status_id AND os.language_id = o.language_id) AS order_status FROM `" . DB_PREFIX . "order` o WHERE o.order_id = '" . (int)$order_id . "'"); $category_query = $this->db->query("SELECT cd.name FROM `" . DB_PREFIX . "product_to_category` pc INNER JOIN `" . DB_PREFIX . "category_description` cd ON pc.category_id = cd.category_id WHERE pc.product_id = '" . (int)$product['product_id'] . "' AND cd.language_id = '" . (int)$language_id . "'"); $i = 0; foreach ($category_query->rows as $category) { $i++; if ($i <= 5) { $category_data .= $category['name'] . '/'; } } $category_data = rtrim($category_data, '/'); if ($option_data) { $name = utf8_substr($product['name'] . ' - ' . $option_data, 0, 80); } else { $name = utf8_substr($product['name'], 0, 80); } $products[] = array( 'name' => $name, 'sku' => $product['model'], 'category' => $category_data, 'price' => $this->currency->format($product['price'] + ($this->config->get('config_tax') ? $product['tax'] : 0), false, $order_query->row['currency_value']), 'quantity' => $product['quantity'] ); } return array( 'order_id' => $order_query->row['order_id'], 'store_name' => $order_query->row['store_name'], 'products' => $products, 'total' => $this->currency->format($order_query->row['total'], false, $order_query->row['currency_value']), 'currency_code' => $order_query->row['currency_code'] ); } else { return false; } } $order_query = $this->db->query("SELECT *, (SELECT os.name FROM `" . DB_PREFIX . "order_status` os WHERE os.order_status_id = o.order_status_id AND os.language_id = o.language_id) AS order_status FROM `" . DB_PREFIX . "order` o WHERE o.order_id = '" . (int)$order_id . "'"); if ($order_query->num_rows) { $country_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "country` WHERE country_id = '" . (int)$order_query->row['payment_country_id'] . "'"); if ($country_query->num_rows) { $payment_iso_code_2 = $country_query->row['iso_code_2']; $payment_iso_code_3 = $country_query->row['iso_code_3']; } else { $payment_iso_code_2 = ''; $payment_iso_code_3 = ''; } $zone_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone` WHERE zone_id = '" . (int)$order_query->row['payment_zone_id'] . "'"); if ($zone_query->num_rows) { $payment_zone_code = $zone_query->row['code']; } else { $payment_zone_code = ''; } $country_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "country` WHERE country_id = '" . (int)$order_query->row['shipping_country_id'] . "'"); if ($country_query->num_rows) { $shipping_iso_code_2 = $country_query->row['iso_code_2']; $shipping_iso_code_3 = $country_query->row['iso_code_3']; } else { $shipping_iso_code_2 = ''; $shipping_iso_code_3 = ''; } $zone_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone` WHERE zone_id = '" . (int)$order_query->row['shipping_zone_id'] . "'"); if ($zone_query->num_rows) { $shipping_zone_code = $zone_query->row['code']; } else { $shipping_zone_code = ''; } $this->load->model('localisation/language'); $language_info = $this->model_localisation_language->getLanguage($order_query->row['language_id']);
cart gets empty after adding a product and moving to checkout or cart in opencart
Im having a very strange problem. When i add a product to my shopping cart on top header it shows the cart details/products. But when i click on the cart or checkout it says my cart is empty. So each time when i add the product and move to checkout or cart it automatically becomes empty. I have tried the site on firefox, chrome and in different PCs but still the same problem. But the weird part is when i run firebug and move to the console to see the calls, the site works perfectly. But when i close firebug and refresh the page or move the cart becomes empty again. Can someone tell me what might the problem be? Im using Opencart 1.5.4 Checkout controller function public function index() { // Validate cart has products and has stock. if ((!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) { $this->redirect($this->url->link('checkout/cart')); } // Validate minimum quantity requirments. $products = $this->cart->getProducts(); foreach ($products as $product) { $product_total = 0; foreach ($products as $product_2) { if ($product_2['product_id'] == $product['product_id']) { $product_total += $product_2['quantity']; } } if ($product['minimum'] > $product_total) { $this->redirect($this->url->link('checkout/cart')); } } $this->language->load('checkout/checkout'); $this->document->setTitle($this->language->get('heading_title')); $this->data['breadcrumbs'] = array(); $this->data['breadcrumbs'][] = array( 'text' => $this->language->get('text_home'), 'href' => $this->url->link('common/home'), 'separator' => false ); $this->data['breadcrumbs'][] = array( 'text' => $this->language->get('text_cart'), 'href' => $this->url->link('checkout/cart'), 'separator' => $this->language->get('text_separator') ); $this->data['breadcrumbs'][] = array( 'text' => $this->language->get('heading_title'), 'href' => $this->url->link('checkout/checkout', '', 'SSL'), 'separator' => $this->language->get('text_separator') ); $this->data['heading_title'] = $this->language->get('heading_title'); $this->data['text_checkout_option'] = $this->language->get('text_checkout_option'); $this->data['text_checkout_account'] = $this->language->get('text_checkout_account'); $this->data['text_checkout_payment_address'] = $this->language->get('text_checkout_payment_address'); $this->data['text_checkout_shipping_address'] = $this->language->get('text_checkout_shipping_address'); $this->data['text_checkout_shipping_method'] = $this->language->get('text_checkout_shipping_method'); $this->data['text_checkout_payment_method'] = $this->language->get('text_checkout_payment_method'); $this->data['text_checkout_confirm'] = $this->language->get('text_checkout_confirm'); $this->data['text_modify'] = $this->language->get('text_modify'); $this->data['logged'] = $this->customer->isLogged(); $this->data['shipping_required'] = $this->cart->hasShipping(); if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/checkout/checkout.tpl')) { $this->template = $this->config->get('config_template') . '/template/checkout/checkout.tpl'; } else { $this->template = 'default/template/checkout/checkout.tpl'; } $this->children = array( 'common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header' ); $this->response->setOutput($this->render()); } cart controller public function index() { $this->language->load('checkout/cart'); if (!isset($this->session->data['vouchers'])) { $this->session->data['vouchers'] = array(); } // Update if (!empty($this->request->post['quantity'])) { foreach ($this->request->post['quantity'] as $key => $value) { $this->cart->update($key, $value); } unset($this->session->data['shipping_method']); unset($this->session->data['shipping_methods']); unset($this->session->data['payment_method']); unset($this->session->data['payment_methods']); unset($this->session->data['reward']); $this->redirect($this->url->link('checkout/cart')); } // Remove if (isset($this->request->get['remove'])) { $this->cart->remove($this->request->get['remove']); unset($this->session->data['vouchers'][$this->request->get['remove']]); $this->session->data['success'] = $this->language->get('text_remove'); unset($this->session->data['shipping_method']); unset($this->session->data['shipping_methods']); unset($this->session->data['payment_method']); unset($this->session->data['payment_methods']); unset($this->session->data['reward']); $this->redirect($this->url->link('checkout/cart')); } // Coupon if (isset($this->request->post['coupon']) && $this->validateCoupon()) { $this->session->data['coupon'] = $this->request->post['coupon']; $this->session->data['success'] = $this->language->get('text_coupon'); $this->redirect($this->url->link('checkout/cart')); } // Voucher if (isset($this->request->post['voucher']) && $this->validateVoucher()) { $this->session->data['voucher'] = $this->request->post['voucher']; $this->session->data['success'] = $this->language->get('text_voucher'); $this->redirect($this->url->link('checkout/cart')); } // Reward if (isset($this->request->post['reward']) && $this->validateReward()) { $this->session->data['reward'] = abs($this->request->post['reward']); $this->session->data['success'] = $this->language->get('text_reward'); $this->redirect($this->url->link('checkout/cart')); } // Shipping if (isset($this->request->post['shipping_method']) && $this->validateShipping()) { $shipping = explode('.', $this->request->post['shipping_method']); $this->session->data['shipping_method'] = $this->session->data['shipping_methods'][$shipping[0]]['quote'][$shipping[1]]; $this->session->data['success'] = $this->language->get('text_shipping'); $this->redirect($this->url->link('checkout/cart')); } $this->document->setTitle($this->language->get('heading_title')); $this->data['breadcrumbs'] = array(); $this->data['breadcrumbs'][] = array( 'href' => $this->url->link('common/home'), 'text' => $this->language->get('text_home'), 'separator' => false ); $this->data['breadcrumbs'][] = array( 'href' => $this->url->link('checkout/cart'), 'text' => $this->language->get('heading_title'), 'separator' => $this->language->get('text_separator') ); if ($this->cart->hasProducts() || !empty($this->session->data['vouchers'])) { $points = $this->customer->getRewardPoints(); $points_total = 0; foreach ($this->cart->getProducts() as $product) { if ($product['points']) { $points_total += $product['points']; } } $this->data['heading_title'] = $this->language->get('heading_title'); $this->data['text_next'] = $this->language->get('text_next'); $this->data['text_next_choice'] = $this->language->get('text_next_choice'); $this->data['text_use_coupon'] = $this->language->get('text_use_coupon'); $this->data['text_use_voucher'] = $this->language->get('text_use_voucher'); $this->data['text_use_reward'] = sprintf($this->language->get('text_use_reward'), $points); $this->data['text_shipping_estimate'] = $this->language->get('text_shipping_estimate'); $this->data['text_shipping_detail'] = $this->language->get('text_shipping_detail'); $this->data['text_shipping_method'] = $this->language->get('text_shipping_method'); $this->data['text_select'] = $this->language->get('text_select'); $this->data['text_none'] = $this->language->get('text_none'); $this->data['column_image'] = $this->language->get('column_image'); $this->data['column_name'] = $this->language->get('column_name'); $this->data['column_model'] = $this->language->get('column_model'); $this->data['column_quantity'] = $this->language->get('column_quantity'); $this->data['column_price'] = $this->language->get('column_price'); $this->data['column_total'] = $this->language->get('column_total'); $this->data['entry_coupon'] = $this->language->get('entry_coupon'); $this->data['entry_voucher'] = $this->language->get('entry_voucher'); $this->data['entry_reward'] = sprintf($this->language->get('entry_reward'), $points_total); $this->data['entry_country'] = $this->language->get('entry_country'); $this->data['entry_zone'] = $this->language->get('entry_zone'); $this->data['entry_postcode'] = $this->language->get('entry_postcode'); $this->data['button_update'] = $this->language->get('button_update'); $this->data['button_remove'] = $this->language->get('button_remove'); $this->data['button_coupon'] = $this->language->get('button_coupon'); $this->data['button_voucher'] = $this->language->get('button_voucher'); $this->data['button_reward'] = $this->language->get('button_reward'); $this->data['button_quote'] = $this->language->get('button_quote'); $this->data['button_shipping'] = $this->language->get('button_shipping'); $this->data['button_shopping'] = $this->language->get('button_shopping'); $this->data['button_checkout'] = $this->language->get('button_checkout'); if (isset($this->error['warning'])) { $this->data['error_warning'] = $this->error['warning']; } elseif (!$this->cart->hasStock() && (!$this->config->get('config_stock_checkout') || $this->config->get('config_stock_warning'))) { $this->data['error_warning'] = $this->language->get('error_stock'); } else { $this->data['error_warning'] = ''; } if ($this->config->get('config_customer_price') && !$this->customer->isLogged()) { $this->data['attention'] = sprintf($this->language->get('text_login'), $this->url->link('account/login'), $this->url->link('account/register')); } else { $this->data['attention'] = ''; } if (isset($this->session->data['success'])) { $this->data['success'] = $this->session->data['success']; unset($this->session->data['success']); } else { $this->data['success'] = ''; } $this->data['action'] = $this->url->link('checkout/cart'); if ($this->config->get('config_cart_weight')) { $this->data['weight'] = $this->weight->format($this->cart->getWeight(), $this->config->get('config_weight_class_id'), $this->language->get('decimal_point'), $this->language->get('thousand_point')); } else { $this->data['weight'] = ''; } $this->load->model('tool/image'); $this->data['products'] = array(); $products = $this->cart->getProducts(); foreach ($products as $product) { $product_total = 0; foreach ($products as $product_2) { if ($product_2['product_id'] == $product['product_id']) { $product_total += $product_2['quantity']; } } if ($product['minimum'] > $product_total) { $this->data['error_warning'] = sprintf($this->language->get('error_minimum'), $product['name'], $product['minimum']); } if ($product['image']) { $image = $this->model_tool_image->resize($product['image'], $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height')); } else { $image = ''; } $option_data = array(); foreach ($product['option'] as $option) { if ($option['type'] != 'file') { $value = $option['option_value']; } else { $filename = $this->encryption->decrypt($option['option_value']); $value = utf8_substr($filename, 0, utf8_strrpos($filename, '.')); } $option_data[] = array( 'name' => $option['name'], 'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value) ); } // Display prices if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) { $price = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax'))); } else { $price = false; } // Display prices if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) { $total = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity']); } else { $total = false; } $this->data['products'][] = array( 'key' => $product['key'], 'thumb' => $image, 'name' => $product['name'], 'model' => $product['model'], 'option' => $option_data, 'quantity' => $product['quantity'], 'stock' => $product['stock'] ? true : !(!$this->config->get('config_stock_checkout') || $this->config->get('config_stock_warning')), 'reward' => ($product['reward'] ? sprintf($this->language->get('text_points'), $product['reward']) : ''), 'price' => $price, 'total' => $total, 'href' => $this->url->link('product/product', 'product_id=' . $product['product_id']), 'remove' => $this->url->link('checkout/cart', 'remove=' . $product['key']) ); } // Gift Voucher $this->data['vouchers'] = array(); if (!empty($this->session->data['vouchers'])) { foreach ($this->session->data['vouchers'] as $key => $voucher) { $this->data['vouchers'][] = array( 'key' => $key, 'description' => $voucher['description'], 'amount' => $this->currency->format($voucher['amount']), 'remove' => $this->url->link('checkout/cart', 'remove=' . $key) ); } } if (isset($this->request->post['next'])) { $this->data['next'] = $this->request->post['next']; } else { $this->data['next'] = ''; } $this->data['coupon_status'] = $this->config->get('coupon_status'); if (isset($this->request->post['coupon'])) { $this->data['coupon'] = $this->request->post['coupon']; } elseif (isset($this->session->data['coupon'])) { $this->data['coupon'] = $this->session->data['coupon']; } else { $this->data['coupon'] = ''; } $this->data['voucher_status'] = $this->config->get('voucher_status'); if (isset($this->request->post['voucher'])) { $this->data['voucher'] = $this->request->post['voucher']; } elseif (isset($this->session->data['voucher'])) { $this->data['voucher'] = $this->session->data['voucher']; } else { $this->data['voucher'] = ''; } $this->data['reward_status'] = ($points && $points_total && $this->config->get('reward_status')); if (isset($this->request->post['reward'])) { $this->data['reward'] = $this->request->post['reward']; } elseif (isset($this->session->data['reward'])) { $this->data['reward'] = $this->session->data['reward']; } else { $this->data['reward'] = ''; } $this->data['shipping_status'] = $this->config->get('shipping_status') && $this->config->get('shipping_estimator') && $this->cart->hasShipping(); if (isset($this->request->post['country_id'])) { $this->data['country_id'] = $this->request->post['country_id']; } elseif (isset($this->session->data['shipping_country_id'])) { $this->data['country_id'] = $this->session->data['shipping_country_id']; } else { $this->data['country_id'] = $this->config->get('config_country_id'); } $this->load->model('localisation/country'); $this->data['countries'] = $this->model_localisation_country->getCountries(); if (isset($this->request->post['zone_id'])) { $this->data['zone_id'] = $this->request->post['zone_id']; } elseif (isset($this->session->data['shipping_zone_id'])) { $this->data['zone_id'] = $this->session->data['shipping_zone_id']; } else { $this->data['zone_id'] = ''; } if (isset($this->request->post['postcode'])) { $this->data['postcode'] = $this->request->post['postcode']; } elseif (isset($this->session->data['shipping_postcode'])) { $this->data['postcode'] = $this->session->data['shipping_postcode']; } else { $this->data['postcode'] = ''; } if (isset($this->request->post['shipping_method'])) { $this->data['shipping_method'] = $this->request->post['shipping_method']; } elseif (isset($this->session->data['shipping_method'])) { $this->data['shipping_method'] = $this->session->data['shipping_method']['code']; } else { $this->data['shipping_method'] = ''; } // Totals $this->load->model('setting/extension'); $total_data = array(); $total = 0; $taxes = $this->cart->getTaxes(); // Display prices if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) { $sort_order = array(); $results = $this->model_setting_extension->getExtensions('total'); foreach ($results as $key => $value) { $sort_order[$key] = $this->config->get($value['code'] . '_sort_order'); } array_multisort($sort_order, SORT_ASC, $results); foreach ($results as $result) { if ($this->config->get($result['code'] . '_status')) { $this->load->model('total/' . $result['code']); $this->{'model_total_' . $result['code']}->getTotal($total_data, $total, $taxes); } $sort_order = array(); foreach ($total_data as $key => $value) { $sort_order[$key] = $value['sort_order']; } array_multisort($sort_order, SORT_ASC, $total_data); } } $this->data['totals'] = $total_data; $this->data['continue'] = $this->url->link('common/home'); $this->data['checkout'] = $this->url->link('checkout/checkout', '', 'SSL'); if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/checkout/cart.tpl')) { $this->template = $this->config->get('config_template') . '/template/checkout/cart.tpl'; } else { $this->template = 'default/template/checkout/cart.tpl'; } $this->children = array( 'common/column_left', 'common/column_right', 'common/content_bottom', 'common/content_top', 'common/footer', 'common/header' ); $this->response->setOutput($this->render()); } else { $this->data['heading_title'] = $this->language->get('heading_title'); $this->data['text_error'] = $this->language->get('text_empty'); $this->data['button_continue'] = $this->language->get('button_continue'); $this->data['continue'] = $this->url->link('common/home'); unset($this->session->data['success']); if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) { $this->template = $this->config->get('config_template') . '/template/error/not_found.tpl'; } else { $this->template = 'default/template/error/not_found.tpl'; } $this->children = array( 'common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header' ); $this->response->setOutput($this->render()); } } session library class Session { public $data = array(); public function __construct() { if (!session_id()) { ini_set('session.use_cookies', 'On'); ini_set('session.use_trans_sid', 'Off'); session_set_cookie_params(0, '/'); session_start(); } $this->data =& $_SESSION; } function getId() { return session_id(); } }
It's extremely hard to say, where's the root of the problem. If you have any 3rd party extensions (VQMods), they can change original OpenCart code. In this case you should look in cached files, not original ones. That's for the start.
Opencart Info Page
OK, I have been searching for quite some time, and this has me baffled. I'm trying to add an ad that will pull up more info in the main content section. If you look at http://teachingforapples.com/ , you'll see 2 links below the orange ad on the left. The only difference between those links is the information ID. However, they behave very differently. The one that says 'about' opens inside the main content area, but the one that says 'referral' opens full window. There's nothing in the document content that would change this behavior. The links are made exactly the same in the code except for the ID #. The generated code shows the same kind of link, neither one has a target attrib. I can't find anything in any of the modules that has logic code that looks at the doc id #. So, I started looking at the database. I looked at all the information tables, but don't see anything different between the 2 pages. Can someone point me in the right direction please? I feel that it must be something simple, but I just can't find it. Thanks P.S. the Information module is NOT installed. Here's the information.php file. <?php class ControllerInformationInformation extends Controller { public function index() { $this->language->load('information/information'); $this->load->model('catalog/information'); $this->data['breadcrumbs'] = array(); $this->data['breadcrumbs'][] = array( 'text' => $this->language->get('text_home'), 'href' => $this->url->link('common/home'), 'separator' => false ); if (isset($this->request->get['information_id'])) { $information_id = (int)$this->request->get['information_id']; } else { $information_id = 0; } $information_info = $this->model_catalog_information->getInformation($information_id); if ($information_info) { $this->document->setTitle($information_info['title']); $this->data['breadcrumbs'][] = array( 'text' => $information_info['title'], 'href' => $this->url->link('information/information', 'information_id=' . $information_id), 'separator' => $this->language->get('text_separator') ); $this->data['info_id'] = $information_id; $this->data['heading_title'] = $information_info['title']; $this->data['button_continue'] = $this->language->get('button_continue'); $this->data['description'] = html_entity_decode($information_info['description'], ENT_QUOTES, 'UTF-8'); $this->data['continue'] = $this->url->link('common/home'); if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/information/information.tpl')) { $this->template = $this->config->get('config_template') . '/template/information/information.tpl'; } else { $this->template = 'default/template/information/information.tpl'; } $this->children = array( 'common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header' ); $this->response->setOutput($this->render()); } else { $this->data['breadcrumbs'][] = array( 'text' => $this->language->get('text_error'), 'href' => $this->url->link('information/information', 'information_id=' . $information_id), 'separator' => $this->language->get('text_separator') ); $this->document->setTitle($this->language->get('text_error')); $this->data['heading_title'] = $this->language->get('text_error'); $this->data['text_error'] = $this->language->get('text_error'); $this->data['button_continue'] = $this->language->get('button_continue'); $this->data['continue'] = $this->url->link('common/home'); if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) { $this->template = $this->config->get('config_template') . '/template/error/not_found.tpl'; } else { $this->template = 'default/template/error/not_found.tpl'; } $this->children = array( 'common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header' ); $this->response->setOutput($this->render()); } } public function info() { $this->load->model('catalog/information'); if (isset($this->request->get['information_id'])) { $information_id = (int)$this->request->get['information_id']; } else { $information_id = 0; } $information_info = $this->model_catalog_information->getInformation($information_id); if ($information_info) { $output = '<html dir="ltr" lang="en">' . "\n"; $output .= '<head>' . "\n"; $output .= ' <title>' . $information_info['title'] . '</title>' . "\n"; $output .= ' <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' . "\n"; $output .= ' <meta name="robots" content="noindex">' . "\n"; $output .= '</head>' . "\n"; $output .= '<body>' . "\n"; $output .= ' <h1>' . $information_info['title'] . '</h1>' . "\n"; $output .= html_entity_decode($information_info['description'], ENT_QUOTES, 'UTF-8') . "\n"; $output .= ' </body>' . "\n"; $output .= '</html>' . "\n"; $this->response->setOutput($output); } } } ?>
Add Netsuite Sales order items
I am getting this type of error: => i am getting error in the integration of the netsuite. In sales order add the items in the netsuite so there are some error is define in above section my code is below please see the code add how to solve this problem. [code] => USER_ERROR [message] => You must enter at least one line item for this transaction. [type] => ERRORi am gatting this type of error please help me [code] => USER_ERROR [message] => You must enter at least one line item for this transaction. [type] => ERROR my code is include('NetSuiteService.php'); $service = new NetSuiteService(); if($order_items->netsuitid > 0){ $internal_Id = $order_items->netsuitid; $emailCustomer = $order_items->user_email; } else{ $customer_Info = $order->get_customer_info($order->user_id); $customer_information = array(); foreach($customer_Info as $customer_key => $customer_value){ if($customer_value->meta_key == 'first_name'){ $customer_information['first_name'] = $customer_value->meta_value; } if($customer_value->meta_key == 'last_name'){ $customer_information['last_name'] = $customer_value->meta_value; } } $customer_information['email'] = $customer_Info->user_email; //Add customer into net suit integration $service = new NetSuiteService(); $customer = new Customer(); $customer->lastName = $customer_information['last_name']; $customer->firstName = $customer_information['first_name']; $customer->companyName = 'Company Name'; $customer->phone = '2222222222'; $customer->email = $customer_information['email']; $emailCustomer = $customer_information['email']; $request = new AddRequest(); $request->record = $customer; $addResponse = $service->add($request); if (!$addResponse->writeResponse->status->isSuccess) { echo "You are already Registered with Netsuit."; } else { $internal_Id = $addResponse->writeResponse->baseRef->internalId; $order->insert_Customer($internal_Id,$order->user_id); } //End customer into net suit integration } //Add Product Information /*$items = array(); foreach ( $order_items as $item_id => $item ) { $itemRef = new nsRecordRef(array('internalId'=>$internal_Id)); $qty = $item['qty']; if($item['type'] == 'line_item'){ $salesOrderItemFieldArray = array( "item" => $itemRef, "quantity" => $qty ); } if($item['type'] == 'fee'){ $salesOrderItemFieldArray = array( "item" => $itemRef, "quantity" => $qty ); } $SalesOrderItem->setFields($salesOrderItemFieldArray); $items[] = $SalesOrderItem; } $salesOrderItemList = new nsComplexObject("SalesOrderItemList"); $salesOrderItemList->setFields(array( "item" => $items )); $salesOrderFields = array( "orderStatus" => $order->status, "entity" => '', "getAuth" => true, "shippingCost" => $order->order_shipping, "shipMethod" => $order->payment_method, "toBeEmailed" => true, "email" => $emailCustomer, "itemList" => $salesOrderItemList );*/ $so = new SalesOrder(); //created Date //$so->createdDate = $order->order_date; //entity $so->entity = new RecordRef(); $so->entity->internalId = $internal_Id; $so->entity->name = $order->order_custom_fields['_billing_company'][0]; //Transaction Id //$so->tranId = $order->order_custom_fields['Transaction ID'][0]; //Transaction Paid Date //$so->tranDate = $order->order_custom_fields['_paid_date'][0]; //Source $so->source = 'littlecrate'; //Created From $so->createdFrom = 'littlecrate.com'; //Currency Name require_once('geoplugin.class.php'); $geoplugin = new geoPlugin(); $geoplugin->currency = $order->order_custom_fields['_order_currency']; $so->currencyName = $geoplugin->countryName; $so->currency = $order->order_custom_fields['_order_currency'][0]; //Discount $so->discountRate = $order->order_custom_fields['_order_discount'][0]; //Tax $so->taxRate = $order->order_custom_fields['_order_tax'][0]; //email $so->email = $order->billing_email; //Status //$so->orderStatus = $order->status; //Billing Address $so->billAddressList = array( 'billFirstname' => $order->order_custom_fields['_billing_first_name'][0], 'lastname' => $order->order_custom_fields['_billing_last_name'][0], 'billAddressee' => $order->order_custom_fields['_billing_address_1'][0], 'billAddr1' => $order->order_custom_fields['_billing_address_2'][0], 'billCountry' => $order->order_custom_fields['_billing_country'][0], 'billState' => $order->order_custom_fields['_billing_state'][0], 'billZip' => $order->order_custom_fields['_billing_postcode'][0], 'billPhone' => $order->order_custom_fields['_billing_phone'][0], 'billEmail' => $order->order_custom_fields['_billing_email'][0]); //Shipping Address $so->shipAddressList = array( 'shipFirstname' => $order->order_custom_fields['_shipping_first_name'][0], 'shipLastname' => $order->order_custom_fields['_shipping_last_name'][0], 'shipAddressee' => $order->order_custom_fields['_shipping_address_1'][0], 'shipAddr1' => $order->order_custom_fields['_shipping_address_2'][0], 'shipCity' => $order->order_custom_fields['_shipping_city'][0], 'shipState' => $order->order_custom_fields['_shipping_state'][0], 'shipZip' => $order->order_custom_fields['_shipping_postcode'][0], 'shiplPhone' => $order->order_custom_fields['_billing_phone'][0], 'shipEmail' => $order->order_custom_fields['_billing_email'][0]); //Ship Date //$so->shipDate = $order->order_custom_fields['Transaction ID'][0]; //Shipping Method $so->shipMethod = $order->shipping_method; //Shipping Charges $so->shippingCost = $order->order_shipping; //Shipping Tax Rate $so->shippingTax1Rate = $order->order_shipping_tax; //Payment Method $so->paymentMethod = $order->payment_method; //Sub Total //$so->subTotal = $order->order_total; //Discount Total(Cart Total) //$so->discountTotal = $order->cart_discount; //Tax Total //$so->taxTotal = $order->order_tax; //Total //$so->total = $order->order_total; //Product Listing $arrItemsList = array(); $i = 0; foreach($order_items_product as $keyProduct =>$valueProduct){ if($valueProduct['type'] == 'line_item'){ //$arrItemsList[$i]['item']['internalId'] = $valueProduct['product_id']; //$arrItemsList[$i]['item']['externalId'] = $keyProduct; $arrItemsList[$i]['item']['name'] = $valueProduct['name']; $arrItemsList[$i]['item']['quantity'] = $valueProduct['qty']; $arrItemsList[$i]['item']['description'] = $valueProduct['type']; $arrItemsList[$i]['item']['amount'] = $valueProduct['line_total']; } if($valueProduct['type'] == 'fee'){ //$arrItemsList[$i]['item']['internalId'] = $valueProduct['product_id']; //$arrItemsList[$i]['item']['externalId'] = $keyProduct; $arrItemsList[$i]['item']['name'] = $valueProduct['name']; $arrItemsList[$i]['item']['quantity'] = $valueProduct['qty']; $arrItemsList[$i]['item']['description'] = $valueProduct['type']; $arrItemsList[$i]['item']['amount'] = $valueProduct['line_total']; } $i++; } //print_r($arrItemsList); $so->itemList->item = $arrItemsList; /*$so->itemList = new SalesOrderItemList(); $soi = new SalesOrderItem(); $soi->item = new RecordRef(); $soi->item->internalId = 15; $soi->quantity = 3; $soi->price = new RecordRef(); $soi->price->internalId = $id; $soi->amount = 55.3; $so->itemList->item = array($soi);*/ $request = new AddRequest(); $request->record = $so; //print_r($request); $addResponse = $service->add($request); print_r($addResponse); exit; if (!$addResponse->writeResponse->status->isSuccess) { echo "ADD ERROR"; } else { echo "ADD SUCCESS, id " . $addResponse->writeResponse->baseRef->internalId; } +
I Complited Using The Help Of Saqib, http://stackoverflow.com/users/810555/saqib He is The Great Developer And Regarding Netsuite Information Please Contact To Saqib Thanks Man U Just Do It. <?php $order_date = date('Y-m-d H:i:s'); // create array of fields $itemArr = array(); $i = 0; foreach($order_items_product as $keyProduct =>$valueProduct){ //if you not have internal id of item in netsuuite then please add the item in the netsuite and try. $netsuiteItemId = 'Your Item Internal id Which is in the Netsuite Item'; $itemArr[$i]['item']['internalId'] = $netsuiteItemId; $itemArr[$i]['quantity'] = $valueProduct['qty']; $i++; } if (!define('LF', "\n")) { define('LF', "\n"); } /* for use in formatting custom addresses since NetSuite converts to <br> */ //Billing Address Information /* this example has the customer address info in a db record, just pulled into $row */ $billAddress = stripslashes($order->order_custom_fields['_billing_first_name'][0]) . ' ' . $order->order_custom_fields['_billing_last_name'][0] . LF; $billAddress .= stripslashes($order->order_custom_fields['_billing_address_1'][0]).LF; $billAddress .= stripslashes($order->order_custom_fields['_billing_address_2'][0]).LF; $billAddress .= stripslashes($order->order_custom_fields['_billing_country'][0]).LF; $billAddress .= stripslashes($order->order_custom_fields['_billing_state'][0]) . ' - ' . $order->order_custom_fields['_billing_postcode'][0] . ', ' . LF; $billAddress .= $order->order_custom_fields['_billing_phone'][0] . ', ' . $order->order_custom_fields['_billing_email'][0]; //Shipping Address Information $shipAddress = stripslashes($order->order_custom_fields['_shipping_first_name'][0]) . ' ' . $order->order_custom_fields['_shipping_last_name'][0] . LF; $shipAddress .= stripslashes($order->order_custom_fields['_shipping_address_1'][0]).LF; $shipAddress .= stripslashes($order->order_custom_fields['_shipping_address_2'][0]).LF; $shipAddress .= stripslashes($order->order_custom_fields['_shipping_city'][0]).LF; $shipAddress .= stripslashes($order->order_custom_fields['_shipping_state'][0]) . ', ' . $order->order_custom_fields['_shipping_postcode'][0] . ', ' . LF; $shipAddress .= $order->order_custom_fields['_billing_phone'][0] .', '. $order->order_custom_fields['_billing_email'][0]; $purchaseOrderFields = array ( 'entity' => array ('internalId' => $internal_Id, 'type' => 'customer'), 'shippingCost' => $order->order_shipping, 'shipMethod' => $order->payment_method, 'toBeEmailed' => true, //'tranId' => $order->order_custom_fields['Transaction ID'][0], //'tranDate' => date('Y-m-d H:i:s'), 'source' => 'littlecrate', 'createdFrom' => 'littlecrate.com', 'discountRate' => $order->order_custom_fields['_order_discount'][0], 'taxRate' => $order->order_custom_fields['_order_tax'][0], 'email' => $order->billing_email, //'shipDate' => date('Y-m-d H:i:s'), 'shipMethod' => $order->shipping_method, 'shippingCost' => $order->order_shipping, 'shippingTax1Rate' => $order->order_shipping_tax, 'paymentMethod' => $order->payment_method, //'taxTotal' => $order->order_tax, //'total' => $order->order_total, 'billAddress' => $billAddress, 'shipAddress' => $shipAddress, 'itemList' => array ( 'item' => $itemArr ) ); $salesOrder = new nsComplexObject('SalesOrder'); $salesOrder ->setFields($purchaseOrderFields); $addResponse = $myNSclient->add($salesOrder ); if (!$addResponse->isSuccess) { echo "Order Information is Not Inserted Into The Netsuite. Please Contact to Administration."; exit; } ?>
You item List object doesn't seem in correct format. Your code should look like this $itemArr = array(); foreach($order_items_product as $keyProduct =>$valueProduct){ $item = new SalesOrderItem(); $item->item = $valueProduct['product_id']; $item->quantity = $valueProduct['qty']; $itemArr[] = $item; } $itemList = new SalesOrderItemList(); $itemList->item = $itemArr; $so->itemList->item = $itemList;