Jump to content

Get products ID's from listing pages


Konrad B.

Recommended Posts

Hi,
i need to integrate some code for sales tracking purposes. It needs to be inserted in the body section. So i putted it into /themes/my-theme/templates/_partials/header.tpl at the top.

It looks like in attachment (i was blocked while trying create topic with that code inserted as plain text or as code).

My questions refer to the last section in the code dealing with category pages:
1. How can i get an array of products ID's from category pages (there's infinite scroll) in line: 'products' : '{/literal}['productId1','productId2','productId3']{literal}'
2. is there any simplier/better method to get 'categoryId' from category pages than: '{$smarty.get.id_category}'?

code.jpg

Link to comment
Share on other sites

Dnia 22.03.2024 o 10:50 AM, Konrad B. napisał:

Hi,
i need to integrate some code for sales tracking purposes. It needs to be inserted in the body section. So i putted it into /themes/my-theme/templates/_partials/header.tpl at the top.

It looks like in attachment (i was blocked while trying create topic with that code inserted as plain text or as code).

My questions refer to the last section in the code dealing with category pages:
1. How can i get an array of products ID's from category pages (there's infinite scroll) in line: 'products' : '{/literal}['productId1','productId2','productId3']{literal}'
2. is there any simplier/better method to get 'categoryId' from category pages than: '{$smarty.get.id_category}'?

code.jpg

You will have to do it with module because category pages are using ProductListingController. Then you will be able to acess products by hooking into actionProductSearchAfter. After that you can return one single smarty variable.

Here is part of this controller.
 

        $searchVariables = [
            'result' => $result,
            'label' => $this->getListingLabel(),
            'products' => $products,
            'sort_orders' => $sort_orders,
            'sort_selected' => $sort_selected,
            'pagination' => $pagination,
            'rendered_facets' => $rendered_facets,
            'rendered_active_filters' => $rendered_active_filters,
            'js_enabled' => $this->ajax,
            'current_url' => $this->updateQueryString([
                'q' => $result->getEncodedFacets(),
            ]),
        ];

        Hook::exec('filterProductSearch', ['searchVariables' => &$searchVariables]);
        Hook::exec('actionProductSearchAfter', $searchVariables);

        return $searchVariables;

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...