SimonBru Posted July 12, 2019 Share Posted July 12, 2019 (edited) Hi, I am developping a recommender system module and would like to use prestashop related products module for recommended products display. However, I am struggling with the documentation for data structure to pass this template. Actually, I am loading my products like that: $products = array(); foreach($recommendations as $recommendation) { array_push($products, (array) new Product($recommendation['id_product'], false, '1')); } And pass that $products variable to the template: "module:ptsrelatedproducts/views/templates/hook/ptsrelatedproducts.tpl". It displays some products but with a lot of missing information like images, links, js events, etc. Does anyone know how to reuse that template ? Which datatype should I send in the $products array ? Is there any reusable function to format that data ? I am working on prestashop 1.7.1 Thanks in advance Simon Edited July 12, 2019 by SimonBru resolved (see edit history) Link to comment Share on other sites More sharing options...
SimonBru Posted July 12, 2019 Author Share Posted July 12, 2019 I found a solution to my problem, by digging into the PtsRelatedProducts class, i took some code of the getCategoryProducts function. The part of code in the original code is not needed anymore, this function formats data to be passed to the module:ptsrelatedproducts/views/templates/hook/ptsrelatedproducts.tpl template. /** * @param array $products an array with product id [ 'id_product' => 1 ....] */ private function getProducts($products) { $assembler = new ProductAssembler($this->context); $presenterFactory = new ProductPresenterFactory($this->context); $presentationSettings = $presenterFactory->getPresentationSettings(); $presenter = new ProductListingPresenter( new ImageRetriever( $this->context->link ), $this->context->link, new PriceFormatter(), new ProductColorsRetriever(), $this->context->getTranslator() ); foreach ($products as $rawProduct) { $productsForTemplate[] = $presenter->present( $presentationSettings, $assembler->assembleProduct($rawProduct), $this->context->language ); } return $productsForTemplate; } 1 Link to comment Share on other sites More sharing options...
BC17 Posted August 17, 2022 Share Posted August 17, 2022 Hi Simon, Thanks you very much for sharing this code, this helped me a lot. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now