-1

How to show category id in confirm order Opencart 2.

Thanks.

image here

  • To avoid a bad start in the Stack Overflow community I recommend you to review [How do i ask a good question?] . Good questions brings good answers, unfortunately your question might be seem clear to you but it is not really. – Takoyaro Jun 11 '16 at 14:28

1 Answers1

0

You will have to do the following changed.

  1. 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');

  2. 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']),
    );
  1. 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;
    }
    
  2. 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>
Ali Zia
  • 3,825
  • 5
  • 29
  • 77