I need in each product card on the category page to display the recommended products.

I have the usual open card with a non-standard template. Began to write by hand. I am now trying, by analogy with the file product.tpl, to do the same with category.tpl. In product.tpl I found the line include(......../related.php) . She pulls me the recommended goods. When I use the same in the category.tpl file, I am drawn to all the products that are in the category. And I can not figure out how to fix it.

    1 answer 1

    The answer implies that the so-called. Recommended products are a module that is included and instantiated like any other standard module.

    In opencart to display additional blocks, such as custom html structures, sidebars, sliders and other modules on various pages of the site, there is a separate menu item - Layouts . There you will find a list of all the main site templates. In your case, these are the Category and Product items. Going into them you will find the name of the scheme, the store to which this scheme is designed (for a multi-store), draw schemes, and a set of modules that are additionally connected to the scheme enter image description here

    Here, in the Mодуль list, the required one from the set of дополнения > модули Расположение selected; By default, the OC has 4 modular positions - up / down / left / right. In the .tpl templates, the variables $column_right; $column_left; $content_top; $content_bottom; $column_right; $column_left; $content_top; $content_bottom; The modules in them are displayed in a list in accordance with the sorting specified in the Порядок сортировки (by default, in the order of addition)

    UPD:

    Adding "recommended" from the product card to the catalog

    The section of the " Recommended " product card is formed as follows:

     #catalog/controller/product/product.php: $data['products'] = array();//->$products $results = $this->model_catalog_product->getProductRelated($this->request->get['product_id']); foreach ($results as $result) { #... code ... #... code ... $data['products'][] = array( 'product_id' => $result['product_id'], #... code ... #... code ... ); } #catalog/view/theme/default(your_theme)/product/product.tpl: <?php if ($products) { ?> 

    Actually, part of the product controller must be inserted into the product formation cycle in the category catalog controller (by slightly changing):

     #catalog/controller/product/category.php: #straight before this peace of code: $data['products'][] = array( 'sort_order' => $result['sort_order'], 'product_id' => $result['product_id'], #... code ... #... code ... ) #put this spell: $related_to = array(); $related_to_results = $this->model_catalog_product->getProductRelated($this->request->get['product_id']); foreach ($results as $result) { #... code ... #... code ... $related_to = array( 'product_id' => $result['product_id'], #repeat all the code ); } #and finally add this to $data['products'][]: $data['products'][] = array( 'sort_order' => $result['sort_order'], 'product_id' => $result['product_id'], #... code ... #... code ... 'related' => $related_to//<------- ) 

    As a result, in catalog/view/theme/dafault(your_theme)/category.tpl , in the <?php foreach ($products as $product) { ?> catalog/view/theme/dafault(your_theme)/category.tpl , an array of products recommended in this $ product ['related'] will be available . Expand through foreach, salt to taste, bring to readiness.

    • Not exactly what I need. I was wrong. This is called similar products in the product card itself. and these products are displayed in the card itself, but I need to withdraw these products for each product on the category page - Alexey Pukh
    • @ Aleksey Pooh I wrote you a recipe. For the page "cattery" everything is exactly the same. - Kirill Korushkin
    • I probably poorly described the task. I do NOT need to display somewhere on the category page recommended products that I manually added to this module. When I fill the site with goods, I fill in the value of many attributes of the goods and in the connection tab at the very bottom there is an item similar products. I have the opportunity to add products to it very easily and when I switch to the product card on the site I see the main product and similar products. - Aleksey Pooh
    • and now I want that when I enter a category, I have seen a lot of goods in a category (this is of course already implemented by default), but in each of these products (without going into the product card itself) I also want to see (before the button to buy for example) those similar products (but only links) that I can see by going to the product card itself - Aleksey Pukha
    • Tried to rewrite the code of category files by analogy with the product files. Not yet received - Alexey Pooh