Magento2: Magento Code Sniff Issue

Created on 31 Jul 2017  路  5Comments  路  Source: magento/magento2

Hello,

I am submitting my extension on magento marketplace but the extension get rejects everytime due to the warning "Model LSD method delete() detected in loop" or "Model LSD method save() detected in loop". Please let me know how can fix those types of warnings for massActions.

I checked magento's core module and found that same way used in script for mass delete and mass update.
CMS Module: Magento-CE-2.1.6/vendor/magento/module-cms/Controller/Adminhtml/Page/MassDelete.php

I don't understand why my module is rejected when I am using same code in my custom module.

Thanks,
Vishal

Most helpful comment

Yes sure. The walk method internally will iterate over the items and execute the method name passed as the parameter to the walk method.

Here is an example from the Magento core:
app/code/Magento/Sales/Cron/CleanExpiredQuotes.php

All 5 comments

Hello Vishal,

Sometimes it happens that Magento core doesn't abide by the coding standards set by Magento itself.

As for the solution to your problem you will have to use collection instead of model load.

So you have to load the collection of items you would like to perform a mass action on using the collection filter methods and then use ->walk() method to perform the mass action like ->walk('delete') will do a mass delete of the all the collection items loaded

Thanks for your reply. Can I use walk for save() save method too?

Yes sure. The walk method internally will iterate over the items and execute the method name passed as the parameter to the walk method.

Here is an example from the Magento core:
app/code/Magento/Sales/Cron/CleanExpiredQuotes.php

Rules like https://github.com/magento/marketplace-eqp were introduced not very long ago. While Magento 2 still uses a lot of legacy code (and will have to use due to backward compatibility constraints) there is no reason to write any new code in such a way.

Problems with such sniffs should be reported in https://github.com/magento/marketplace-eqp, for questions how to solve problem with your code it is better to use Magento Stack Exchange.

Thanks for your response guys!!

Was this page helpful?
0 / 5 - 0 ratings