Review rating count not updating unless index is rebuilt
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Review rating count not updating unless index is rebuilt
Laravel framework version: 9.52.4
Aimeos Laravel version: ~2022.10
PHP Version: 8.2.4
Environment: Linux
Steps to reproduce:
1) Use ElasticSearch index
2) Add a review to a product
3) Publish the review from the administration
4) The review rating count is not updated in the frontend
5) php artisan aimeos:jobs index/rebuild
6) Review rating count is updated in the frontend
The code I use to get the count of ratings:
$this->detailProductItem->getRatings()
Aimeos Laravel version: ~2022.10
PHP Version: 8.2.4
Environment: Linux
Steps to reproduce:
1) Use ElasticSearch index
2) Add a review to a product
3) Publish the review from the administration
4) The review rating count is not updated in the frontend
5) php artisan aimeos:jobs index/rebuild
6) Review rating count is updated in the frontend
The code I use to get the count of ratings:
$this->detailProductItem->getRatings()
Re: Review rating count not updating unless index is rebuilt
There had been two problems:
- The admin backend used only the product manager to update the ratings, not the index manager
- The ElasticIndex class didn't forward the new rating to the product manager
This has been fixed and new 2022.10.x versions of the aimeos/ai-admin-jqadm and aimeoscom/ai-elastic packages have been released. If you use 2023.04+, use the ".x-dev" version instead until new minor releases are available.
- The admin backend used only the product manager to update the ratings, not the index manager
- The ElasticIndex class didn't forward the new rating to the product manager
This has been fixed and new 2022.10.x versions of the aimeos/ai-admin-jqadm and aimeoscom/ai-elastic packages have been released. If you use 2023.04+, use the ".x-dev" version instead until new minor releases are available.
Re: Review rating count not updating unless index is rebuilt
Hello,
I still haven't solved this problem.
Which files exactly were the problematic ones, because I might have overwritten them.
This is what my composer.json looks like:
I still haven't solved this problem.
Which files exactly were the problematic ones, because I might have overwritten them.
This is what my composer.json looks like:
Code: Select all
{
"name": "aimeos/aimeos",
"description": "Aimeos ecommerce and shop system",
"keywords": ["aimeos", "ecommerce", "shop", "laravel", "distribution"],
"license": "MIT",
"type": "project",
"repositories": [{
"type": "composer",
"url": "https://packages.aimeos.org/aimeoscom"
}, {
"type": "path",
"url": "packages/*"
}, {
"type": "vcs",
"url": "https://github.com/kras95/omnipay-borica"
},{
"type": "composer",
"url": "https://packages.aimeos.org/aimeoscom"
}],
"require": {
"php": "^8.0.10",
"composer-runtime-api": "^2.1",
"aimeos/ai-cache": "^2022.10",
"aimeos/ai-catsuggest": "^2022.10",
"aimeos/ai-client-jsonapi": "2022.10.x-dev",
"aimeos/ai-payments": "^2022.10",
"aimeos/aimeos-laravel": "~2022.10",
"aimeoscom/ai-elastic": "^2022.10",
"doctrine/dbal": "^3.5",
"guzzlehttp/guzzle": "^7.2",
"laravel/breeze": "^1.9",
"laravel/framework": "^9.2",
"laravel/sanctum": "^2.14.1",
"laravel/socialite": "^5.5",
"laravel/tinker": "^2.7",
"league/flysystem-aws-s3-v3": "^3.0",
"league/omnipay": "^3.2",
"omnipay/paypal": "^3.0",
"omnipay/stripe": "^3.2"
},
"require-dev": {
"fakerphp/faker": "^1.9.1",
"laravel/sail": "^1.0.1",
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^6.1",
"phpunit/phpunit": "^9.5.10",
"spatie/laravel-ignition": "^1.0"
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
},
"exclude-from-classmap": [ "vendor/aimeoscom/ai-elastic/src/MShop/Product/Manager/Elastic.php" ],
"files": [ "packages/my-extension/src/MShop/Product/Manager/Elastic.php" ]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi",
"App\\Composer::configure",
"@php artisan migrate",
"App\\Composer::setup",
"App\\Composer::account",
"App\\Composer::success"
],
"post-update-cmd": [
"@php artisan migrate",
"@php artisan vendor:publish --tag=public --force",
"\\Aimeos\\Shop\\Composer::join"
]
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true,
"allow-plugins": {
"php-http/discovery": true
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
Re: Review rating count not updating unless index is rebuilt
I think that this may actually be some kind of cache.
I get the reviews like this (network logs):
/jsonapi/review?filter%5Bf_refid%5D=26&sort=-ctime
The reviews are actually taking a bit of time before appearing in the frontend.
I get the reviews like this (network logs):
/jsonapi/review?filter%5Bf_refid%5D=26&sort=-ctime
The reviews are actually taking a bit of time before appearing in the frontend.
Re: Review rating count not updating unless index is rebuilt
I solved it like this:
Decorator:
packages/my-extension/src/MShop/Review/Manager/Decorator/MyDecorator.php
Config:
packages/my-extension/config/client.php
Decorator:
packages/my-extension/src/MShop/Review/Manager/Decorator/MyDecorator.php
Code: Select all
<?php
namespace Aimeos\Client\JsonApi\Review\Decorator;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
class MyDecorator
extends \Aimeos\Client\JsonApi\Common\Decorator\Base
implements \Aimeos\Client\JsonApi\Common\Decorator\Iface
{
/**
* Remove user review cache
*/
public function get( ServerRequestInterface $request, ResponseInterface $response ) : \Psr\Http\Message\ResponseInterface
{
return parent::get( $request, $response )
->withHeader('Cache-Control', 'no-store, no-cache, must-revalidate')
->withHeader('Pragma', 'no-cache')
->withHeader('Expires', '0');
}
}
packages/my-extension/config/client.php
Code: Select all
<?php
return [
'jsonapi' => [
'review' => [
'decorators' => [
'local' => [ 'MyDecorator' ]
]
]
],
];
Re: Review rating count not updating unless index is rebuilt
Seems to be some browser caching because the Laravel Jsonapi controller doesn't set any caching headers for GET requests:
https://github.com/aimeos/aimeos-larave ... roller.php
https://github.com/aimeos/aimeos-larave ... roller.php
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star