-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor - cleanup unnecessary around plugins #28767
Refactor - cleanup unnecessary around plugins #28767
Conversation
after: \Magento\GroupedProduct\Helper\Product\Configuration\Plugin\Grouped::afterGetOptions \Magento\ConfigurableProduct\Helper\Product\Configuration\Plugin::afterGetOptions \Magento\AdvancedSearch\Model\Indexer\Fulltext\Plugin\CustomerGroup::afterSave \Magento\Catalog\Model\Indexer\Product\Price\Plugin\CustomerGroup::afterSave \Magento\CatalogSearch\Model\Attribute\SearchWeight::afterSave \Magento\CatalogUrlRewrite\Model\Category\Plugin\Category\Remove::afterDelete \Magento\ConfigurableProduct\Model\Entity\Product\Attribute\Group\AttributeMapper\Plugin::afterMap \Magento\ConfigurableProduct\Plugin\Model\ResourceModel\Product::afterDelete \Magento\Customer\Model\Plugin\CustomerFlushFormKey::afterExecute \Magento\GroupedProduct\Model\ResourceModel\Product\Link\RelationPersister::afterDeleteProductLink \Magento\Theme\Model\Indexer\Design\Config\Plugin\Store::afterSave \Magento\Theme\Model\Indexer\Design\Config\Plugin\Website::afterSave before: \Magento\CatalogInventory\Plugin\MassUpdateProductAttribute::beforeExecute
Hi @lewisvoncken. Thank you for your contribution
❗ Automated tests can be triggered manually with an appropriate comment:
You can find more information about the builds here ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review. For more details, please, review the Magento Contributor Guide documentation. |
@magento run all tests |
@magento run all tests |
@@ -118,7 +118,7 @@ public function testAroundSave( | |||
* | |||
* @return array | |||
*/ | |||
public function aroundSaveDataProvider(): array | |||
public function afterSaveDataProvider(): array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is data provider, please update place where it is used
*/ | ||
public function aroundExecute(Save $subject, callable $proceed) | ||
public function beforeExecute(Save $subject) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't really need to change arguments for "save", so it's better to use void
return type here and not use return statement at all
public function beforeExecute(Save $subject) | |
public function beforeExecute(Save $subject): void |
@@ -101,16 +100,16 @@ public function aroundExecute(Save $subject, callable $proceed) | |||
$this->updateInventoryInProducts($productIds, $websiteId, $inventoryData); | |||
} | |||
|
|||
return $proceed(); | |||
return []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return []; |
} catch (\Magento\Framework\Exception\LocalizedException $e) { | ||
$this->messageManager->addErrorMessage($e->getMessage()); | ||
return $proceed(); | ||
return []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return []; |
} catch (\Exception $e) { | ||
$this->messageManager->addExceptionMessage( | ||
$e, | ||
__('Something went wrong while updating the product(s) attributes.') | ||
); | ||
return $proceed(); | ||
return []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return []; |
\Magento\Catalog\Model\ResourceModel\Attribute $subject, | ||
\Closure $proceed, | ||
\Magento\Catalog\Model\ResourceModel\Attribute $result, | ||
\Magento\Framework\Model\AbstractModel $attribute | ||
) { | ||
$isNew = $attribute->isObjectNew(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think after save it will be always "false", probably that's why we had there "around" plugin. Could you double check it?
\Magento\Catalog\Model\ResourceModel\Product $subject, | ||
\Closure $proceed, | ||
\Magento\Catalog\Model\ResourceModel\Product $result, | ||
\Magento\Catalog\Model\Product $product | ||
) { | ||
$configurableProductIds = $this->configurable->getParentIdsByChild($product->getId()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure this still will be available after deleting product. Please double check it
*/ | ||
public function aroundDeleteProductLink(Link $subject, \Closure $proceed, $linkId) | ||
public function afterDeleteProductLink(Link $subject, Link $result, $linkId) | ||
{ | ||
/** @var \Magento\Catalog\Model\ProductLink\Link $link */ | ||
$link = $this->linkFactory->create(); | ||
$subject->load($link, $linkId, $subject->getIdFieldName()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it will not work after deleting
* @return StoreStore | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function aroundSave(StoreStore $subject, \Closure $proceed) | ||
public function afterSave(StoreStore $subject, StoreStore $result) | ||
{ | ||
$isObjectNew = $subject->getId() == 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks liike this will be always false, as object already saved and have id
* @return StoreWebsite | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function aroundSave(StoreWebsite $subject, \Closure $proceed) | ||
public function afterSave(StoreWebsite $subject, StoreWebsite $result) | ||
{ | ||
$isObjectNew = $subject->getId() == 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks liike this will be always false, as object already saved and have id
Hi @lewisvoncken, |
@lewisvoncken I am closing this PR now due to inactivity. |
Hi @lewisvoncken, thank you for your contribution! |
Description (*)
Changed the following around plugins to before and after plugins:
Starting from Magento 2.2 it is no longer necessary to use around plugins in cases which you now could just use an after which also contains the parameters.
This refactor is because of performance reasons:

source:
https://devdocs.magento.com/guides/v2.4/extension-dev-guide/plugins.html#around-methods
Fixed Issues (if relevant)
around
plugin #27912Contribution checklist (*)