1

I want to override isAvailable() method of Magento\Paypal\Model\Payflowpro.php

I have tried below steps but it is not working for me.

app/code/Moduleoverride/Payflowpaypal/etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Moduleoverride_Payflowpaypal" setup_version="1.0.1">
</module>
</config>

app/code/Moduleoverride/Payflowpaypal/registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Moduleoverride_Payflowpaypal',
__DIR__
);

app/code/Moduleoverride/Payflowpaypal/etc/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="Magento\Paypal\Model\Payflowpro" type="Moduleoverride\Payflowpaypal\Model\Payflowpro" />
</config>

app/code/Moduleoverride/Payflowpaypal/Model/Payflowpro.php

namespace Moduleoverride\Payflowpaypal\Model;

class Payflowpro extends \Magento\Paypal\Model\Payflowpro
{
  public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null)
    { echo "This is working";exit;
    }
}
2

Use Plugin instead of overwrite whole class.

app/code/SR/MagentoCommunity/etc/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">
    <type name="Magento\Paypal\Model\Payflowpro">
        <plugin name="sr_payflowpro"
                type="SR\MagentoCommunity\Plugin\Paypal\Model\Payflowpro" sortOrder="1"/>
    </type>
</config>

app/code/SR/MagentoCommunity/Plugin/Paypal/Model/Payflowpro.php

<?php
namespace SR\MagentoCommunity\Plugin\Paypal\Model;


class Payflowpro
{
    /**
     * @var \Psr\Log\LoggerInterface
     */
    private $logger;

    /**
     * Payflowpro constructor.
     * @param \Psr\Log\LoggerInterface $logger
     */
    public function __construct(
        \Psr\Log\LoggerInterface $logger
    ) {
        $this->logger = $logger;
    }

    /**
     * @param \Magento\Paypal\Model\Payflowpro $subject
     * @param $result
     * @return mixed
     */
    public function afterIsAvailable(
        \Magento\Paypal\Model\Payflowpro $subject,
        $result
    ) {
        $this->logger->info(__METHOD__);
        return $result;
    }
}

Not tested code.

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.