Can't assign category for a new product

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!
User avatar
ahmed31916
Advanced
Posts: 148
Joined: 14 Apr 2022, 12:15

Can't assign category for a new product

Post by ahmed31916 » 08 May 2022, 10:23

Hello,
I tried to assign "home" category to a new product. But, all my attempts was failed.

Code: Select all

$categoryArray = [[
    'prodid' => 1,  
    'siteid' => 1, 
    'catid' => 1,
    'listtype ' => 'default'
    'pos' => 1,
]];
$categoryManager = \Aimeos\MShop::create( $context(), 'index/catalog' );
foreach( $categoryArray as $categoryData )
{
    $listItem = $manager->createListItem()->fromArray( $categoryData );
    $categoryItem = $categoryManager->create()->fromArray( $categoryData );
    $item->addListItem( 'index/catalog', $listItem, $categoryItem );
}
$manager->saveItem( $item );

User avatar
ahmed31916
Advanced
Posts: 148
Joined: 14 Apr 2022, 12:15

Re: Can't assign category for a new product

Post by ahmed31916 » 09 May 2022, 03:46

@aimeos
please help :roll:

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

Re: Can't assign category for a new product

Post by aimeos » 09 May 2022, 13:37

Which Aimeos version do you use?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

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

Re: Can't assign category for a new product

Post by aimeos » 11 May 2022, 06:19

Categories must be attached to products that way:

Code: Select all

$catId = 1;
$manager = \Aimeos\MShop::create($context, 'product');

$product = $manager->create()->setCode('abc');
$listItem = $manager->createListItem()->setRefId($catId);
$product->addListItem('catalog', $listItem);

$manager->save($product);
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply