我在为OpenCart编写一段代码时遇到了一些麻烦。首先请让我说我真的很感谢任何帮助和支持,我当然不认为这是理所当然的!此外,我对代码的所有经验都是自我辅导所以请原谅我缺乏知识,但你必须从某个地方开始! :)
我的OpenCart安装中有一段代码可以为客户生成发票。
代码如下所示:
foreach ($products as $product) {
$option_data = array();
$options = $this->model_sale_order->getOrderOptions($order_id, $product['order_product_id']);
foreach ($options as $option) {
$option_data[] = array(
'name' => $option['name'],
'value' => $option['value']
);
}
if ($product['tax'] > 0) {
$price_inc = (($product['price'] / 100) * 20);
$prod_tax = (float) $product['tax']."%";
} else {
$price_inc = 0;
$prod_tax = "";
}
$total_inc = $price_inc * $product['quantity'];
$product_data[] = array(
'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']),
'tax' => $prod_tax,
'price_inc' => $this->currency->format($price_inc, $order_info['currency_code'], $order_info['currency_value']),
'total_inc' => $this->currency->format($total_inc, $order_info['currency_code'], $order_info['currency_value'])
);
}
我正在尝试为我们的发票创建一个新字段,如果产品没有增值税则显示字母“Z”,如果产品有增值税则显示字母V.我试图修改代码来声明$ vat_status,但我似乎做错了。
foreach ($products as $product) {
$option_data = array();
$options = $this->model_sale_order->getOrderOptions($order_id, $product['order_product_id']);
foreach ($options as $option) {
$option_data[] = array(
'name' => $option['name'],
'value' => $option['value']
);
}
if ($product['tax'] > 0) {
$price_inc = (($product['price'] / 100) * 20);
$prod_tax = (float) $product['tax']."%";
} else {
$price_inc = 0;
$prod_tax = "";
}
if ($product['tax'] > 0) {
$vat_status = V;
} else {
$vat_status = Z;
}
$total_inc = $price_inc * $product['quantity'];
$product_data[] = array(
'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']),
'tax' => $prod_tax,
'price_inc' => $this->currency->format($price_inc, $order_info['currency_code'], $order_info['currency_value']),
'total_inc' => $this->currency->format($total_inc, $order_info['currency_code'], $order_info['currency_value']),
'vat_status' => $product['vat_status']
);
}
非常感谢任何帮助,我再次为我缺乏知识而道歉。我作为最后的手段来到Stack Overflow:)
答案 0 :(得分:1)
只需更改此行代码
即可'vat_status' => $product['vat_status']
到
'vat_status' => $vat_status
$ product ['vat_status']首先不存在