@@ -260,51 +260,64 @@ protected function getViewedProducts()
260260 {
261261 $ productIds = $ this ->getViewedProductIds ();
262262
263- if (!empty ($ productIds )) {
264- $ assembler = new ProductAssembler ($ this ->context );
265-
266- $ presenterFactory = new ProductPresenterFactory ($ this ->context );
267- $ presentationSettings = $ presenterFactory ->getPresentationSettings ();
268- if (version_compare (_PS_VERSION_ , '1.7.5 ' , '>= ' )) {
269- $ presenter = new \PrestaShop \PrestaShop \Adapter \Presenter \Product \ProductListingPresenter (
270- new ImageRetriever (
271- $ this ->context ->link
272- ),
273- $ this ->context ->link ,
274- new PriceFormatter (),
275- new ProductColorsRetriever (),
276- $ this ->context ->getTranslator ()
277- );
278- } else {
279- $ presenter = new \PrestaShop \PrestaShop \Core \Product \ProductListingPresenter (
280- new ImageRetriever (
281- $ this ->context ->link
282- ),
283- $ this ->context ->link ,
284- new PriceFormatter (),
285- new ProductColorsRetriever (),
286- $ this ->context ->getTranslator ()
287- );
288- }
263+ if (empty ($ productIds )) {
264+ return false ;
265+ }
266+
267+ $ assembler = new ProductAssembler ($ this ->context );
268+
269+ $ presenterFactory = new ProductPresenterFactory ($ this ->context );
270+ $ presentationSettings = $ presenterFactory ->getPresentationSettings ();
271+ if (version_compare (_PS_VERSION_ , '1.7.5 ' , '>= ' )) {
272+ $ presenter = new \PrestaShop \PrestaShop \Adapter \Presenter \Product \ProductListingPresenter (
273+ new ImageRetriever (
274+ $ this ->context ->link
275+ ),
276+ $ this ->context ->link ,
277+ new PriceFormatter (),
278+ new ProductColorsRetriever (),
279+ $ this ->context ->getTranslator ()
280+ );
281+ } else {
282+ $ presenter = new \PrestaShop \PrestaShop \Core \Product \ProductListingPresenter (
283+ new ImageRetriever (
284+ $ this ->context ->link
285+ ),
286+ $ this ->context ->link ,
287+ new PriceFormatter (),
288+ new ProductColorsRetriever (),
289+ $ this ->context ->getTranslator ()
290+ );
291+ }
292+
293+ // Now, we can present the products for the template.
294+ $ products_for_template = [];
289295
290- $ products_for_template = [];
291-
292- if (is_array ($ productIds )) {
293- foreach ($ productIds as $ productId ) {
294- if ($ this ->currentProductId !== $ productId ) {
295- $ products_for_template [] = $ presenter ->present (
296- $ presentationSettings ,
297- $ assembler ->assembleProduct (['id_product ' => $ productId ]),
298- $ this ->context ->language
299- );
300- }
296+ if (is_array ($ productIds )) {
297+ // Prepare a standardized array with products
298+ $ rawProducts = [];
299+ foreach ($ productIds as $ productId ) {
300+ if ($ this ->currentProductId == $ productId ) {
301+ continue ;
301302 }
303+ $ rawProducts [] = ['id_product ' => $ productId ];
302304 }
303305
304- return $ products_for_template ;
306+ // Assemble & present in bulk or separately, depending on core version
307+ $ assembleInBulk = method_exists ($ assembler , 'assembleProducts ' );
308+ if ($ assembleInBulk ) {
309+ $ rawProducts = $ assembler ->assembleProducts ($ rawProducts );
310+ }
311+ foreach ($ rawProducts as $ rawProduct ) {
312+ $ products_for_template [] = $ presenter ->present (
313+ $ presentationSettings ,
314+ ($ assembleInBulk ? $ rawProduct : $ assembler ->assembleProduct ($ rawProduct )),
315+ $ this ->context ->language
316+ );
317+ }
305318 }
306319
307- return false ;
320+ return $ products_for_template ;
308321 }
309322
310323 /**
0 commit comments