gpt4 book ai didi

php - 通过 OpenCart addOrder 方法处理订单

转载 作者:搜寻专家 更新时间:2023-10-31 21:09:19 25 4
gpt4 key购买 nike

当我在模板文件中回显 $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);
}

谁能看到我错过了什么?

最佳答案

$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;

尝试在现有代码之后添加这个。

关于php - 通过 OpenCart addOrder 方法处理订单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24792053/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com