Due to PayPal Error, i am updating the following function in app/code/Magento/Paypal/Model/Api/Nvp.php
, not edit the entire code just update a single function.
Function Name : function _applyStreetAndRegionWorkarounds()
My Preference:
app/code/Gta/PayPalPreference/registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Gta_PayPalPreference',
__DIR__
);
app/code/Gta/PayPalPreference/etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="Gta_PayPalPreference" schema_version="0.0.1" setup_version="0.0.1"></module>
</config>
app/code/Gta/PayPalPreference/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\Api\Nvp"
type="Gta\PayPalPreference\Model\Api\Nvp"
/>
</config>
app/code/Gta/PayPalPreference/Model/Api/Nvp.php
<?php
declare(strict_types=1);
namespace Gta\PayPalPreference\Model\Api;
use Magento\Store\Model\StoreManagerInterface;
class Nvp extends \Magento\Paypal\Model\Api\Nvp
{
/**
* @var StoreManagerInterface
*/
private $storeManager;
public function __construct(
\Magento\Customer\Helper\Address $customerAddress,
\Psr\Log\LoggerInterface $logger,
\Magento\Payment\Model\Method\Logger $customLogger,
\Magento\Framework\Locale\ResolverInterface $localeResolver,
\Magento\Directory\Model\RegionFactory $regionFactory,
\Magento\Directory\Model\CountryFactory $countryFactory,
\Magento\Paypal\Model\Api\ProcessableExceptionFactory $processableExceptionFactory,
\Magento\Framework\Exception\LocalizedExceptionFactory $frameworkExceptionFactory,
\Magento\Framework\HTTP\Adapter\CurlFactory $curlFactory,
StoreManagerInterface $storeManager,
array $data = []
) {
parent::__construct($customerAddress, $logger, $customLogger, $localeResolver, $regionFactory, $countryFactory, $processableExceptionFactory, $frameworkExceptionFactory, $curlFactory, $data);
$this->storeManager = $storeManager;
}
protected function _applyStreetAndRegionWorkarounds(DataObject $address)
{
// e.g. if you do not want to run the code on website id = 2
if ($this->storeManager->getWebsite()->getId() == 1) {
parent::_applyStreetAndRegionWorkarounds($address);
return;
}
if ($address->getData('street2') !== null) {
$address->setStreet(implode("\n", [$address->getData('street'), $address->getData('street2')]));
$address->unsetData('street2');
}
if ($address->getCountryId() && $address->getRegion()) {
$regions = $this->_countryFactory->create()
->loadByCode($address->getCountryId())
->getRegionCollection()
->addRegionCodeOrNameFilter($address->getRegion())
->setPageSize(1);
if ($regions->count()) {
$regionItems = $regions->getItems();
$region = array_shift($regionItems);
$address->setRegionId($region->getId());
$address->setExportedKeys(array_merge($address->getExportedKeys(), ['region_id']));
}
}
}
}
I am getting the following error during the compile command,
Warning: Declaration of Gta\PayPalPreference\Model\Api\Nvp::_applyStreetAndRegionWorkarounds(Gta\PayPalPreference\Model\Api\DataObject $address) should be compatib le with Magento\Paypal\Model\Api\Nvp::_applyStreetAndRegionWorkarounds(Magento\Framework\DataObject $address) in /var/www/html/test/app/code/Gta/PayPalPreferenc e/Model/Api/Nvp.php on line 59
Note: website filter included.
How to solve this error?