简体   繁体   中英

OpenCart module on product page based on route

I have set up 2 modules on the left column, one with categories & one with manufacturers, both with their own layouts: product/category & product/manufacturer,

this works fine as it should: when browsing categories, only the category module is shown in the left column, and when browsing manufacturers only the canufacturers module is shown in the left column.

But when checking product details, it will only show modules assigned to the layout "product", and here is where I can't get my head around what to do. If adding layout "product" to both category & manufacturer module, then (of course) both modules are shown, how can add module based on route?

Example Browsing Categorys:

1) Only categories module is shown in the left column (all good here)

index.php?route=product/category&path=33

2) entering product :

index.php?route=product/product&path=33&product_id=31

now all modules assigned to layout "product" is shown, and I just want the module shown when browsing Category (step1) to be shown

Example Browsing Manufacturers:

1) Only Manufacturer module is shown in the left column (all good here)

index.php?route=product/manufacturer

2) entering the same product as in the category example:

index.php?route=product/product&manufacturer_id=9&product_id=31

now all modules assigned to layout "product" is shown, and I just want the module shown when browsing Manufacturers (step1) to be shown

So it's two different routes to the same product:

index.php?route=product/product&path=33&product_id=31
index.php?route=product/product&manufacturer_id=9&product_id=31

But the layout that applys are the one called "product" with route product/product

So is there a way to add those two different routes to two different layouts, so the modules could be shown correctly or Im I thinking the wrong way?

Any input on this would be great

OpenCart 1.5.6

You have some options here. Either You could take a look at the $_SERVER['HTTP_REFERER'] header, which may not be sent (so is not 100% reliable), or You could use session to store the key of where are you coming from... Eg, when listing categories, in category controller do something like:

$this->session->data['user_is_listing'] = 'category';

If The user jumps to the manufacturers listing in manufacturer controller set the same key, different value:

$this->session->data['user_is_listing'] = 'manufacturer';

Then, in column_left controller add a new check for these two modules ( both manufacturer and category modules have to be assigned to the product detail page ) and check what value is stored in session under the key user_is_listing ... Then, either allow the module rendering or not...

EDIT: OK, let's assume that Your own modules have names category1 and manufacturer1 (if You are using the default modules, then the names would be without number 1 ). Now, in column left find the foreach ($extensions as $extension) { loop and we will modify it this way:

    foreach ($extensions as $extension) {
        $modules = $this->config->get($extension['code'] . '_module');

        if ($modules) {
            foreach ($modules as $module) {
                if ($module['layout_id'] == $layout_id && $module['position'] == 'column_left' && $module['status']) {
                    if ($route == 'product/product' && in_array($extension['code'], array('category1', 'manufacturer1'))) {
                        if($this->session->data['user_is_listing'] == $extension['code'])) {
                            $module_data[] = array(
                                'code'       => $extension['code'],
                                'setting'    => $module,
                                'sort_order' => $module['sort_order']
                            );
                        }
                    } else {
                        $module_data[] = array(
                            'code'       => $extension['code'],
                            'setting'    => $module,
                            'sort_order' => $module['sort_order']
                        );
                    }
                }
            }
        }
    }

Now it's necessary that the name stored in the session is the same as the name of that module.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM