Post by eddy-r3 » Tue Oct 10, 2017 6:01 am

Hi guys, i followed a quick guide on getting a category to display in the checkout, and although it worked great, its not showing parent categories, and only the sub category the product is in, here is the code :

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<modification>
    <name>Category_Cart</name>
    <version>1.0</version>
    <code>Category_Cart</code>
    <author>A2bizz</author>
    <link>http://blog.a2bizz.com</link>
    <file path="catalog/view/theme/*/template/checkout/cart.tpl">
        <operation>
            <search><![CDATA[
           <td class="text-left"><?php echo $column_name; ?></td>
            ]]></search>
            <add position="after" offset="0"><![CDATA[
            <td class="text-left"><?php echo $column_category; ?></td>
            ]]></add>
        </operation>
         <operation>
            <search><![CDATA[
           <td class="text-left"><?php echo $product['model']; ?></td>
            ]]></search>
            <add position="before" offset="0"><![CDATA[
            <td class="text-left"><?php echo $product['category_name']; ?></td>
            ]]></add>
        </operation>
    </file>
    <file path="catalog/controller/checkout/cart.php">
        <operation>
            <search><![CDATA[
           $data['column_name'] = $this->language->get('column_name');
            ]]></search>
            <add position="after" offset="0"><![CDATA[
            $data['column_category'] = $this->language->get('column_category');
            ]]></add>
        </operation>
         <operation>
            <search><![CDATA[
           $this->load->model('tool/upload');
            ]]></search>
            <add position="after" offset="0"><![CDATA[
            $this->load->model('catalog/custom');
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[
           $product_total = 0;
            ]]></search>
            <add position="before" offset="0"><![CDATA[
            $category_name = $this->model_catalog_custom->getproductcategory($product['product_id']);
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[
           'name'      => $product['name'],
            ]]></search>
            <add position="after" offset="0"><![CDATA[
            'category_name'=>$category_name,
            ]]></add>
        </operation>
    </file>
     <file path="catalog/language/*/checkout/cart.php">
        <operation>
            <search><![CDATA[
           $_['column_name']              = 'Product Name';
            ]]></search>
            <add position="after" offset="0"><![CDATA[
            $_['column_category']              = 'Product Category';
            ]]></add>
        </operation>
    </file>
</modification>

Code: Select all

<?php
class ModelCatalogCustom extends Model {
    public function getproductcategory($product_id){
        $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'");
        $category = $this->getCategory($query->row['category_id']);
        return $category['name'];
    }

    public function getCategory($category_id) {
        $query = $this->db->query("SELECT DISTINCT *, (SELECT GROUP_CONCAT(cd1.name ORDER BY level SEPARATOR '&nbsp;&nbsp;&gt;&nbsp;&nbsp;') FROM " . DB_PREFIX . "category_path cp LEFT JOIN " . DB_PREFIX . "category_description cd1 ON (cp.path_id = cd1.category_id AND cp.category_id != cp.path_id) WHERE cp.category_id = c.category_id AND cd1.language_id = '" . (int)$this->config->get('config_language_id') . "' GROUP BY cp.category_id) AS path, (SELECT DISTINCT keyword FROM " . DB_PREFIX . "url_alias WHERE query = 'category_id=" . (int)$category_id . "') AS keyword FROM " . DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_description cd2 ON (c.category_id = cd2.category_id) WHERE c.category_id = '" . (int)$category_id . "' AND cd2.language_id = '" . (int)$this->config->get('config_language_id') . "'");

        return $query->row;
    }
}
Id like to show parent categories as well as the child category the product is in, any ideas? :)

Also, ive had some "DEBUG1" and "DEBUG2" text appear on my product pages, would this be caused by this mod?

Many thanks,

Active Member

Posts

Joined
Tue Jan 31, 2012 4:46 am

Post by eddy-r3 » Thu Oct 12, 2017 6:53 pm

Hate to bump, but anyone? :)

Active Member

Posts

Joined
Tue Jan 31, 2012 4:46 am

Post by IP_CAM » Fri Oct 13, 2017 3:35 am

Well, I am not a real Coder, but since Products 'linkwise' don't strictly require
to carry a category as part of their link url, you require a controller-routine,
similar to the one, used in this V.2 full breadcrumbs display Mod, to make
it work, I assume. It would probably have to be placed in the checkout.php
controller File, if it is to be used there, I guess...
Good Luck ! ;)
Ernie
---
Category Breadcrumb Long Path [VQMod] opencart 2
https://www.opencart.com/index.php?rout ... n_id=27407
---
Image

My Github OC Site: https://github.com/IP-CAM
5'200 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland
Who is online

Users browsing this forum: No registered users and 88 guests