how do I connect product to catalog (category) items
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!
how do I connect product to catalog (category) items
I'm tring to create products via the product manager. Everything works fine.
=> mgr->create()
=> fill the values with the setter methods
=> addListItem for a catalog node
=> mgr->save()
The product will be stored as espected, and the category reference is also inserted (list items with domain catalog).
If i show the product in the backend, no category is added/displayed
If I load a manually created product in the backend, there is a special section 'catalog' in the bdata array...
Have anyone a hint for me, how to correctly connect catalog items with product items? I searched in forum, documetation and source code without success.
=> mgr->create()
=> fill the values with the setter methods
=> addListItem for a catalog node
=> mgr->save()
The product will be stored as espected, and the category reference is also inserted (list items with domain catalog).
If i show the product in the backend, no category is added/displayed
If I load a manually created product in the backend, there is a special section 'catalog' in the bdata array...
Have anyone a hint for me, how to correctly connect catalog items with product items? I searched in forum, documetation and source code without success.
Last edited by frimi on 20 Nov 2020, 09:29, edited 2 times in total.
Re: how do I connect product to calalog (category) items
The product <-> category relation is stored in the mshop_catalog_list table and you have to use the catalog/lists manager to add the product to a category.
Storing the relation in the mshop_product_lists table doesn't cause an error but isn't used at all.
Storing the relation in the mshop_product_lists table doesn't cause an error but isn't used at all.
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
Re: how do I connect product to calalog (category) items
Many thanks, that helps
I do the job with
on the catalog item and it seems to work. In the backend looks all fine.
To maintain the relations between the catalog items and the product I need to test, if there are existing relations between a given category and product. If I load a linked catalog item, the listItem Array is empty!? Also testing with
return always NULL
How should I do the testing?
I do the job with
Code: Select all
$catItem->addListItem('product',$newCatListItem->setRefId($productId))
To maintain the relations between the catalog items and the product I need to test, if there are existing relations between a given category and product. If I load a linked catalog item, the listItem Array is empty!? Also testing with
Code: Select all
$catItem->getListItem('product','default',$productId)
How should I do the testing?
Re: how do I connect product to catalog (category) items
You have to tell the manager to load either load the products associated to the category using:
But this can load a lot of data and can be very slow!
Instead, you can use the catalog manager to check if there already exists a relation to the product using:
The second item in the array for createFunction ("default") is the list type of the relation and can also be "promotion" for top seller products.
In 2020.10, you can also write this more compact using:
Code: Select all
$manager->searchItems( $filter, ['product'] )
Instead, you can use the catalog manager to check if there already exists a relation to the product using:
Code: Select all
$filter = $manager->createSearch()->setSlice( 0, 1 );
$filter->setConditions( $filter->compare( '!=', $filter->createFunction( 'catalog:has', ['product', 'default', $prodid] ), null ) );
if( $manager->searchItems( $filter )->isEmpty() ) {
...
}
In 2020.10, you can also write this more compact using:
Code: Select all
$filter = $manager->filter()->slice( 0, 1 );
$filter->add( [$filter->make( 'catalog:has', ['product', 'default', $prodid] ) => null], '!=' );
if( $manager->search( $filter )->isEmpty() ) {
...
}
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
Re: how do I connect product to catalog (category) items
Huh, it works Many thanks!
Now I need to delete catalog<->product relations. How can I do that?
$item->deleteListItem( 'product', $listitem );
How can i get the $listItem? As mentoined, getListItem() returns NULL
Now I need to delete catalog<->product relations. How can I do that?
$item->deleteListItem( 'product', $listitem );
How can i get the $listItem? As mentoined, getListItem() returns NULL
Last edited by frimi on 12 Dec 2020, 16:54, edited 2 times in total.
Re: how do I connect product to catalog (category) items
To use deleteListItems(), all catalog<->product relations must be loaded when retrieving the catalog item. This can be extremely slow, so the better alternative is to use the catalog/lists manager directly and remove the recored based on its ID (2020.10 code):
Code: Select all
\Aimeos\MShop::create( $context, 'catalog/lists' )->deleteItem( $id );
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
Re: how do I connect product to catalog (category) items
I have still problems with the deleting of the relations. If I use a known id, it works fine. But how can I find/get/retrieve the id of the relation to delete dynamicly without loading all the relations first? What I have ist the product id (item) and the catolog item.
Re: how do I connect product to catalog (category) items
If you have the product ID, you can use this code to retrieve all catalog<->product relationships including their IDs (2020.10 LTS code):
Code: Select all
$manager = \Aimeos\MShop::create( $context, 'catalog/lists' )
$filter = $manager->filter()->add( [
'catalog.lists.domain' => 'product',
'catalog.lists.type' => ['default', 'promotion'],
'catalog.lists.refid => $prodIds
] )->slice( 0, 10000 );
$manager->delete( $manager->search( $filter ) );
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
Re: how do I connect product to catalog (category) items
Hello. We have updatet our Aimeos / Typo3 installation to aimeos Extension 23.10.1 on Typo3 12.4.5 and i have a lot of things not working the same way. Could it be, that the managing of the realtions between product and the catalog has changed? If i add the relation on catalog_list table as learned in the former post, the product has no catalog item in the backend and will be not displayed in the frontent. If i add a category manually, there will be added a product_list entry, that points to the catalog item an all works fine, also in the frontend. So I'm wondering, what happened and how i have to change my code. Thanks for your help and kind regards, Michael
Re: how do I connect product to catalog (category) items
Yes, product<->category relations have moved from mshop_catalog_lists to mshop_product_lists table since 2022.x (same for suppliers). Check the changelogs when upgrading from older LTS versions: https://aimeos.org/docs/latest/changelog/2023.x/
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