Product - Delete Multiple Products
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!
Product - Delete Multiple Products
Laravel: 5.6
Aimeos: 2018.04
PHP: 7.1.18
Hi,
I need to delete more than 1 product from complex Aimeos DB schema. Can you please, guide me how I can do this by just one click? Or if there is any other method of deleting multiple products based on their ID or code?
Please, reply!
Thanks!
Aimeos: 2018.04
PHP: 7.1.18
Hi,
I need to delete more than 1 product from complex Aimeos DB schema. Can you please, guide me how I can do this by just one click? Or if there is any other method of deleting multiple products based on their ID or code?
Please, reply!
Thanks!
Re: Product - Delete Multiple Products
You can easily delete multiple products by using deleteItems() of the product manager. This method accepts a list of product IDs.
If you want to clean up everything that is associated to the products (categories, images, prices, texts), you can use this code:
Beware: This does only work since 2018.07 (current stable version)
If you want to clean up everything that is associated to the products (categories, images, prices, texts), you can use this code:
Code: Select all
$productItems = [...];
$catalogListManager = \Aimeos\MShop\Factory::createManager( $context, 'catalog/lists' );
$search = $catalogListManager->createSearch()->setSlice( 0, 0x7fffffff );
$expr = [
$search->compare( '==', 'catalog.lists.refid', array_keys( $productItems ) ),
$search->compare( '==', 'catalog.lists.domain', 'product' ),
];
$search->setConditions( $search->combine( '&&', $expr ) );
$listItems = $catalogListManager->searchItems( $search );
$catalogListManager->deleteItems( array_keys( $listItems ) );
$productManager = \Aimeos\MShop\Factory::createManager( $context, 'product' );
foreach( $productItems as $item ) {
$item->deleteListItems( $item->getListItems( ['media', 'price', 'text'], null, null, false ), true );
$productManager->saveItem( $item ); // deletes are referenced media, price and text items
}
$productManager->deleteItems( array_keys( $productItems ) );
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: Product - Delete Multiple Products
Hi,aimeos wrote:You can easily delete multiple products by using deleteItems() of the product manager. This method accepts a list of product IDs.
If you want to clean up everything that is associated to the products (categories, images, prices, texts), you can use this code:Beware: This does only work since 2018.07 (current stable version)Code: Select all
$productItems = [...]; $catalogListManager = \Aimeos\MShop\Factory::createManager( $context, 'catalog/lists' ); $search = $catalogListManager->createSearch()->setSlice( 0, 0x7fffffff ); $expr = [ $search->compare( '==', 'catalog.lists.refid', array_keys( $productItems ) ), $search->compare( '==', 'catalog.lists.domain', 'product' ), ]; $search->setConditions( $search->combine( '&&', $expr ) ); $listItems = $catalogListManager->searchItems( $search ); $catalogListManager->deleteItems( array_keys( $listItems ) ); $productManager = \Aimeos\MShop\Factory::createManager( $context, 'product' ); foreach( $productItems as $item ) { $item->deleteListItems( $item->getListItems( ['media', 'price', 'text'], null, null, false ), true ); $productManager->saveItem( $item ); // deletes are referenced media, price and text items } $productManager->deleteItems( array_keys( $productItems ) );
Thanks for the help! It may take me some time to understand all this but hopefully, I shall make it happen. I would suggest though, if you guys can give an option in future release to delete more than one product on Product List page then it would be great.
Thanks!
Re: Product - Delete Multiple Products
Yes, it's already on the list: https://github.com/aimeos/ai-admin-jqadm/issues/23
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: Product - Delete Multiple Products
Great!aimeos wrote:Yes, it's already on the list: https://github.com/aimeos/ai-admin-jqadm/issues/23