问题
I want to create an order for a customer in the administration. The customer has certain credit (let's say $200). The order total is calculated like order total - customer's credit = new order total
.
The problem is the customer's credit does not change after creating an order.
For example:
- the order total is:
$500
- credit is:
$200
- then the order total is : $500 - $200 =
$300
- but the customer's credit is still:
$200
Has anybody else had the same problem?
I try to change the status of that order, both processing and setting, but it doesn't work.
The transaction in customer info page does not change.
I have checked the code in backend - there is no code that would operate with oc_customer_transaction
table.
In frontend, there is a function in /catalog/model/total/credit.php
public function confirm($order_info, $order_total) {
$this->language->load('total/credit');
if ($order_info['customer_id']) {
$this->db->query("INSERT INTO " . DB_PREFIX . "customer_transaction SET
customer_id = '" . (int)$order_info['customer_id'] . "',
order_id = '" . (int)$order_info['order_id'] . "',
description = '" . $this->db->escape(
sprintf($this->language->get('text_order_id'),
(int)$order_info['order_id'])) . "',
amount = '" . (float)$order_total['value'] . "',
date_added = NOW()");
}
}
it is called during the checkout process to recalculate customer's credit balance. But I haven't found such code in backend.
回答1:
I already fix that.
code:
$this->db->query("INSERT INTO " . DB_PREFIX . "customer_transaction SET
customer_id = '" . (int)$order_info['customer_id'] . "',
order_id = '" . (int)$order_info['order_id'] . "',
description = '" . $this->db->escape(
sprintf($this->language->get('text_order_id'),
(int)$order_info['order_id'])) . "',
amount = '" . (float)$order_total['value'] . "',
date_added = NOW()");
just add the credit calculate code when at following place:
1./admin/model/sale/order.php addOrder method
a. when you add product to a new customer order in the backend, the system will send request to the frontend (/catalog/checkout/mannual.php index ) wo calculate the order total(such as: subtotal, credit, shipping, total). after this request, order total in the page will be refreshed
b. when you save the order, the (admin/model/sale/order.php) addOrder method will be called eventually. You just need add code above to that function.
insert into..... customer_transaction means use the credit
2./admin/model/sale/order.php editOrder method
a. when you edit a order, the each item in totals will be changed. so, you should delete all credit you used for this order before.
delete * from oc_customer_transaction where 'order_id'=$order_id
b. since the each item of totals(involve credit) has been recalculated in step1, so this method will receive the new credit amount. just insert the new amount by code blow
3.you do not need to change admin/model/sale/order.php deleteOrder method because it delete all totals, include item in the data table oc_customer_transaction
things done!
来源:https://stackoverflow.com/questions/26574510/issue-on-store-credit-of-opencart-1-5-6