Add custom sortation to catalog/lists with ElasticSearch

Help for integrating the Laravel package
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!
kdim95
Advanced
Posts: 208
Joined: 26 Aug 2022, 12:17

Re: Add custom sortation to catalog/lists with ElasticSearch

Post by kdim95 » 20 Jun 2023, 07:24

aimeos wrote: 20 Jun 2023, 06:35
Can you please post you complete (custom) configuration related to the mshop config key?
Of course, I have a file in my extension here: config/mshop/product.php

This is the content of the file:

Code: Select all

return [
    'manager' => [
            'name' => 'StandardCustom',
    ],
];
Inside the StandardCustom manager, I have this:

Code: Select all

protected function createItemBase( array $values = [], array $listItems = [],
        array $refItems = [], array $propertyItems = [] ) : \Aimeos\MShop\Common\Item\Iface
    {
        $values['.date'] = $this->date;
        return new \Aimeos\MShop\Product\Item\StandardCustom( $values, $listItems, $refItems, $propertyItems );
    }
That creates a StandardCustom product, it works when ElasticIndex is not being used.
When ElasticIndex is being used and I try to go into a product details page, my custom product class is not used.
Then it throws errors that I have undefined methods in my custom product item class.

aimeos wrote: 20 Jun 2023, 06:35
You need to add that to your app/Providers/AppServiceProvider.php in the boot() method.
Thank you for this, I will try it. If it works, I won't need to create custom product item classes.
I think that the documentation wasn't clear enough and I ended up adding it in the wrong location.
The "Item properties" section should have a note that that config should be added to the boot() method.
I can also add the details about this as a pull request on github.

kdim95
Advanced
Posts: 208
Joined: 26 Aug 2022, 12:17

Re: Add custom sortation to catalog/lists with ElasticSearch

Post by kdim95 » 20 Jun 2023, 07:47

I added this to App\Providers\AppServiceProvider::boot():

Code: Select all

\Aimeos\MShop\Product\Item\Standard::method( 'getMycolumn', function() {
    return $this->get( 'mycolumn' );
} );
I got this error: Called unknown macro "method" on class "Aimeos\MShop\Product\Item\Standard"

I think my code is up to date (~2023.04), not sure what the problem is.

User avatar
aimeos
Administrator
Posts: 7913
Joined: 01 Jan 1970, 00:00

Re: Add custom sortation to catalog/lists with ElasticSearch

Post by aimeos » 20 Jun 2023, 15:07

The method name changed from "method" to "macro" two years ago:

Code: Select all

\Aimeos\MShop\Product\Item\Standard::macro( 'getMycolumn', function() {
    return $this->get( 'mycolumn' );
} );
Is there still an old reference somewhere?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

kdim95
Advanced
Posts: 208
Joined: 26 Aug 2022, 12:17

Re: Add custom sortation to catalog/lists with ElasticSearch

Post by kdim95 » 21 Jun 2023, 07:49

Docs need to be updated with the "macro" method here:
https://aimeos.org/docs/2023.x/models/extend-managers/

User avatar
aimeos
Administrator
Posts: 7913
Joined: 01 Jan 1970, 00:00

Re: Add custom sortation to catalog/lists with ElasticSearch

Post by aimeos » 21 Jun 2023, 14:38

Thanks, has been fixed now
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply