How to override this below file? Pepperjam\Network\Model\Beacon\Itemized.php

I need to override protected function inside this file, I tried with reference but not working

I have add override using plugin method but it is not working please advise if I am wrong:

In etc/di.xml add below code

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Pepperjam\Network\Model\Beacon\Itemized">
    <plugin name="cmarix-pepperjam-itemized-model" type="[VendorName][ModuleName]\Plugin\ItemizedPlugin" sortOrder="1" />

And In [VendorName][ModuleName]\Plugin\ItemizedPlugin.php file add below code


namespace [VendorName][ModuleName]\Plugin;

class ItemizedPlugin
    protected function aftergetQuantity($item)
        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/afterlog.log');
        $logger = new \Zend\Log\Logger();
        $logger->info('Your text message');

        if ($item->getProduct()->canConfigure()) {
            return 0;
        } else {
            return (int) $item->getQtyOrdered();


  • try with <preference in your di.xml – Arif Ahmad Sep 12 '19 at 12:32
  • tried not working – Arjun Sep 12 '19 at 13:12
  • Where is this file coming from? Is it a magento module? – Philipp Sander Sep 12 '19 at 15:03
  • Have you got the solution? – aravind Sep 13 '19 at 12:23
  • You cannot override a protected/public function using Plugin or preference..Is this your custom module? – aravind Sep 13 '19 at 12:24

You can easily override the file as this following steps

Step 1: you need to create di.xml file in your own Module. Path: [VendorName]\[ModuleName]\etc\

Step 2: Write this following code in your di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Pepperjam\Network\Model\Beacon\Itemized" type="[VendorName]\[ModuleName]\Model\Beacon\Itemized"/>
  • I have already override using same way but it is not override I have created di.xml file in etc folder and added below code: <?xml version="1.0"?> <config xmlns:xsi="w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Pepperjam\Network\Model\Beacon\Itemized" type="[VendorName][ModuleName]\Model\Beacon\Itemized" /> </config> After that I have created model file in below location: [VendorName][ModuleName]\Model\Beacon\Itemized.php And added function that I want to override – Arjun Sep 13 '19 at 7:49
  • okay, now you can try plugin after to override the method. – Oscprofessionals Sep 13 '19 at 8:07
  • But I need to override protected method so it is not override using plugin – Arjun Sep 13 '19 at 8:46
  • I have updated my question please chk & advice – Arjun Sep 13 '19 at 12:12
  • Can you share Itemized.php code here (Pepperjam\Network\Model\Beacon\Itemized). – Oscprofessionals Sep 16 '19 at 8:50

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.