当我在模板文件中回显$ test_text时,正在调用以下函数。
Php也不再对我大吼大叫,但“订单”没有处理。
public function process_cart() {
$this->load->model('sale/order');
$this->data['test_text'] = "I'm here."
$order_details = array(
'store_id' => 1,
'customer_id' => $this->address['customer_id'],
'customer_group_id' => 1,
'firstname' => $this->address['firstname'],
'lastname' => $this->address['lastname'],
'email' => $this->address['email'],
'telephone' => $this->address['telephone'],
'fax' => $this->address['fax'],
'payment_firstname' => $this->address['firstname'],
'payment_lastname' => $this->address['lastname'],
'payment_company' => '',
'payment_company_id' => '',
'payment_tax_id' => '',
'payment_address_1' => '',
'payment_address_2' => '',
'payment_city' => '',
'payment_postcode' => '',
'payment_country_id' => '',
'payment_zone_id' => '',
'payment_method' => '',
'payment_code' => '',
'shipping_firstname' => '',
'shipping_lastname' => '',
'shipping_company' => '',
'shipping_address_1' => '',
'shipping_address_2' => '',
'shipping_city' => '',
'shipping_postcode' => '',
'shipping_country_id' => '',
'shipping_zone_id' => '',
'shipping_method' => '',
'shipping_code' => '',
'comment' => '',
'order_status_id' => 1,
'affiliate_id' => '',
'products' => $this->data['products']
);
$this->model_sale_order->addOrder($order_details);
}
任何人都能看到我错过的东西吗?
答案 0 :(得分:2)
$order_id = $this->db->getLastId();
foreach ($data['products'] as $product) {
$this->db->query("INSERT INTO " . DB_PREFIX . "order_product SET
order_id = '" . (int)$order_id . "',
product_id = '" . (int)$product['product_id'] . "',
name = '" . $this->db->escape($product['name']) . "',
model = '" . $this->db->escape($product['model']) . "',
quantity = '" . (int)$product['quantity'] . "',
price = '" . (float)$product['price'] . "',
total = '" . (float)$product['total'] . "',
tax = '" . (float)$product['tax'] . "',
reward = '" . (int)$product['reward'] . "'");
$order_product_id = $this->db->getLastId();
foreach ($product['option'] as $option) {
$this->db->query("INSERT INTO " . DB_PREFIX . "order_option SET
order_id = '" . (int)$order_id . "',
order_product_id = '" . (int)$order_product_id . "',
product_option_id = '" . (int)$option['product_option_id'] . "',
product_option_value_id = '" . (int)$option['product_option_value_id'] . "',
name = '" . $this->db->escape($option['name']) . "',
`value` = '" . $this->db->escape($option['value']) . "',
`type` = '" . $this->db->escape($option['type']) . "'");
}
foreach ($product['download'] as $download) {
$this->db->query("INSERT INTO " . DB_PREFIX . "order_download SET
order_id = '" . (int)$order_id . "',
order_product_id = '" . (int)$order_product_id . "',
name = '" . $this->db->escape($download['name']) . "',
filename = '" . $this->db->escape($download['filename']) . "',
mask = '" . $this->db->escape($download['mask']) . "',
remaining = '" . (int)($download['remaining'] * $product['quantity']) . "'");
}
}
foreach ($data['vouchers'] as $voucher) {
$this->db->query("INSERT INTO " . DB_PREFIX . "order_voucher SET
order_id = '" . (int)$order_id . "',
description = '" . $this->db->escape($voucher['description']) . "',
code = '" . $this->db->escape($voucher['code']) . "',
from_name = '" . $this->db->escape($voucher['from_name']) . "',
from_email = '" . $this->db->escape($voucher['from_email']) . "',
to_name = '" . $this->db->escape($voucher['to_name']) . "',
to_email = '" . $this->db->escape($voucher['to_email']) . "',
voucher_theme_id = '" . (int)$voucher['voucher_theme_id'] . "',
message = '" . $this->db->escape($voucher['message']) . "',
amount = '" . (float)$voucher['amount'] . "'");
}
foreach ($data['totals'] as $total) {
$this->db->query("INSERT INTO " . DB_PREFIX . "order_total SET
order_id = '" . (int)$order_id . "',
code = '" . $this->db->escape($total['code']) . "',
title = '" . $this->db->escape($total['title']) . "',
text = '" . $this->db->escape($total['text']) . "',
`value` = '" . (float)$total['value'] . "',
sort_order = '" . (int)$total['sort_order'] . "'");
}
return $order_id;
尝试在现有代码之后添加一个。