Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
uses: actions/checkout@v2.0.0

- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: vendor
key: php-${{ hashFiles('composer.lock') }}
Expand Down Expand Up @@ -70,14 +70,14 @@ jobs:

# Add vendor folder in cache to make next builds faster
- name: Cache vendor folder
uses: actions/cache@v1
uses: actions/cache@v4
with:
path: vendor
key: php-${{ hashFiles('composer.lock') }}

# Add composer local folder in cache to make next builds faster
- name: Cache composer folder
uses: actions/cache@v1
uses: actions/cache@v4
with:
path: ~/.composer/cache
key: php-composer-cache
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,25 @@

Display a kind of showcase on your product pages with recently viewed products.

## Compatibility

PrestaShop: `1.7.0.0` or later

## Multistore compatibility

This module is compatible with the multistore :heavy_check_mark: <br/>
It can be configured differently from one store to another.<br/>
It can be configured quickly in the same way on all stores thanks to the all shops context or the group of shops.<br/>
It can be activated on one store and deactivated on another

## How to test

Link to specs : https://docs.prestashop-project.org/functional-documentation/functional-documentation/ux-ui/back-office/improve/modules/viewed-products-block

Check on the Homepage that the “Viewed products” block is well displayed.
On BO, configure the number of products to display.
Make sure the module is hooked to displayFooterProduct.

## Reporting issues

You can report issues with this module in the main PrestaShop repository. [Click here to report an issue][report-issue].
Expand Down
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>ps_viewedproduct</name>
<displayName><![CDATA[Viewed products block]]></displayName>
<version><![CDATA[1.2.4]]></version>
<version><![CDATA[1.2.5]]></version>
<description><![CDATA[Adds a block displaying recently viewed products.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[front_office_features]]></tab>
Expand Down
93 changes: 53 additions & 40 deletions ps_viewedproduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct()
{
$this->name = 'ps_viewedproduct';
$this->author = 'PrestaShop';
$this->version = '1.2.4';
$this->version = '1.2.5';
$this->tab = 'front_office_features';
$this->need_instance = 0;

Expand Down Expand Up @@ -260,51 +260,64 @@ protected function getViewedProducts()
{
$productIds = $this->getViewedProductIds();

if (!empty($productIds)) {
$assembler = new ProductAssembler($this->context);

$presenterFactory = new ProductPresenterFactory($this->context);
$presentationSettings = $presenterFactory->getPresentationSettings();
if (version_compare(_PS_VERSION_, '1.7.5', '>=')) {
$presenter = new \PrestaShop\PrestaShop\Adapter\Presenter\Product\ProductListingPresenter(
new ImageRetriever(
$this->context->link
),
$this->context->link,
new PriceFormatter(),
new ProductColorsRetriever(),
$this->context->getTranslator()
);
} else {
$presenter = new \PrestaShop\PrestaShop\Core\Product\ProductListingPresenter(
new ImageRetriever(
$this->context->link
),
$this->context->link,
new PriceFormatter(),
new ProductColorsRetriever(),
$this->context->getTranslator()
);
}
if (empty($productIds)) {
return false;
}

$assembler = new ProductAssembler($this->context);

$presenterFactory = new ProductPresenterFactory($this->context);
$presentationSettings = $presenterFactory->getPresentationSettings();
if (version_compare(_PS_VERSION_, '1.7.5', '>=')) {
$presenter = new \PrestaShop\PrestaShop\Adapter\Presenter\Product\ProductListingPresenter(
new ImageRetriever(
$this->context->link
),
$this->context->link,
new PriceFormatter(),
new ProductColorsRetriever(),
$this->context->getTranslator()
);
} else {
$presenter = new \PrestaShop\PrestaShop\Core\Product\ProductListingPresenter(
new ImageRetriever(
$this->context->link
),
$this->context->link,
new PriceFormatter(),
new ProductColorsRetriever(),
$this->context->getTranslator()
);
}

// Now, we can present the products for the template.
$products_for_template = [];

$products_for_template = [];

if (is_array($productIds)) {
foreach ($productIds as $productId) {
if ($this->currentProductId !== $productId) {
$products_for_template[] = $presenter->present(
$presentationSettings,
$assembler->assembleProduct(['id_product' => $productId]),
$this->context->language
);
}
if (is_array($productIds)) {
// Prepare a standardized array with products
$rawProducts = [];
foreach ($productIds as $productId) {
if ($this->currentProductId == $productId) {
continue;
}
$rawProducts[] = ['id_product' => $productId];
}

return $products_for_template;
// Assemble & present in bulk or separately, depending on core version
$assembleInBulk = method_exists($assembler, 'assembleProducts');
if ($assembleInBulk) {
$rawProducts = $assembler->assembleProducts($rawProducts);
}
foreach ($rawProducts as $rawProduct) {
$products_for_template[] = $presenter->present(
$presentationSettings,
($assembleInBulk ? $rawProduct : $assembler->assembleProduct($rawProduct)),
$this->context->language
);
}
}

return false;
return $products_for_template;
}

/**
Expand Down
File renamed without changes.
Loading