I am having a little trouble writing a piece of code for OpenCart. First of all please let me say I really do appreciate any help and support offered and I certainly do not take it for granted! Also all of my experience with code is self tutored so please forgive me for my lack of knowledge, but you have to start somewhere! :)
I have a piece of code from my OpenCart installation that generates an invoice for customers.
The code looks like this:
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'])
);
}
I am trying to create a new field for our invoice that displays the letter "Z" if the product has zero VAT and the letter V if the product has vat. I have tried to modify the code to declare $vat_status but I seem to have done something wrong.
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']
);
}
Any help is much appreciated and once again I apologize for my lack of knowledge. I come to Stack Overflow as a last resort :)
- Tom