如果在opencart结帐页面中选中此复选框,则希望向“总计”中添加一些费用
以下是我要更改的代码。如果选择了付款方式“ COD”,则此代码会增加费用。
<?php
class ModelExtensionTotalCashonDeliveryFee extends Model {
public function getTotal($total) {
if ($this->config->get('cashon_delivery_fee_status') && isset($this->session->data['payment_method']) && $this->session->data['payment_method']['code'] == 'cod') {
$this->load->language('extension/total/cashon_delivery_fee');
$fee_amount = 0;
$sub_total = $this->cart->getSubTotal();
if($this->config->get('cashon_delivery_fee_type') == 'P') {
$fee_amount = round((($sub_total * $this->config->get('cashon_delivery_fee_fee')) / 100), 2);
} else {
$fee_amount = $this->config->get('cashon_delivery_fee_fee');
}
$tax_rates = $this->tax->getRates($fee_amount, $this->config->get('cashon_delivery_fee_tax_class_id'));
foreach ($tax_rates as $tax_rate) {
if (!isset($taxes[$tax_rate['tax_rate_id']])) {
$taxes[$tax_rate['tax_rate_id']] = $tax_rate['amount'];
} else {
$taxes[$tax_rate['tax_rate_id']] += $tax_rate['amount'];
}
}
$total['totals'][] = array(
'code' => 'cashon_delivery_fee',
'title' => $this->language->get('text_cashon_delivery_fee'),
'value' => $fee_amount,
'sort_order' => $this->config->get('cashon_delivery_fee_sort_order')
);
$total['total'] += $fee_amount;
}
}
}
我希望它在.tpl中选中<input type="checkbox" name="checkbox">COD Charges
的输入复选框时增加费用
而不是选择“ cod”付款方式。
答案 0 :(得分:0)
您不能通过单击复选框将数据直接添加到模型文件中。首先,您需要像以下这样调用此数据:
在将复选框放置到复选框标记的模板文件中,添加id="{{ order_id }}
在此模板文件或其他javascript文件中添加以下脚本:
var checkbox = document.getElementById(product_id);
if (checkbox.checked == true) {
addFee(product_id);
//another stuff if you need
}
接下来,您需要在相应的控制器文件创建函数中,例如add_fee
,在其中您可以根据发布的product_id
从数据库中调用数据,还可以像这样$this->session->data['fee'] = $some_fee_from_DB
那样将这些数据包括到当前会话中。
在相应的模板文件或其他javascript文件中,添加ajax函数,例如addFee
:
function addFee(product_id) {
$.ajax({
type: 'post',
url: 'index.php?route=link_to_your_function/add_fee',
data: 'product_id=' + product_id,
dataType: 'json',
success: function(json) {
$('#fee').html(json['fee']); // and all other data which will be returned.
if (json['success']) {
//some stuff on success what you need to be displayed or filled up to the corresponding fields.
}
}
});
}
然后,您将可以使用$this->session->data['fee']
在您提到的模型文件中检索数据。这不是完整的东西,仅仅是您需要做的事情。