Good luck!You can change the app/code/StackExchange/PayPalPreference/Model/Api/Nvp.php like this and use storeManager to fetch website id to decide whether to run the code or not for particular websites:
<?php
declare(strict_types=1);
namespace StackExchange\PayPalPreference\Model\Api;
use Magento\Store\Model\StoreManagerInterface;
class Nvp extends \Magento\Paypal\Model\Api\Nvp
{
/**
* @var StoreManagerInterface
*/
private StoreManagerInterface $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() == 2) {
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']));
}
}
}
}