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\ResourceModel\Product; use Magento\Catalog\Model\ResourceModel\Product\Collection; class CollectionPlugin { /** * @param Collection $subject * @param bool $...


3

There is no way to access that value in either an after or around plugin.


2

You are able to access the arguments passed to the original method as below: public function afterAddProduct($subject,$result, $product, $params) { }


2

The class does not seem to be generated via object manager, but via new $className in \Magento\ImportExport\Model\Import\Adapter::factory


2

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 into registry, so you may access the product from there. This code should work in my opinion, but I didn't test it: public function __construct( \...


2

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 instead: namespace Vendor\Module\Model\Plugin; class Category { public function afterMove(\Magento\Catalog\Model\Category $subject, $result) { echo '...


2

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\Product" sortOrder="1" disabled="false"/> </type> </config> Type name: A class, interface, or virtual type, which is observed by a plugin. ...


2

@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) with a return of original function then you can data of both $room, $options at around and after plugin. Original Method: class vendorClass { function ...


2

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 show up until I combined the two into module. I now have the Model override and plugin in one module and it's working. In case anyone else is having the same ...


2

You do not need to extend any class in your Plugin, Please try below code <?php namespace Mymodule\Orderedproductsreport\Plugin; class ProductSoldCollection { public function afterAddOrderedQty( \Magento\Reports\Model\ResourceModel\Product\Sold\Collection $subject, $result,$from = '', $to = '' ) { $writer = new \Zend\...


1

Your namespace is wrong try this. <?php namespace Mymodule\Orderedproductsreport\Plugin; class ProductSoldCollection extends \Magento\Reports\Model\ResourceModel\Order\Collection { public function afterAddOrderedQty( \Magento\Reports\Model\ResourceModel\Product\Sold\Collection $subject, $result,$from = '', $to = '' ) { $...


1

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->addWriter($writer); $logger->info('Simple Text Log'); // Simple Text Log $logger->info('Array Log'.print_r($myArrayVar, true)); // Array Log For more ...


1

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){ //BeforeFunction //Do sonething //ExecuteFunction $proceed(); } }


1

Solution worked for me: <?php namespace Vendor\Model\Plugin\Model\Quote\Address\RateResult; class MethodPlugin { public function afterSetPrice($subject) { $new_price = "2.00"; $subject->setData("price", $new_price); return $subject; } }


1

The method name needs to be afterGetName. Also getData(key:'price') is wrong. You can either use ->getData('price') or ->getPrice(). <?php namespace Inchoo\Custom\Plugins; Class Product { public function afterGetName(\Magento\Catalog\Model\Product $product, $name) { $price = $product->getPrice(); if ($price < 60 ) { $name .= " So ...


1

I found solution using below way. For Wishlist product page. app/code/Namespace/Modulename/etc/frontend/di.xml <type name="Magento\Wishlist\Block\Customer\Wishlist\Item\Column\Image"> <plugin name="Namespace_Modulename::wishlistProduct" type="Namaespace\Modulename\Plugin\Customer\Wishlist\Item\Column\Image" sortOrder="18" /> </type>...


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