How to show category id in confirm order Opencart 2.
Thanks.
You will have to do the following changed.
Open the file catalog/controller/checkout/confirm.php
. Find the line $this->load->model('extension/extension');
and add this after it. $this->load->model('catalog/product');
Replace this
$data['products'][] = array(
'key' => $product['key'],
'product_id' => $product['product_id'],
'name' => $product['name'],
'model' => $product['model'],
'option' => $option_data,
'recurring' => $recurring,
'quantity' => $product['quantity'],
'subtract' => $product['subtract'],
'price' => $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax'))),
'total' => $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity']),
'href' => $this->url->link('product/product', 'product_id=' . $product['product_id']),
);
BY THIS
$cats = $this->model_catalog_product->getCatByProd($product['product_id']);
$prefix = '';
foreach ($cats as $cat){
$categories .= $prefix.$cat['category_id'];
$prefix = ', ';
}
$data['products'][] = array(
'key' => $product['key'],
'product_id' => $product['product_id'],
'categories' => $categories,
'name' => $product['name'],
'model' => $product['model'],
'option' => $option_data,
'recurring' => $recurring,
'quantity' => $product['quantity'],
'subtract' => $product['subtract'],
'price' => $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax'))),
'total' => $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity']),
'href' => $this->url->link('product/product', 'product_id=' . $product['product_id']),
);
OPEN THIS FILE catalog/model/catalog/product.php
. Add this function inside it.
public function getCatByProd($product_id) {
$query = $this->db->query("SELECT category_id FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'");
return $query->rows;
}
OPEN THIS FILE catalog\view\theme\default\template\checkout\confirm.tpl
.
Replace this
<a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a>
BY THIS
<a href="<?php echo $product['href']; ?>"><?php echo $product['name'].' ('.$product['categories'].')'; ?></a>