Skip to main content
3 votes
Accepted

Magento 2.4 alter contact form post values using plugin afterExecute

use before plugin instead of after plugin. public function beforeExecute(\Magento\Contact\Controller\Index\Post $subject) { $comment = $subject->getRequest()->getParam('comment', false); ...
Ronak Chauhan's user avatar
3 votes

Magento 2.3.4 Plugin Sitemap not working

I've found out that my plugin is firing ok after printing in __constructor bu method afterCollectSitemapItems not any more. So using public method generateXml like so: public function __construct( ...
Juliano Vargas's user avatar
3 votes
Accepted

Cart page fatal error after creating a product collection plugin, Magento 2.3

In case you are using the after plugin, you must have a $result in the arguments first, and it must return the $result. See example: <?php namespace Vendor\Module\Plugin\Catalog\Model\...
Siarhey Uchukhlebau's user avatar
3 votes

Can I access changed parameters in an after/around plugin?

There is no way to access that value in either an after or around plugin.
Shawn Abramson's user avatar
3 votes
Accepted

Get Product info from afterAddProduct Plugin in magento 2

You are able to access the arguments passed to the original method as below: public function afterAddProduct($subject,$result, $product, $params) { }
Daniel Truong's user avatar
3 votes

I cant seem to write an Plugin for \Magento\ImportExport\Model\Import\AbstractSource

The class does not seem to be generated via object manager, but via new $className in \Magento\ImportExport\Model\Import\Adapter::factory
Alex's user avatar
  • 14k
2 votes
Accepted

Unable to get newly inserted Product's Id using After Plugin for Catalog Product save controller method

The variable $product is not accessible from outside the save method. The only exceptioon is the event controller_action_catalog_product_save_entity_after. But the product builder puts the product ...
HelgeB's user avatar
  • 4,541
2 votes
Accepted

Magento2: Intercept category moved inside tree

I looked at this briefly and couldn't find the method you were trying to write a plugin for. The method move does exist and should be appropriate for what you're trying to do, try the code below ...
jamil's user avatar
  • 985
2 votes
Accepted

Plugin isn't working in Magento2 local host

You di.xml file should have below code: <?xml version="1.0"?> <config> <type name="Magento\Catalog\Model\Product"> <plugin name="InchooProduct" type="Inchoo\Custom\Plugins\...
Prashant Valanda's user avatar
2 votes

Resourcemodel plugin not working - Magento2

You do not need to extend any class in your Plugin, Please try below code <?php namespace Mymodule\Orderedproductsreport\Plugin; class ProductSoldCollection { public function ...
Kishan Savaliya's user avatar
2 votes

Can I access changed parameters in an after/around plugin?

@shawn-abramson, right but if you do some changes at the original method then you can access the parameters of the change at around, after plugin. If you pass this two-parameters ($room, $options) ...
Amit Bera's user avatar
  • 77.7k
2 votes
Accepted

Magento 2 Plugin Not Extending Model - Finally Solved It

After many many days of banging my head on a wall, I've finally solved it. I had two modules set up originally: Mynamespace\Grouped\ Mynamespace\Plugingrouped Nothing I did would make the plugin ...
wjp_bill's user avatar
  • 330
2 votes

Magento 2.3.4 Plugin Sitemap not working

Try this below and add your die as well public function __construct( \Magento\Sitemap\Helper\Data $helper ) { $this->helper = $helper; } public function ...
jibin george's user avatar
2 votes
Accepted

New Order Send custom email template in Magento 2.4

In Magento Magento\Sales\Model\Order\Email\Sender from the email template for orde. If you want customization then you have to work on prepareTemplate() method. You need to override this class. Here ...
Amit Bera's user avatar
  • 77.7k
2 votes
Accepted

After Plugin - Is it compulsory to return result?

As we can see in \Magento\Framework\Interception\Interceptor::___callPlugins:146, return value of after plugin will be used as result for function. foreach ($currentPluginInfo[DefinitionInterface::...
Max's user avatar
  • 4,064
1 vote

New Order Send custom email template in Magento 2.4

@Amit Bera is great answer but i have describe more. Using preference override Model file.Below steps /app/code/Stack/Exchange/etc/di.xml <?xml version="1.0"?> <!-- /** * Dependency ...
Mohit Patel's user avatar
  • 3,968
1 vote

Magento 2 custom shipping method carrier is not showing after selecting the method from dropdown in order shipment backend

Without seeing your config.xml, I believe Magento is failing to create a Carrier object, thus returning 'Custom Value' as a fallback title: \Magento\Rma\Block\Adminhtml\Rma\Edit\Tab\General\Shipping\...
kookaburra's user avatar
1 vote

Magento 2.4 alter contact form post values using plugin afterExecute

Try before plugin with below code <?php declare(strict_types=1); namespace Vendor\MyModule\Plugin\Frontend\Magento\Contact\Controller\Index; class Post { public function beforeExecute( ...
Rahul Barot's user avatar
  • 1,122
1 vote
Accepted

What's the correct way of having two different plugins for one method?

I think this should work, but you added the same plugin name on both instances plugin name="order_repository" and according to the doc, we have: <plugin name="{pluginName}" ...
Diana's user avatar
  • 5,280
1 vote
Accepted

Magento 2 - Write plugin for API interface

The folder in which your di file is placed is key. In your example the plugin only get executed for the frontend area. I recommend putting it without frontend so it is used everywhere. If this is not ...
CloudySi's user avatar
  • 374
1 vote
Accepted

Plugin for an existing plugin

Yes It's Possible possible to create a plugin for an existing plugin class . The sortOrder property from the plugin node declared in di.xml determines the plugin’s prioritization when more than one ...
Msquare's user avatar
  • 9,328
1 vote
Accepted

Execute after plugin: how to know no error occurred?

If the method you are using throws an exception. The afterPlugin will not be executed. You can try using this code. class ValidateSomething { public function afterBeforeSave(Product $product): ...
Nadeem Sayyed's user avatar
1 vote

How do i get createAccount methods argument in after plugin Magento 2?

You can use the arguments of the observed method in your after plugin as well. As I can see you are observing following method which has three arguments \Magento\Customer\Model\AccountManagement:...
Abdul Pathan's user avatar
  • 2,832
1 vote
Accepted

Magento 2 how to get get product ID in after plugin?

In afterAddProduct(), you can get the product Id with $requestInfo param. Below is the example code for getting product Id in afterAddProduct(). public function afterAddProduct($subject, $productInfo,...
Sumit's user avatar
  • 4,968
1 vote
Accepted

Plugin always breaks the core Flatrate Shipping method

Update your plugin file using this below code. afterCollectRates function missing one arguement. <?php namespace MyLearning\CustomFlatrate\Plugin; class Flatrate { protected $...
Rohan Hapani's user avatar
  • 17.5k
1 vote
Accepted

Execute Plugin Class from specific module in Magento2

I'm not sure if I understood your problem, but you may check the modulename of the request in your plugin methods and execute the code only if the request module name matches. For example adding some ...
HelgeB's user avatar
  • 4,541
1 vote
Accepted

Resourcemodel plugin not working - Magento2

Your namespace is wrong try this. <?php namespace Mymodule\Orderedproductsreport\Plugin; class ProductSoldCollection extends \Magento\Reports\Model\ResourceModel\Order\Collection { public ...
Rakesh Varma's user avatar
  • 2,236
1 vote

Magento 2 - Create a log file in plugin that will print log when data is inserted in database

To generate log file you can use below code. add pass data as per your need. $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/logfile.log'); $logger = new \Zend\Log\Logger(); $logger->...
anonymous's user avatar
  • 3,752
1 vote

Around Plugins ( Interceptors) in magento can be used to suppress before and after plugin execution?

Why not wrap everything inside around plugin for your case? So that: public function aroundFunction(\My\Module\Model\MyUtility $subject, callable $proceed){ //If condition is true if (true){ ...
PY Yick's user avatar
  • 2,705
1 vote
Accepted

Override Shipping Rates at checkout

Solution worked for me: <?php namespace Vendor\Model\Plugin\Model\Quote\Address\RateResult; class MethodPlugin { public function afterSetPrice($subject) { $new_price = "2.00"; ...
SNAFU's user avatar
  • 306

Only top scored, non community-wiki answers of a minimum length are eligible