Can't assign category for a new product
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!
- ahmed31916
- Advanced
- Posts: 148
- Joined: 14 Apr 2022, 12:15
Can't assign category for a new product
Hello,
I tried to assign "home" category to a new product. But, all my attempts was failed.
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 );
- ahmed31916
- Advanced
- Posts: 148
- Joined: 14 Apr 2022, 12:15
Re: Can't assign category for a new product
@aimeos
please help
please help
Re: Can't assign category for a new product
Which Aimeos version do you use?
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: Can't assign category for a new product
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, give us a star
If you like Aimeos, give us a star