Intercepting Frontend Product Controller with Product Decorator
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
-
- Posts: 41
- Joined: 03 Jun 2023, 17:30
Intercepting Frontend Product Controller with Product Decorator
Laravel Framework v10.45.1, php8.1-fpm, aimeos/aimeos-laravel 2023.10.7
Hello,
I want to be able to display a special variation of a product if the user passes a special query parameter in the request. I am struggling to do that. I am currently trying to to this with a Product Decorator in my own extension and intercept the get() method..
I have a new class I created for the Decorator which is located in my packages/mytheme/src/Controller/Frontend/Product/Decorator/SpecialVariant.php:
And then I added this to my shop.php 'controller' key:
I would expect that anytime I try to access a product the app would die(), but this doesnt seem to be the case. It doesn't appear my Decorator is working the way I expect.. Am I approaching this the correct way?
Hello,
I want to be able to display a special variation of a product if the user passes a special query parameter in the request. I am struggling to do that. I am currently trying to to this with a Product Decorator in my own extension and intercept the get() method..
I have a new class I created for the Decorator which is located in my packages/mytheme/src/Controller/Frontend/Product/Decorator/SpecialVariant.php:
Code: Select all
<?php
namespace Aimeos\Controller\Frontend\Product\Decorator;
use Aimeos\Controller\Frontend\Product\Iface;
use Aimeos\Controller\Frontend\Product\Decorator\Base;
class Specialvariant extends Base
{
public function get(string $id, string $ref = 'default', bool $all = false): \Aimeos\MShop\Product\Item\Iface
{
// Get the original product item
$product = $this->getController()->get($id, $ref, $all);
die();
// Check if the special query parameter is present
$specialParam = request()->query('special');
if ($specialParam === 'true') {
// Implement logic to handle special variation of the product
// Modify $product accordingly
die();
return $product;
}
return $product;
}
}
Code: Select all
'controller' => [
'frontend' => [
'catalog' => [
'levels-always' => 3 // number of category levels for mega menu
],
'product' => [
'standard' => [
'name' => 'Specialvariant',
'decorators' => [
'local' => ['Specialvariant']
],
]
]
]
],
-
- Posts: 41
- Joined: 03 Jun 2023, 17:30
Re: Intercepting Frontend Product Controller with Product Decorator
Testing further, I do believe that that my decorator is being honored. I can override the method for 'public function __construct' and see that my debugger enters that function in the 'Specialvariant' class.
So maybe that get() function is just never being called/used from the Standard class when displaying a product? I assumed that while loading a product on the website, it would call get() to get the product and I could tap into the method to do anything I want before returning the $product..
So maybe that get() function is just never being called/used from the Standard class when displaying a product? I assumed that while loading a product on the website, it would call get() to get the product and I could tap into the method to do anything I want before returning the $product..
Re: Intercepting Frontend Product Controller with Product Decorator
Hi.
Did you clear the cache ?
Did you clear the cache ?
-
- Posts: 41
- Joined: 03 Jun 2023, 17:30
Re: Intercepting Frontend Product Controller with Product Decorator
Hello,
I have been running this command between tests:
php artisan optimize:clear
I have also been running composer update between tests in the event that the files from my extension need to be picked up again.
There might be an easier way to do what I am trying to accomplish:
I have been running this command between tests:
php artisan optimize:clear
I have also been running composer update between tests in the event that the files from my extension need to be picked up again.
There might be an easier way to do what I am trying to accomplish:
- I have a product in the store that I will run Google Ads on and I want to pass a query parameter in the URL so that I know the traffic came from Google Ads, ie: http://mysite/shop/test-product?source=google
- If the traffic was not referred by Google Ads (ill check the source=google), then I want to product to display differently. Different images, different title, different description, different price, etc.
- Public visitors to the store would never be able to find this 'special' product, unless they had ?source=google in the URL query parameters.
Re: Intercepting Frontend Product Controller with Product Decorator
You have configured your configurations incorrectly.
Try this.
Try this.
Code: Select all
'product' => [
'decorators' => [
'local' => ['Specialvariant']
]
]
Re: Intercepting Frontend Product Controller with Product Decorator
If the product is so different, why don't you create new product that only contains the relevant information and add it to a hidden category so it's not visible without knowing the exact URL?BrianMecler wrote: ↑24 Feb 2024, 22:04
I have a product in the store that I will run Google Ads on and I want to pass a query parameter in the URL so that I know the traffic came from Google Ads, ie: http://mysite/shop/test-product?source=google[/list]
If the traffic was not referred by Google Ads (ill check the source=google), then I want to product to display differently. Different images, different title, different description, different price, etc.[/list]
Public visitors to the store would never be able to find this 'special' product, unless they had ?source=google in the URL query parameters.
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
-
- Posts: 41
- Joined: 03 Jun 2023, 17:30
Re: Intercepting Frontend Product Controller with Product Decorator
I want to use the URL of this product in Google Ads, but I dont want the product to show up in search engines. I believe that Google will try to index the product since I used it in an Ad. So my idea would be to masquerade the product if someone found it organically via a search engine.
Re: Intercepting Frontend Product Controller with Product Decorator
You can prevent URLs from being indexed in the robots.txt. This is much easier than implementing it the way you outlined.
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
-
- Posts: 41
- Joined: 03 Jun 2023, 17:30
Re: Intercepting Frontend Product Controller with Product Decorator
Thank you Aimeos,
I could go that route, but I would need to prevent indexing by using a specific meta tag on that product. Using robots.txt will prevent crawling, but not indexing (ie: the case of an external link).
I see some options on the product to add meta keywords and description, but no custom tags.
I see the following text here about metatags:
https://aimeos.org/docs/2023.x/config/c ... /#metatags
I could go that route, but I would need to prevent indexing by using a specific meta tag on that product. Using robots.txt will prevent crawling, but not indexing (ie: the case of an external link).
I see some options on the product to add meta keywords and description, but no custom tags.
I see the following text here about metatags:
https://aimeos.org/docs/2023.x/config/c ... /#metatags
Maybe adding my own sounds interesting, do you have any insight on this?This setting enables you to suppress these tags in the page header and maybe add your own to the page manually.
Re: Intercepting Frontend Product Controller with Product Decorator
This disables adding meta tags for the product to the pages completely and you would have to add it otherwise, e.g. in the Blade template, so this is not what you want.BrianMecler wrote: ↑27 Feb 2024, 22:11 Maybe adding my own sounds interesting, do you have any insight on this?
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