Magento 2: Mass Delete PHP code not WorkingWhere is function location of mass delete ordersMagento 2 massaction delete not workingHow to mass delete products from disabled categories?Magento 2: How to override newsletter Subscriber modelMass Action not sending all dataSolved - Adding Mass Delete Action to the GridMass action delete not working on Magento 2.1.9Magento2 : massdelete is not workingMagento 2 Mass shipmentAdmin Grid Mass Action delete not working for custom module for Magento 2.2.4
Would Brexit have gone ahead by now if Gina Miller had not forced the Government to involve Parliament?
How long does it take to crack RSA 1024 with a PC?
Would the Geas spell work in a dead magic zone once you enter it?
Array Stutter Implementation
Placing bypass capacitors after VCC reaches the IC
Is it possible to play as a necromancer skeleton?
ECDSA - why not using the cyclic additive group
Command to Search for Filenames Exceeding 143 Characters?
Crossing US border with music files I'm legally allowed to possess
How do you say “buy” in the sense of “believe”?
Is floating in space similar to falling under gravity?
What is the difference between nullifying your vote and not going to vote at all?
Full backup on database creation
Employer asking for online access to bank account - Is this a scam?
Python program to convert a 24 hour format to 12 hour format
When do characters level up?
Approximate solution : factorial and exponentials
Why is desire the root of suffering?
Tic-tac-toe for the terminal, written in C
How does an ARM MCU run faster than the external crystal?
Boss wants me to falsify a report. How should I document this unethical demand?
What's the Difference between Two Single-Quotes and One Double-Quote?
Where did Wilson state that the US would have to force access to markets with violence?
Why does the 'metric Lagrangian' approach appear to fail in Newtonian mechanics?
Magento 2: Mass Delete PHP code not Working
Where is function location of mass delete ordersMagento 2 massaction delete not workingHow to mass delete products from disabled categories?Magento 2: How to override newsletter Subscriber modelMass Action not sending all dataSolved - Adding Mass Delete Action to the GridMass action delete not working on Magento 2.1.9Magento2 : massdelete is not workingMagento 2 Mass shipmentAdmin Grid Mass Action delete not working for custom module for Magento 2.2.4
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm very new to Magento, i created a Mass Action for Delete i write this code in /EC/Downloads/view/adminhtml/ui_component/ec_downloads_items.xml
<?xml version="1.0"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<listingToolbar name="listing_top">
<settings>
<sticky>true</sticky>
</settings>
<paging name="listing_paging"/>
<filters name="listing_filters"/>
<massaction name="listing_massaction">
<action name="delete">
<settings>
<confirm>
<message translate="true">Delete selected items?</message>
<title translate="true">Delete items</title>
</confirm>
<url path="*/items/MassDelete"/>
<type>delete</type>
<label translate="true">Delete</label>
</settings>
</action>
</massaction>
</listingToolbar>
<columns name="ec_downloads_items_columns">
<selectionsColumn name="ids">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="resizeEnabled" xsi:type="boolean">false</item>
<item name="resizeDefaultWidth" xsi:type="string">55</item>
<item name="indexField" xsi:type="string">downloads_id</item>
<item name="sortOrder" xsi:type="number">10</item>
</item>
</argument>
</selectionsColumn>
<column name="downloads_id">.......</column>
</columns>
</listing>
and this code in /EC/Downloads/Controller/Adminhtml/Items/MassDelete.php
<?php
namespace ECDownloadsControllerAdminhtmlItems;
use MagentoBackendAppAction;
/**
* Class MassDelete
*/
class MassDelete extends MagentoBackendAppAction
/**
* @return MagentoBackendModelViewResultRedirect
*/
public function execute()
$ids = $this->getRequest()->getParam('downloads_id');
echo $ids;
exit;
if (!is_array($ids)
code in /EC/Downloads/Model/ResourceModel/Items.php
<?php
namespace ECDownloadsModelResourceModel;
/**
* Class Items
* @package ECDownloadsModelResourceModel
*/
class Items extends MagentoFrameworkModelResourceModelDbAbstractDb
/**
*
*/
protected function _construct()
$this->_init('downloads', 'downloads_id');
When i try to delete more items it's not working, when i try to echo|exit, i found that i dosen't go to the delete part coz ids is empty.
magento2 magento2.3 delete massaction
|
show 1 more comment
I'm very new to Magento, i created a Mass Action for Delete i write this code in /EC/Downloads/view/adminhtml/ui_component/ec_downloads_items.xml
<?xml version="1.0"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<listingToolbar name="listing_top">
<settings>
<sticky>true</sticky>
</settings>
<paging name="listing_paging"/>
<filters name="listing_filters"/>
<massaction name="listing_massaction">
<action name="delete">
<settings>
<confirm>
<message translate="true">Delete selected items?</message>
<title translate="true">Delete items</title>
</confirm>
<url path="*/items/MassDelete"/>
<type>delete</type>
<label translate="true">Delete</label>
</settings>
</action>
</massaction>
</listingToolbar>
<columns name="ec_downloads_items_columns">
<selectionsColumn name="ids">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="resizeEnabled" xsi:type="boolean">false</item>
<item name="resizeDefaultWidth" xsi:type="string">55</item>
<item name="indexField" xsi:type="string">downloads_id</item>
<item name="sortOrder" xsi:type="number">10</item>
</item>
</argument>
</selectionsColumn>
<column name="downloads_id">.......</column>
</columns>
</listing>
and this code in /EC/Downloads/Controller/Adminhtml/Items/MassDelete.php
<?php
namespace ECDownloadsControllerAdminhtmlItems;
use MagentoBackendAppAction;
/**
* Class MassDelete
*/
class MassDelete extends MagentoBackendAppAction
/**
* @return MagentoBackendModelViewResultRedirect
*/
public function execute()
$ids = $this->getRequest()->getParam('downloads_id');
echo $ids;
exit;
if (!is_array($ids)
code in /EC/Downloads/Model/ResourceModel/Items.php
<?php
namespace ECDownloadsModelResourceModel;
/**
* Class Items
* @package ECDownloadsModelResourceModel
*/
class Items extends MagentoFrameworkModelResourceModelDbAbstractDb
/**
*
*/
protected function _construct()
$this->_init('downloads', 'downloads_id');
When i try to delete more items it's not working, when i try to echo|exit, i found that i dosen't go to the delete part coz ids is empty.
magento2 magento2.3 delete massaction
Can you please add more code of ui_component xml file?
– Kazim Noorani
May 21 at 12:22
@KazimNoorani Updated....
– Saif Zakir
May 21 at 12:27
Please check my answer. Might help you.
– Kazim Noorani
May 21 at 12:32
Is it helpful ?
– Kazim Noorani
May 21 at 12:38
I can't see the <item> tag name provider and <dataSource> tag process and make the UI component work with this data.
– Shekhar Suman
May 22 at 9:33
|
show 1 more comment
I'm very new to Magento, i created a Mass Action for Delete i write this code in /EC/Downloads/view/adminhtml/ui_component/ec_downloads_items.xml
<?xml version="1.0"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<listingToolbar name="listing_top">
<settings>
<sticky>true</sticky>
</settings>
<paging name="listing_paging"/>
<filters name="listing_filters"/>
<massaction name="listing_massaction">
<action name="delete">
<settings>
<confirm>
<message translate="true">Delete selected items?</message>
<title translate="true">Delete items</title>
</confirm>
<url path="*/items/MassDelete"/>
<type>delete</type>
<label translate="true">Delete</label>
</settings>
</action>
</massaction>
</listingToolbar>
<columns name="ec_downloads_items_columns">
<selectionsColumn name="ids">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="resizeEnabled" xsi:type="boolean">false</item>
<item name="resizeDefaultWidth" xsi:type="string">55</item>
<item name="indexField" xsi:type="string">downloads_id</item>
<item name="sortOrder" xsi:type="number">10</item>
</item>
</argument>
</selectionsColumn>
<column name="downloads_id">.......</column>
</columns>
</listing>
and this code in /EC/Downloads/Controller/Adminhtml/Items/MassDelete.php
<?php
namespace ECDownloadsControllerAdminhtmlItems;
use MagentoBackendAppAction;
/**
* Class MassDelete
*/
class MassDelete extends MagentoBackendAppAction
/**
* @return MagentoBackendModelViewResultRedirect
*/
public function execute()
$ids = $this->getRequest()->getParam('downloads_id');
echo $ids;
exit;
if (!is_array($ids)
code in /EC/Downloads/Model/ResourceModel/Items.php
<?php
namespace ECDownloadsModelResourceModel;
/**
* Class Items
* @package ECDownloadsModelResourceModel
*/
class Items extends MagentoFrameworkModelResourceModelDbAbstractDb
/**
*
*/
protected function _construct()
$this->_init('downloads', 'downloads_id');
When i try to delete more items it's not working, when i try to echo|exit, i found that i dosen't go to the delete part coz ids is empty.
magento2 magento2.3 delete massaction
I'm very new to Magento, i created a Mass Action for Delete i write this code in /EC/Downloads/view/adminhtml/ui_component/ec_downloads_items.xml
<?xml version="1.0"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<listingToolbar name="listing_top">
<settings>
<sticky>true</sticky>
</settings>
<paging name="listing_paging"/>
<filters name="listing_filters"/>
<massaction name="listing_massaction">
<action name="delete">
<settings>
<confirm>
<message translate="true">Delete selected items?</message>
<title translate="true">Delete items</title>
</confirm>
<url path="*/items/MassDelete"/>
<type>delete</type>
<label translate="true">Delete</label>
</settings>
</action>
</massaction>
</listingToolbar>
<columns name="ec_downloads_items_columns">
<selectionsColumn name="ids">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="resizeEnabled" xsi:type="boolean">false</item>
<item name="resizeDefaultWidth" xsi:type="string">55</item>
<item name="indexField" xsi:type="string">downloads_id</item>
<item name="sortOrder" xsi:type="number">10</item>
</item>
</argument>
</selectionsColumn>
<column name="downloads_id">.......</column>
</columns>
</listing>
and this code in /EC/Downloads/Controller/Adminhtml/Items/MassDelete.php
<?php
namespace ECDownloadsControllerAdminhtmlItems;
use MagentoBackendAppAction;
/**
* Class MassDelete
*/
class MassDelete extends MagentoBackendAppAction
/**
* @return MagentoBackendModelViewResultRedirect
*/
public function execute()
$ids = $this->getRequest()->getParam('downloads_id');
echo $ids;
exit;
if (!is_array($ids)
code in /EC/Downloads/Model/ResourceModel/Items.php
<?php
namespace ECDownloadsModelResourceModel;
/**
* Class Items
* @package ECDownloadsModelResourceModel
*/
class Items extends MagentoFrameworkModelResourceModelDbAbstractDb
/**
*
*/
protected function _construct()
$this->_init('downloads', 'downloads_id');
When i try to delete more items it's not working, when i try to echo|exit, i found that i dosen't go to the delete part coz ids is empty.
magento2 magento2.3 delete massaction
magento2 magento2.3 delete massaction
edited May 21 at 12:24
Saif Zakir
asked May 21 at 12:15
Saif ZakirSaif Zakir
387
387
Can you please add more code of ui_component xml file?
– Kazim Noorani
May 21 at 12:22
@KazimNoorani Updated....
– Saif Zakir
May 21 at 12:27
Please check my answer. Might help you.
– Kazim Noorani
May 21 at 12:32
Is it helpful ?
– Kazim Noorani
May 21 at 12:38
I can't see the <item> tag name provider and <dataSource> tag process and make the UI component work with this data.
– Shekhar Suman
May 22 at 9:33
|
show 1 more comment
Can you please add more code of ui_component xml file?
– Kazim Noorani
May 21 at 12:22
@KazimNoorani Updated....
– Saif Zakir
May 21 at 12:27
Please check my answer. Might help you.
– Kazim Noorani
May 21 at 12:32
Is it helpful ?
– Kazim Noorani
May 21 at 12:38
I can't see the <item> tag name provider and <dataSource> tag process and make the UI component work with this data.
– Shekhar Suman
May 22 at 9:33
Can you please add more code of ui_component xml file?
– Kazim Noorani
May 21 at 12:22
Can you please add more code of ui_component xml file?
– Kazim Noorani
May 21 at 12:22
@KazimNoorani Updated....
– Saif Zakir
May 21 at 12:27
@KazimNoorani Updated....
– Saif Zakir
May 21 at 12:27
Please check my answer. Might help you.
– Kazim Noorani
May 21 at 12:32
Please check my answer. Might help you.
– Kazim Noorani
May 21 at 12:32
Is it helpful ?
– Kazim Noorani
May 21 at 12:38
Is it helpful ?
– Kazim Noorani
May 21 at 12:38
I can't see the <item> tag name provider and <dataSource> tag process and make the UI component work with this data.
– Shekhar Suman
May 22 at 9:33
I can't see the <item> tag name provider and <dataSource> tag process and make the UI component work with this data.
– Shekhar Suman
May 22 at 9:33
|
show 1 more comment
4 Answers
4
active
oldest
votes
It's working fine. Try this
UI component Form
<action name="delete">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="type" xsi:type="string">delete</item>
<item name="label" xsi:type="string" translate="true">Delete</item>
<item name="url" xsi:type="url" path="router_name/index/massdelete"/>
<item name="confirm" xsi:type="array">
<item name="title" xsi:type="string" translate="true">Delete</item>
<item name="message" xsi:type="string" translate="true">Do you want to delete selected row record?</item>
</item>
</item>
</argument>
</action>
Controller
<?php
namespace ECDownloadsControllerAdminhtmlIndex;
use MagentoFrameworkControllerResultFactory;
use MagentoBackendAppActionContext;
use MagentoUiComponentMassActionFilter;
use ECDownloadsModelResourceModelPostCollectionFactory;
class MassDelete extends MagentoBackendAppAction
protected $_filter;
protected $serviceFactory;
public function __construct(
Context $context,
Filter $filter,
ECDownloadsModelDownloadsFactory $serviceFactory,
CollectionFactory $collectionFactory
)
$this->_filter = $filter;
$this->collectionFactory = $collectionFactory;
$this->serviceFactory = $serviceFactory;
parent::__construct($context);
public function execute()
$collection = $this->_filter->getCollection($this->collectionFactory->create());
$collectionSize = $collection->getSize();
foreach ($collection as $item)
$item = $this->serviceFactory->create()->load($item->getDownloadsId());
$item->delete();
$this->messageManager->addSuccess(__('A total of %1 element(s) have been deleted.', $collectionSize));
/** @var MagentoBackendModelViewResultRedirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath('downloads/index/items');
Getting this error:Exception #0 (Zend_Db_Statement_Exception): SQLSTATE[42S22]:Column not found: 1054 Unknown column '' in 'where clause', query was:SELECT COUNT(*) FROM downloads AS main_table WHERE (`` IN('7'))Exception #1 (PDOException): SQLSTATE[42S22]:Column not found: 1054 Unknown column '' in 'where clause'@ARUNPRABAKARANM
– Saif Zakir
May 22 at 11:11
Yeah I need to add this line inModelResourceModelModuleCollection.php...protected $_idFieldName = 'downloads_id';
– Saif Zakir
May 22 at 11:27
Did you get an error till now?
– ARUNPRABAKARAN M
May 22 at 14:02
Yes bro...! no doubt .... :)
– Saif Zakir
2 days ago
add a comment |
Does your resourceModel collection have a key defined?
namespace XigenDataModelResourceModelFitment;
class Collection extends MagentoFrameworkModelResourceModelDbCollectionAbstractCollection
/**
* @var string
*/
protected $_idFieldName = 'fitment_id';
/**
* Define resource model
*
* @return void
*/
protected function _construct()
$this->_init(
XigenDataModelFitment::class,
XigenDataModelResourceModelFitment::class
);
Just for reference here is my MassDelete.php
namespace XigenDataControllerAdminhtmlFitment;
/**
* Mass-Delete Controller.
*/
class MassDelete extends MagentoBackendAppAction
const ADMIN_RESOURCE = 'Xigen_Data::import';
private $filter;
private $collectionFactory;
/**
* MassDelete constructor.
*
* @param MagentoBackendAppActionContext $context
* @param MagentoUiComponentMassActionFilter $filter
* @param XigenDataModelResourceModelImportCollectionFactory $collectionFactory
*/
public function __construct(
MagentoBackendAppActionContext $context,
MagentoUiComponentMassActionFilter $filter,
XigenDataModelResourceModelFitmentCollectionFactory $collectionFactory,
XigenDataModelFitmentFactory $fitmentFactory
)
$this->filter = $filter;
$this->fitmentFactory = $fitmentFactory;
parent::__construct($context);
/**
* Execute action.
*
* @return MagentoBackendModelViewResultRedirect
* @throws MagentoFrameworkExceptionLocalizedException
Question updated withRersourceModel@DominicXigen
– Saif Zakir
May 21 at 12:22
coulden't understand this.... !
– Saif Zakir
May 21 at 12:29
add a comment |
Just for reference, this is my code of ui_component listing xml file.
<listingToolbar name="listing_top">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="sticky" xsi:type="boolean">true</item>
</item>
</argument>
<bookmark name="bookmarks"/>
<columnsControls name="columns_controls"/>
<filters name="listing_filters"/>
<massaction name="listing_massaction">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/tree-massactions</item>
</item>
</argument>
<action name="delete">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="type" xsi:type="string">delete</item>
<item name="label" xsi:type="string" translate="true">Delete</item>
<item name="url" xsi:type="url" path="bannerslider/banner/massDelete"/>
<item name="confirm" xsi:type="array">
<item name="title" xsi:type="string" translate="true">Delete Slider</item>
<item name="message" xsi:type="string" translate="true">Are you sure you wan't to delete selected Banners?</item>
</item>
</item>
</argument>
</action>
</massaction>
<paging name="listing_paging"/>
</listingToolbar>
And this is massDelete Controller.
<?php
namespace ABannerSliderControllerAdminhtmlBanner;
use MagentoBackendAppAction;
use MagentoBackendAppActionContext;
use MagentoUiComponentMassActionFilter;
use ABannerSliderModelResourceModelBannerCollectionFactory;
class MassDelete extends Action
protected $filter;
protected $collectionFactory;
public function __construct(
Filter $filter,
CollectionFactory $collectionFactory,
Context $context
)
$this->filter = $filter;
$this->collectionFactory = $collectionFactory;
parent::__construct($context);
public function execute()
$collection = $this->filter->getCollection($this->collectionFactory->create());
$delete = 0;
foreach ($collection as $item)
$item->delete();
$delete++;
$this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.', $delete));
$resultRedirect = $this->resultFactory->create(MagentoFrameworkControllerResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath('*/*/');
add a comment |
Paste your MassDelete.php with below one:
<?php
namespace ECDownloadsControllerAdminhtmlItems;
use MagentoBackendAppAction;
/**
* Class MassDelete
*/
class MassDelete extends MagentoBackendAppAction
/**
* @return MagentoBackendModelViewResultRedirect
*/
public function __construct(
MagentoBackendAppActionContext $context,
MagentoUiComponentMassActionFilter $filter,
ECDownloadsModelResourceModelItemsCollectionFactory $collectionFactory,
ECDownloadsModelItemFactory $itemFactory
)
$this->filter = $filter;
$this->itemFactory = $itemFactory;
parent::__construct($context);
public function execute()
$ids = $this->getRequest()->getPost();
if ($ids)
$collection = $this->itemFactory->create()
->getCollection()
->addFieldToFilter('downloads_id', array('in' => $ids));
$collectionSize = $collection->getSize();
$deletedItems = 0;
foreach ($collection as $item)
try
$item->delete();
$deletedItems++;
catch (Exception $e)
$this->messageManager->addErrorMessage($e->getMessage());
if ($deletedItems != 0)
if ($collectionSize != $deletedItems)
$this->messageManager->addErrorMessage(
__('Failed to delete %1 fitment item(s).', $collectionSize - $deletedItems)
);
$this->messageManager->addSuccessMessage(
__('A total of %1 fitment item(s) have been deleted.', $deletedItems)
);
/** @var MagentoBackendModelViewResultRedirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(MagentoFrameworkControllerResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath('downloads/index/items');
not working....
– Saif Zakir
May 21 at 12:55
->addFieldToFilter('downloads_id', array('in' => $ids));getting error in this line...
– Saif Zakir
May 21 at 12:55
Exception #0 (Exception): Warning: PDO::quote() expects parameter 1 to be string, object given in /var/www/html/mg.local/vendor/magento/zendframework1/library/Zend/Db/Adapter/Pdo/Abstract.php on line 296
– Saif Zakir
May 21 at 12:56
Are you getting $ids?
– Rutvee Sojitra
May 21 at 13:00
yes... like this: id => 1 and 3:ZendStdlibParameters Object ( [storage:ArrayObject:private] => Array ( [selected] => Array ( [0] => 1 [1] => 3 ) [filters] => Array ( [placeholder] => true ) [namespace] => ec_downloads_items [form_key] => TfQNKpKNTlflHLwE ) )
– Saif Zakir
May 21 at 13:07
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f275467%2fmagento-2-mass-delete-php-code-not-working%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
It's working fine. Try this
UI component Form
<action name="delete">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="type" xsi:type="string">delete</item>
<item name="label" xsi:type="string" translate="true">Delete</item>
<item name="url" xsi:type="url" path="router_name/index/massdelete"/>
<item name="confirm" xsi:type="array">
<item name="title" xsi:type="string" translate="true">Delete</item>
<item name="message" xsi:type="string" translate="true">Do you want to delete selected row record?</item>
</item>
</item>
</argument>
</action>
Controller
<?php
namespace ECDownloadsControllerAdminhtmlIndex;
use MagentoFrameworkControllerResultFactory;
use MagentoBackendAppActionContext;
use MagentoUiComponentMassActionFilter;
use ECDownloadsModelResourceModelPostCollectionFactory;
class MassDelete extends MagentoBackendAppAction
protected $_filter;
protected $serviceFactory;
public function __construct(
Context $context,
Filter $filter,
ECDownloadsModelDownloadsFactory $serviceFactory,
CollectionFactory $collectionFactory
)
$this->_filter = $filter;
$this->collectionFactory = $collectionFactory;
$this->serviceFactory = $serviceFactory;
parent::__construct($context);
public function execute()
$collection = $this->_filter->getCollection($this->collectionFactory->create());
$collectionSize = $collection->getSize();
foreach ($collection as $item)
$item = $this->serviceFactory->create()->load($item->getDownloadsId());
$item->delete();
$this->messageManager->addSuccess(__('A total of %1 element(s) have been deleted.', $collectionSize));
/** @var MagentoBackendModelViewResultRedirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath('downloads/index/items');
Getting this error:Exception #0 (Zend_Db_Statement_Exception): SQLSTATE[42S22]:Column not found: 1054 Unknown column '' in 'where clause', query was:SELECT COUNT(*) FROM downloads AS main_table WHERE (`` IN('7'))Exception #1 (PDOException): SQLSTATE[42S22]:Column not found: 1054 Unknown column '' in 'where clause'@ARUNPRABAKARANM
– Saif Zakir
May 22 at 11:11
Yeah I need to add this line inModelResourceModelModuleCollection.php...protected $_idFieldName = 'downloads_id';
– Saif Zakir
May 22 at 11:27
Did you get an error till now?
– ARUNPRABAKARAN M
May 22 at 14:02
Yes bro...! no doubt .... :)
– Saif Zakir
2 days ago
add a comment |
It's working fine. Try this
UI component Form
<action name="delete">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="type" xsi:type="string">delete</item>
<item name="label" xsi:type="string" translate="true">Delete</item>
<item name="url" xsi:type="url" path="router_name/index/massdelete"/>
<item name="confirm" xsi:type="array">
<item name="title" xsi:type="string" translate="true">Delete</item>
<item name="message" xsi:type="string" translate="true">Do you want to delete selected row record?</item>
</item>
</item>
</argument>
</action>
Controller
<?php
namespace ECDownloadsControllerAdminhtmlIndex;
use MagentoFrameworkControllerResultFactory;
use MagentoBackendAppActionContext;
use MagentoUiComponentMassActionFilter;
use ECDownloadsModelResourceModelPostCollectionFactory;
class MassDelete extends MagentoBackendAppAction
protected $_filter;
protected $serviceFactory;
public function __construct(
Context $context,
Filter $filter,
ECDownloadsModelDownloadsFactory $serviceFactory,
CollectionFactory $collectionFactory
)
$this->_filter = $filter;
$this->collectionFactory = $collectionFactory;
$this->serviceFactory = $serviceFactory;
parent::__construct($context);
public function execute()
$collection = $this->_filter->getCollection($this->collectionFactory->create());
$collectionSize = $collection->getSize();
foreach ($collection as $item)
$item = $this->serviceFactory->create()->load($item->getDownloadsId());
$item->delete();
$this->messageManager->addSuccess(__('A total of %1 element(s) have been deleted.', $collectionSize));
/** @var MagentoBackendModelViewResultRedirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath('downloads/index/items');
Getting this error:Exception #0 (Zend_Db_Statement_Exception): SQLSTATE[42S22]:Column not found: 1054 Unknown column '' in 'where clause', query was:SELECT COUNT(*) FROM downloads AS main_table WHERE (`` IN('7'))Exception #1 (PDOException): SQLSTATE[42S22]:Column not found: 1054 Unknown column '' in 'where clause'@ARUNPRABAKARANM
– Saif Zakir
May 22 at 11:11
Yeah I need to add this line inModelResourceModelModuleCollection.php...protected $_idFieldName = 'downloads_id';
– Saif Zakir
May 22 at 11:27
Did you get an error till now?
– ARUNPRABAKARAN M
May 22 at 14:02
Yes bro...! no doubt .... :)
– Saif Zakir
2 days ago
add a comment |
It's working fine. Try this
UI component Form
<action name="delete">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="type" xsi:type="string">delete</item>
<item name="label" xsi:type="string" translate="true">Delete</item>
<item name="url" xsi:type="url" path="router_name/index/massdelete"/>
<item name="confirm" xsi:type="array">
<item name="title" xsi:type="string" translate="true">Delete</item>
<item name="message" xsi:type="string" translate="true">Do you want to delete selected row record?</item>
</item>
</item>
</argument>
</action>
Controller
<?php
namespace ECDownloadsControllerAdminhtmlIndex;
use MagentoFrameworkControllerResultFactory;
use MagentoBackendAppActionContext;
use MagentoUiComponentMassActionFilter;
use ECDownloadsModelResourceModelPostCollectionFactory;
class MassDelete extends MagentoBackendAppAction
protected $_filter;
protected $serviceFactory;
public function __construct(
Context $context,
Filter $filter,
ECDownloadsModelDownloadsFactory $serviceFactory,
CollectionFactory $collectionFactory
)
$this->_filter = $filter;
$this->collectionFactory = $collectionFactory;
$this->serviceFactory = $serviceFactory;
parent::__construct($context);
public function execute()
$collection = $this->_filter->getCollection($this->collectionFactory->create());
$collectionSize = $collection->getSize();
foreach ($collection as $item)
$item = $this->serviceFactory->create()->load($item->getDownloadsId());
$item->delete();
$this->messageManager->addSuccess(__('A total of %1 element(s) have been deleted.', $collectionSize));
/** @var MagentoBackendModelViewResultRedirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath('downloads/index/items');
It's working fine. Try this
UI component Form
<action name="delete">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="type" xsi:type="string">delete</item>
<item name="label" xsi:type="string" translate="true">Delete</item>
<item name="url" xsi:type="url" path="router_name/index/massdelete"/>
<item name="confirm" xsi:type="array">
<item name="title" xsi:type="string" translate="true">Delete</item>
<item name="message" xsi:type="string" translate="true">Do you want to delete selected row record?</item>
</item>
</item>
</argument>
</action>
Controller
<?php
namespace ECDownloadsControllerAdminhtmlIndex;
use MagentoFrameworkControllerResultFactory;
use MagentoBackendAppActionContext;
use MagentoUiComponentMassActionFilter;
use ECDownloadsModelResourceModelPostCollectionFactory;
class MassDelete extends MagentoBackendAppAction
protected $_filter;
protected $serviceFactory;
public function __construct(
Context $context,
Filter $filter,
ECDownloadsModelDownloadsFactory $serviceFactory,
CollectionFactory $collectionFactory
)
$this->_filter = $filter;
$this->collectionFactory = $collectionFactory;
$this->serviceFactory = $serviceFactory;
parent::__construct($context);
public function execute()
$collection = $this->_filter->getCollection($this->collectionFactory->create());
$collectionSize = $collection->getSize();
foreach ($collection as $item)
$item = $this->serviceFactory->create()->load($item->getDownloadsId());
$item->delete();
$this->messageManager->addSuccess(__('A total of %1 element(s) have been deleted.', $collectionSize));
/** @var MagentoBackendModelViewResultRedirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath('downloads/index/items');
edited May 22 at 7:14
answered May 22 at 7:08
ARUNPRABAKARAN MARUNPRABAKARAN M
758215
758215
Getting this error:Exception #0 (Zend_Db_Statement_Exception): SQLSTATE[42S22]:Column not found: 1054 Unknown column '' in 'where clause', query was:SELECT COUNT(*) FROM downloads AS main_table WHERE (`` IN('7'))Exception #1 (PDOException): SQLSTATE[42S22]:Column not found: 1054 Unknown column '' in 'where clause'@ARUNPRABAKARANM
– Saif Zakir
May 22 at 11:11
Yeah I need to add this line inModelResourceModelModuleCollection.php...protected $_idFieldName = 'downloads_id';
– Saif Zakir
May 22 at 11:27
Did you get an error till now?
– ARUNPRABAKARAN M
May 22 at 14:02
Yes bro...! no doubt .... :)
– Saif Zakir
2 days ago
add a comment |
Getting this error:Exception #0 (Zend_Db_Statement_Exception): SQLSTATE[42S22]:Column not found: 1054 Unknown column '' in 'where clause', query was:SELECT COUNT(*) FROM downloads AS main_table WHERE (`` IN('7'))Exception #1 (PDOException): SQLSTATE[42S22]:Column not found: 1054 Unknown column '' in 'where clause'@ARUNPRABAKARANM
– Saif Zakir
May 22 at 11:11
Yeah I need to add this line inModelResourceModelModuleCollection.php...protected $_idFieldName = 'downloads_id';
– Saif Zakir
May 22 at 11:27
Did you get an error till now?
– ARUNPRABAKARAN M
May 22 at 14:02
Yes bro...! no doubt .... :)
– Saif Zakir
2 days ago
Getting this error:
Exception #0 (Zend_Db_Statement_Exception): SQLSTATE[42S22]: Column not found: 1054 Unknown column '' in 'where clause', query was: SELECT COUNT(*) FROM downloads AS main_table WHERE (`` IN('7')) Exception #1 (PDOException): SQLSTATE[42S22]: Column not found: 1054 Unknown column '' in 'where clause' @ARUNPRABAKARANM– Saif Zakir
May 22 at 11:11
Getting this error:
Exception #0 (Zend_Db_Statement_Exception): SQLSTATE[42S22]: Column not found: 1054 Unknown column '' in 'where clause', query was: SELECT COUNT(*) FROM downloads AS main_table WHERE (`` IN('7')) Exception #1 (PDOException): SQLSTATE[42S22]: Column not found: 1054 Unknown column '' in 'where clause' @ARUNPRABAKARANM– Saif Zakir
May 22 at 11:11
Yeah I need to add this line in
ModelResourceModelModuleCollection.php ... protected $_idFieldName = 'downloads_id';– Saif Zakir
May 22 at 11:27
Yeah I need to add this line in
ModelResourceModelModuleCollection.php ... protected $_idFieldName = 'downloads_id';– Saif Zakir
May 22 at 11:27
Did you get an error till now?
– ARUNPRABAKARAN M
May 22 at 14:02
Did you get an error till now?
– ARUNPRABAKARAN M
May 22 at 14:02
Yes bro...! no doubt .... :)
– Saif Zakir
2 days ago
Yes bro...! no doubt .... :)
– Saif Zakir
2 days ago
add a comment |
Does your resourceModel collection have a key defined?
namespace XigenDataModelResourceModelFitment;
class Collection extends MagentoFrameworkModelResourceModelDbCollectionAbstractCollection
/**
* @var string
*/
protected $_idFieldName = 'fitment_id';
/**
* Define resource model
*
* @return void
*/
protected function _construct()
$this->_init(
XigenDataModelFitment::class,
XigenDataModelResourceModelFitment::class
);
Just for reference here is my MassDelete.php
namespace XigenDataControllerAdminhtmlFitment;
/**
* Mass-Delete Controller.
*/
class MassDelete extends MagentoBackendAppAction
const ADMIN_RESOURCE = 'Xigen_Data::import';
private $filter;
private $collectionFactory;
/**
* MassDelete constructor.
*
* @param MagentoBackendAppActionContext $context
* @param MagentoUiComponentMassActionFilter $filter
* @param XigenDataModelResourceModelImportCollectionFactory $collectionFactory
*/
public function __construct(
MagentoBackendAppActionContext $context,
MagentoUiComponentMassActionFilter $filter,
XigenDataModelResourceModelFitmentCollectionFactory $collectionFactory,
XigenDataModelFitmentFactory $fitmentFactory
)
$this->filter = $filter;
$this->fitmentFactory = $fitmentFactory;
parent::__construct($context);
/**
* Execute action.
*
* @return MagentoBackendModelViewResultRedirect
* @throws MagentoFrameworkExceptionLocalizedException
Question updated withRersourceModel@DominicXigen
– Saif Zakir
May 21 at 12:22
coulden't understand this.... !
– Saif Zakir
May 21 at 12:29
add a comment |
Does your resourceModel collection have a key defined?
namespace XigenDataModelResourceModelFitment;
class Collection extends MagentoFrameworkModelResourceModelDbCollectionAbstractCollection
/**
* @var string
*/
protected $_idFieldName = 'fitment_id';
/**
* Define resource model
*
* @return void
*/
protected function _construct()
$this->_init(
XigenDataModelFitment::class,
XigenDataModelResourceModelFitment::class
);
Just for reference here is my MassDelete.php
namespace XigenDataControllerAdminhtmlFitment;
/**
* Mass-Delete Controller.
*/
class MassDelete extends MagentoBackendAppAction
const ADMIN_RESOURCE = 'Xigen_Data::import';
private $filter;
private $collectionFactory;
/**
* MassDelete constructor.
*
* @param MagentoBackendAppActionContext $context
* @param MagentoUiComponentMassActionFilter $filter
* @param XigenDataModelResourceModelImportCollectionFactory $collectionFactory
*/
public function __construct(
MagentoBackendAppActionContext $context,
MagentoUiComponentMassActionFilter $filter,
XigenDataModelResourceModelFitmentCollectionFactory $collectionFactory,
XigenDataModelFitmentFactory $fitmentFactory
)
$this->filter = $filter;
$this->fitmentFactory = $fitmentFactory;
parent::__construct($context);
/**
* Execute action.
*
* @return MagentoBackendModelViewResultRedirect
* @throws MagentoFrameworkExceptionLocalizedException
Question updated withRersourceModel@DominicXigen
– Saif Zakir
May 21 at 12:22
coulden't understand this.... !
– Saif Zakir
May 21 at 12:29
add a comment |
Does your resourceModel collection have a key defined?
namespace XigenDataModelResourceModelFitment;
class Collection extends MagentoFrameworkModelResourceModelDbCollectionAbstractCollection
/**
* @var string
*/
protected $_idFieldName = 'fitment_id';
/**
* Define resource model
*
* @return void
*/
protected function _construct()
$this->_init(
XigenDataModelFitment::class,
XigenDataModelResourceModelFitment::class
);
Just for reference here is my MassDelete.php
namespace XigenDataControllerAdminhtmlFitment;
/**
* Mass-Delete Controller.
*/
class MassDelete extends MagentoBackendAppAction
const ADMIN_RESOURCE = 'Xigen_Data::import';
private $filter;
private $collectionFactory;
/**
* MassDelete constructor.
*
* @param MagentoBackendAppActionContext $context
* @param MagentoUiComponentMassActionFilter $filter
* @param XigenDataModelResourceModelImportCollectionFactory $collectionFactory
*/
public function __construct(
MagentoBackendAppActionContext $context,
MagentoUiComponentMassActionFilter $filter,
XigenDataModelResourceModelFitmentCollectionFactory $collectionFactory,
XigenDataModelFitmentFactory $fitmentFactory
)
$this->filter = $filter;
$this->fitmentFactory = $fitmentFactory;
parent::__construct($context);
/**
* Execute action.
*
* @return MagentoBackendModelViewResultRedirect
* @throws MagentoFrameworkExceptionLocalizedException
Does your resourceModel collection have a key defined?
namespace XigenDataModelResourceModelFitment;
class Collection extends MagentoFrameworkModelResourceModelDbCollectionAbstractCollection
/**
* @var string
*/
protected $_idFieldName = 'fitment_id';
/**
* Define resource model
*
* @return void
*/
protected function _construct()
$this->_init(
XigenDataModelFitment::class,
XigenDataModelResourceModelFitment::class
);
Just for reference here is my MassDelete.php
namespace XigenDataControllerAdminhtmlFitment;
/**
* Mass-Delete Controller.
*/
class MassDelete extends MagentoBackendAppAction
const ADMIN_RESOURCE = 'Xigen_Data::import';
private $filter;
private $collectionFactory;
/**
* MassDelete constructor.
*
* @param MagentoBackendAppActionContext $context
* @param MagentoUiComponentMassActionFilter $filter
* @param XigenDataModelResourceModelImportCollectionFactory $collectionFactory
*/
public function __construct(
MagentoBackendAppActionContext $context,
MagentoUiComponentMassActionFilter $filter,
XigenDataModelResourceModelFitmentCollectionFactory $collectionFactory,
XigenDataModelFitmentFactory $fitmentFactory
)
$this->filter = $filter;
$this->fitmentFactory = $fitmentFactory;
parent::__construct($context);
/**
* Execute action.
*
* @return MagentoBackendModelViewResultRedirect
* @throws MagentoFrameworkExceptionLocalizedException
edited May 21 at 12:22
answered May 21 at 12:20
Dominic XigenDominic Xigen
61511
61511
Question updated withRersourceModel@DominicXigen
– Saif Zakir
May 21 at 12:22
coulden't understand this.... !
– Saif Zakir
May 21 at 12:29
add a comment |
Question updated withRersourceModel@DominicXigen
– Saif Zakir
May 21 at 12:22
coulden't understand this.... !
– Saif Zakir
May 21 at 12:29
Question updated with
RersourceModel @DominicXigen– Saif Zakir
May 21 at 12:22
Question updated with
RersourceModel @DominicXigen– Saif Zakir
May 21 at 12:22
coulden't understand this.... !
– Saif Zakir
May 21 at 12:29
coulden't understand this.... !
– Saif Zakir
May 21 at 12:29
add a comment |
Just for reference, this is my code of ui_component listing xml file.
<listingToolbar name="listing_top">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="sticky" xsi:type="boolean">true</item>
</item>
</argument>
<bookmark name="bookmarks"/>
<columnsControls name="columns_controls"/>
<filters name="listing_filters"/>
<massaction name="listing_massaction">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/tree-massactions</item>
</item>
</argument>
<action name="delete">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="type" xsi:type="string">delete</item>
<item name="label" xsi:type="string" translate="true">Delete</item>
<item name="url" xsi:type="url" path="bannerslider/banner/massDelete"/>
<item name="confirm" xsi:type="array">
<item name="title" xsi:type="string" translate="true">Delete Slider</item>
<item name="message" xsi:type="string" translate="true">Are you sure you wan't to delete selected Banners?</item>
</item>
</item>
</argument>
</action>
</massaction>
<paging name="listing_paging"/>
</listingToolbar>
And this is massDelete Controller.
<?php
namespace ABannerSliderControllerAdminhtmlBanner;
use MagentoBackendAppAction;
use MagentoBackendAppActionContext;
use MagentoUiComponentMassActionFilter;
use ABannerSliderModelResourceModelBannerCollectionFactory;
class MassDelete extends Action
protected $filter;
protected $collectionFactory;
public function __construct(
Filter $filter,
CollectionFactory $collectionFactory,
Context $context
)
$this->filter = $filter;
$this->collectionFactory = $collectionFactory;
parent::__construct($context);
public function execute()
$collection = $this->filter->getCollection($this->collectionFactory->create());
$delete = 0;
foreach ($collection as $item)
$item->delete();
$delete++;
$this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.', $delete));
$resultRedirect = $this->resultFactory->create(MagentoFrameworkControllerResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath('*/*/');
add a comment |
Just for reference, this is my code of ui_component listing xml file.
<listingToolbar name="listing_top">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="sticky" xsi:type="boolean">true</item>
</item>
</argument>
<bookmark name="bookmarks"/>
<columnsControls name="columns_controls"/>
<filters name="listing_filters"/>
<massaction name="listing_massaction">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/tree-massactions</item>
</item>
</argument>
<action name="delete">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="type" xsi:type="string">delete</item>
<item name="label" xsi:type="string" translate="true">Delete</item>
<item name="url" xsi:type="url" path="bannerslider/banner/massDelete"/>
<item name="confirm" xsi:type="array">
<item name="title" xsi:type="string" translate="true">Delete Slider</item>
<item name="message" xsi:type="string" translate="true">Are you sure you wan't to delete selected Banners?</item>
</item>
</item>
</argument>
</action>
</massaction>
<paging name="listing_paging"/>
</listingToolbar>
And this is massDelete Controller.
<?php
namespace ABannerSliderControllerAdminhtmlBanner;
use MagentoBackendAppAction;
use MagentoBackendAppActionContext;
use MagentoUiComponentMassActionFilter;
use ABannerSliderModelResourceModelBannerCollectionFactory;
class MassDelete extends Action
protected $filter;
protected $collectionFactory;
public function __construct(
Filter $filter,
CollectionFactory $collectionFactory,
Context $context
)
$this->filter = $filter;
$this->collectionFactory = $collectionFactory;
parent::__construct($context);
public function execute()
$collection = $this->filter->getCollection($this->collectionFactory->create());
$delete = 0;
foreach ($collection as $item)
$item->delete();
$delete++;
$this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.', $delete));
$resultRedirect = $this->resultFactory->create(MagentoFrameworkControllerResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath('*/*/');
add a comment |
Just for reference, this is my code of ui_component listing xml file.
<listingToolbar name="listing_top">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="sticky" xsi:type="boolean">true</item>
</item>
</argument>
<bookmark name="bookmarks"/>
<columnsControls name="columns_controls"/>
<filters name="listing_filters"/>
<massaction name="listing_massaction">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/tree-massactions</item>
</item>
</argument>
<action name="delete">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="type" xsi:type="string">delete</item>
<item name="label" xsi:type="string" translate="true">Delete</item>
<item name="url" xsi:type="url" path="bannerslider/banner/massDelete"/>
<item name="confirm" xsi:type="array">
<item name="title" xsi:type="string" translate="true">Delete Slider</item>
<item name="message" xsi:type="string" translate="true">Are you sure you wan't to delete selected Banners?</item>
</item>
</item>
</argument>
</action>
</massaction>
<paging name="listing_paging"/>
</listingToolbar>
And this is massDelete Controller.
<?php
namespace ABannerSliderControllerAdminhtmlBanner;
use MagentoBackendAppAction;
use MagentoBackendAppActionContext;
use MagentoUiComponentMassActionFilter;
use ABannerSliderModelResourceModelBannerCollectionFactory;
class MassDelete extends Action
protected $filter;
protected $collectionFactory;
public function __construct(
Filter $filter,
CollectionFactory $collectionFactory,
Context $context
)
$this->filter = $filter;
$this->collectionFactory = $collectionFactory;
parent::__construct($context);
public function execute()
$collection = $this->filter->getCollection($this->collectionFactory->create());
$delete = 0;
foreach ($collection as $item)
$item->delete();
$delete++;
$this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.', $delete));
$resultRedirect = $this->resultFactory->create(MagentoFrameworkControllerResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath('*/*/');
Just for reference, this is my code of ui_component listing xml file.
<listingToolbar name="listing_top">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="sticky" xsi:type="boolean">true</item>
</item>
</argument>
<bookmark name="bookmarks"/>
<columnsControls name="columns_controls"/>
<filters name="listing_filters"/>
<massaction name="listing_massaction">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/tree-massactions</item>
</item>
</argument>
<action name="delete">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="type" xsi:type="string">delete</item>
<item name="label" xsi:type="string" translate="true">Delete</item>
<item name="url" xsi:type="url" path="bannerslider/banner/massDelete"/>
<item name="confirm" xsi:type="array">
<item name="title" xsi:type="string" translate="true">Delete Slider</item>
<item name="message" xsi:type="string" translate="true">Are you sure you wan't to delete selected Banners?</item>
</item>
</item>
</argument>
</action>
</massaction>
<paging name="listing_paging"/>
</listingToolbar>
And this is massDelete Controller.
<?php
namespace ABannerSliderControllerAdminhtmlBanner;
use MagentoBackendAppAction;
use MagentoBackendAppActionContext;
use MagentoUiComponentMassActionFilter;
use ABannerSliderModelResourceModelBannerCollectionFactory;
class MassDelete extends Action
protected $filter;
protected $collectionFactory;
public function __construct(
Filter $filter,
CollectionFactory $collectionFactory,
Context $context
)
$this->filter = $filter;
$this->collectionFactory = $collectionFactory;
parent::__construct($context);
public function execute()
$collection = $this->filter->getCollection($this->collectionFactory->create());
$delete = 0;
foreach ($collection as $item)
$item->delete();
$delete++;
$this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.', $delete));
$resultRedirect = $this->resultFactory->create(MagentoFrameworkControllerResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath('*/*/');
answered May 21 at 12:30
Kazim NooraniKazim Noorani
1,1311724
1,1311724
add a comment |
add a comment |
Paste your MassDelete.php with below one:
<?php
namespace ECDownloadsControllerAdminhtmlItems;
use MagentoBackendAppAction;
/**
* Class MassDelete
*/
class MassDelete extends MagentoBackendAppAction
/**
* @return MagentoBackendModelViewResultRedirect
*/
public function __construct(
MagentoBackendAppActionContext $context,
MagentoUiComponentMassActionFilter $filter,
ECDownloadsModelResourceModelItemsCollectionFactory $collectionFactory,
ECDownloadsModelItemFactory $itemFactory
)
$this->filter = $filter;
$this->itemFactory = $itemFactory;
parent::__construct($context);
public function execute()
$ids = $this->getRequest()->getPost();
if ($ids)
$collection = $this->itemFactory->create()
->getCollection()
->addFieldToFilter('downloads_id', array('in' => $ids));
$collectionSize = $collection->getSize();
$deletedItems = 0;
foreach ($collection as $item)
try
$item->delete();
$deletedItems++;
catch (Exception $e)
$this->messageManager->addErrorMessage($e->getMessage());
if ($deletedItems != 0)
if ($collectionSize != $deletedItems)
$this->messageManager->addErrorMessage(
__('Failed to delete %1 fitment item(s).', $collectionSize - $deletedItems)
);
$this->messageManager->addSuccessMessage(
__('A total of %1 fitment item(s) have been deleted.', $deletedItems)
);
/** @var MagentoBackendModelViewResultRedirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(MagentoFrameworkControllerResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath('downloads/index/items');
not working....
– Saif Zakir
May 21 at 12:55
->addFieldToFilter('downloads_id', array('in' => $ids));getting error in this line...
– Saif Zakir
May 21 at 12:55
Exception #0 (Exception): Warning: PDO::quote() expects parameter 1 to be string, object given in /var/www/html/mg.local/vendor/magento/zendframework1/library/Zend/Db/Adapter/Pdo/Abstract.php on line 296
– Saif Zakir
May 21 at 12:56
Are you getting $ids?
– Rutvee Sojitra
May 21 at 13:00
yes... like this: id => 1 and 3:ZendStdlibParameters Object ( [storage:ArrayObject:private] => Array ( [selected] => Array ( [0] => 1 [1] => 3 ) [filters] => Array ( [placeholder] => true ) [namespace] => ec_downloads_items [form_key] => TfQNKpKNTlflHLwE ) )
– Saif Zakir
May 21 at 13:07
add a comment |
Paste your MassDelete.php with below one:
<?php
namespace ECDownloadsControllerAdminhtmlItems;
use MagentoBackendAppAction;
/**
* Class MassDelete
*/
class MassDelete extends MagentoBackendAppAction
/**
* @return MagentoBackendModelViewResultRedirect
*/
public function __construct(
MagentoBackendAppActionContext $context,
MagentoUiComponentMassActionFilter $filter,
ECDownloadsModelResourceModelItemsCollectionFactory $collectionFactory,
ECDownloadsModelItemFactory $itemFactory
)
$this->filter = $filter;
$this->itemFactory = $itemFactory;
parent::__construct($context);
public function execute()
$ids = $this->getRequest()->getPost();
if ($ids)
$collection = $this->itemFactory->create()
->getCollection()
->addFieldToFilter('downloads_id', array('in' => $ids));
$collectionSize = $collection->getSize();
$deletedItems = 0;
foreach ($collection as $item)
try
$item->delete();
$deletedItems++;
catch (Exception $e)
$this->messageManager->addErrorMessage($e->getMessage());
if ($deletedItems != 0)
if ($collectionSize != $deletedItems)
$this->messageManager->addErrorMessage(
__('Failed to delete %1 fitment item(s).', $collectionSize - $deletedItems)
);
$this->messageManager->addSuccessMessage(
__('A total of %1 fitment item(s) have been deleted.', $deletedItems)
);
/** @var MagentoBackendModelViewResultRedirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(MagentoFrameworkControllerResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath('downloads/index/items');
not working....
– Saif Zakir
May 21 at 12:55
->addFieldToFilter('downloads_id', array('in' => $ids));getting error in this line...
– Saif Zakir
May 21 at 12:55
Exception #0 (Exception): Warning: PDO::quote() expects parameter 1 to be string, object given in /var/www/html/mg.local/vendor/magento/zendframework1/library/Zend/Db/Adapter/Pdo/Abstract.php on line 296
– Saif Zakir
May 21 at 12:56
Are you getting $ids?
– Rutvee Sojitra
May 21 at 13:00
yes... like this: id => 1 and 3:ZendStdlibParameters Object ( [storage:ArrayObject:private] => Array ( [selected] => Array ( [0] => 1 [1] => 3 ) [filters] => Array ( [placeholder] => true ) [namespace] => ec_downloads_items [form_key] => TfQNKpKNTlflHLwE ) )
– Saif Zakir
May 21 at 13:07
add a comment |
Paste your MassDelete.php with below one:
<?php
namespace ECDownloadsControllerAdminhtmlItems;
use MagentoBackendAppAction;
/**
* Class MassDelete
*/
class MassDelete extends MagentoBackendAppAction
/**
* @return MagentoBackendModelViewResultRedirect
*/
public function __construct(
MagentoBackendAppActionContext $context,
MagentoUiComponentMassActionFilter $filter,
ECDownloadsModelResourceModelItemsCollectionFactory $collectionFactory,
ECDownloadsModelItemFactory $itemFactory
)
$this->filter = $filter;
$this->itemFactory = $itemFactory;
parent::__construct($context);
public function execute()
$ids = $this->getRequest()->getPost();
if ($ids)
$collection = $this->itemFactory->create()
->getCollection()
->addFieldToFilter('downloads_id', array('in' => $ids));
$collectionSize = $collection->getSize();
$deletedItems = 0;
foreach ($collection as $item)
try
$item->delete();
$deletedItems++;
catch (Exception $e)
$this->messageManager->addErrorMessage($e->getMessage());
if ($deletedItems != 0)
if ($collectionSize != $deletedItems)
$this->messageManager->addErrorMessage(
__('Failed to delete %1 fitment item(s).', $collectionSize - $deletedItems)
);
$this->messageManager->addSuccessMessage(
__('A total of %1 fitment item(s) have been deleted.', $deletedItems)
);
/** @var MagentoBackendModelViewResultRedirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(MagentoFrameworkControllerResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath('downloads/index/items');
Paste your MassDelete.php with below one:
<?php
namespace ECDownloadsControllerAdminhtmlItems;
use MagentoBackendAppAction;
/**
* Class MassDelete
*/
class MassDelete extends MagentoBackendAppAction
/**
* @return MagentoBackendModelViewResultRedirect
*/
public function __construct(
MagentoBackendAppActionContext $context,
MagentoUiComponentMassActionFilter $filter,
ECDownloadsModelResourceModelItemsCollectionFactory $collectionFactory,
ECDownloadsModelItemFactory $itemFactory
)
$this->filter = $filter;
$this->itemFactory = $itemFactory;
parent::__construct($context);
public function execute()
$ids = $this->getRequest()->getPost();
if ($ids)
$collection = $this->itemFactory->create()
->getCollection()
->addFieldToFilter('downloads_id', array('in' => $ids));
$collectionSize = $collection->getSize();
$deletedItems = 0;
foreach ($collection as $item)
try
$item->delete();
$deletedItems++;
catch (Exception $e)
$this->messageManager->addErrorMessage($e->getMessage());
if ($deletedItems != 0)
if ($collectionSize != $deletedItems)
$this->messageManager->addErrorMessage(
__('Failed to delete %1 fitment item(s).', $collectionSize - $deletedItems)
);
$this->messageManager->addSuccessMessage(
__('A total of %1 fitment item(s) have been deleted.', $deletedItems)
);
/** @var MagentoBackendModelViewResultRedirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(MagentoFrameworkControllerResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath('downloads/index/items');
answered May 21 at 12:41
Rutvee SojitraRutvee Sojitra
1,8421321
1,8421321
not working....
– Saif Zakir
May 21 at 12:55
->addFieldToFilter('downloads_id', array('in' => $ids));getting error in this line...
– Saif Zakir
May 21 at 12:55
Exception #0 (Exception): Warning: PDO::quote() expects parameter 1 to be string, object given in /var/www/html/mg.local/vendor/magento/zendframework1/library/Zend/Db/Adapter/Pdo/Abstract.php on line 296
– Saif Zakir
May 21 at 12:56
Are you getting $ids?
– Rutvee Sojitra
May 21 at 13:00
yes... like this: id => 1 and 3:ZendStdlibParameters Object ( [storage:ArrayObject:private] => Array ( [selected] => Array ( [0] => 1 [1] => 3 ) [filters] => Array ( [placeholder] => true ) [namespace] => ec_downloads_items [form_key] => TfQNKpKNTlflHLwE ) )
– Saif Zakir
May 21 at 13:07
add a comment |
not working....
– Saif Zakir
May 21 at 12:55
->addFieldToFilter('downloads_id', array('in' => $ids));getting error in this line...
– Saif Zakir
May 21 at 12:55
Exception #0 (Exception): Warning: PDO::quote() expects parameter 1 to be string, object given in /var/www/html/mg.local/vendor/magento/zendframework1/library/Zend/Db/Adapter/Pdo/Abstract.php on line 296
– Saif Zakir
May 21 at 12:56
Are you getting $ids?
– Rutvee Sojitra
May 21 at 13:00
yes... like this: id => 1 and 3:ZendStdlibParameters Object ( [storage:ArrayObject:private] => Array ( [selected] => Array ( [0] => 1 [1] => 3 ) [filters] => Array ( [placeholder] => true ) [namespace] => ec_downloads_items [form_key] => TfQNKpKNTlflHLwE ) )
– Saif Zakir
May 21 at 13:07
not working....
– Saif Zakir
May 21 at 12:55
not working....
– Saif Zakir
May 21 at 12:55
->addFieldToFilter('downloads_id', array('in' => $ids)); getting error in this line...– Saif Zakir
May 21 at 12:55
->addFieldToFilter('downloads_id', array('in' => $ids)); getting error in this line...– Saif Zakir
May 21 at 12:55
Exception #0 (Exception): Warning: PDO::quote() expects parameter 1 to be string, object given in /var/www/html/mg.local/vendor/magento/zendframework1/library/Zend/Db/Adapter/Pdo/Abstract.php on line 296– Saif Zakir
May 21 at 12:56
Exception #0 (Exception): Warning: PDO::quote() expects parameter 1 to be string, object given in /var/www/html/mg.local/vendor/magento/zendframework1/library/Zend/Db/Adapter/Pdo/Abstract.php on line 296– Saif Zakir
May 21 at 12:56
Are you getting $ids?
– Rutvee Sojitra
May 21 at 13:00
Are you getting $ids?
– Rutvee Sojitra
May 21 at 13:00
yes... like this: id => 1 and 3:
ZendStdlibParameters Object ( [storage:ArrayObject:private] => Array ( [selected] => Array ( [0] => 1 [1] => 3 ) [filters] => Array ( [placeholder] => true ) [namespace] => ec_downloads_items [form_key] => TfQNKpKNTlflHLwE ) )– Saif Zakir
May 21 at 13:07
yes... like this: id => 1 and 3:
ZendStdlibParameters Object ( [storage:ArrayObject:private] => Array ( [selected] => Array ( [0] => 1 [1] => 3 ) [filters] => Array ( [placeholder] => true ) [namespace] => ec_downloads_items [form_key] => TfQNKpKNTlflHLwE ) )– Saif Zakir
May 21 at 13:07
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f275467%2fmagento-2-mass-delete-php-code-not-working%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you please add more code of ui_component xml file?
– Kazim Noorani
May 21 at 12:22
@KazimNoorani Updated....
– Saif Zakir
May 21 at 12:27
Please check my answer. Might help you.
– Kazim Noorani
May 21 at 12:32
Is it helpful ?
– Kazim Noorani
May 21 at 12:38
I can't see the <item> tag name provider and <dataSource> tag process and make the UI component work with this data.
– Shekhar Suman
May 22 at 9:33