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);
...
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(
...
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\...
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.
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)
{
}
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
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 ...
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 ...
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\...
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 ...
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) ...
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 ...
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 ...
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 ...
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::...
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 ...
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\...
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(
...
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}" ...
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 ...
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 ...
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): ...
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:...
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,...
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 $...
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 ...
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 ...
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->...
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){
...
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";
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
after-plugin × 57magento2 × 43
plugin × 24
magento2.4 × 6
magento2.3 × 5
checkout × 3
shipping-methods × 3
before-plugin × 3
product × 2
php × 2
event-observer × 2
addtocart × 2
rest-api × 2
resource-model × 2
override-model × 2
interceptor × 2
around-plugin × 2
database × 1
magento2.2 × 1
orders × 1
customer × 1
api × 1
collection × 1
sales-order × 1
overrides × 1