0

app/code/Mymodule/Orderedproductsreport/etc/di.xml

<type name="Magento\Reports\Model\ResourceModel\Product\Sold\Collection">
   <plugin disabled="false" name="Mymodule_Module_Plugin_ProductSoldCollection" sortOrder="2" type="Mymodule\Orderedproductsreport\Plugin\ProductSoldCollection"/>
</type>

app/code/Mymodule/Orderedproductsreport/Plugin/ProductSoldCollection.php

<?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 = ''
    ) {


        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/ProductSoldCollection.log');
        $logger = new \Zend\Log\Logger();
        $logger->addWriter($writer);
        $logger->info('Your text message');

        return $this;
    }


}

public function afterAddOrderedQty isn't working.

Can any one help me what i'm doing wrong here?

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 = ''
    ) {


        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/ProductSoldCollection.log');
        $logger = new \Zend\Log\Logger();
        $logger->addWriter($writer);
        $logger->info('Your text message');

        return $this;
    }


}

UPDATE

use this class name.

class ProductSoldCollection extends \Magento\Reports\Model\ResourceModel\Product\Sold\Collection

and fire following command.

php bin/magento c:c
php bin/magento s:d:c
| improve this answer | |
  • still not working and not showing any errors – Jimit Bhavsar Nov 15 '19 at 9:03
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\Log\Writer\Stream(BP . '/var/log/ProductSoldCollection.log');
        $logger = new \Zend\Log\Logger();
        $logger->addWriter($writer);
        $logger->info('Your text message');

        return $subject;
    }


}

I verify this thing in My Magento with this URL base_url/admin/reports/report_product/sold/ and that is working in my case.

Hope this will help!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.