PHP Fatal error Magento 2.3.4
-
13-04-2021 - |
Question
I have issue after upgrade magento 2.2.9 to 2.3.4. Compile command php bin/magento setup:di:compile stops during the process and root file error_log can see
PHP Fatal error: Declaration of Rokanthemes\OpCheckout\Block\Checkout\AttributeMerger::getDefaultValue($attributeCode) must be compatible with Magento\Checkout\Block\Checkout\AttributeMerger::getDefaultValue
File: AttributeMerger.php
<?php
namespace Rokanthemes\OpCheckout\Block\Checkout;
use Magento\Directory\Helper\Data as DirectoryHelper;
use Magento\Customer\Model\Session;
use Magento\Customer\Api\CustomerRepositoryInterface as CustomerRepository;
use Magento\Customer\Helper\Address as AddressHelper;
use Rokanthemes\OpCheckout\Helper\Config as OneStepConfig;
use Magento\Directory\Model\ResourceModel\Region\Collection as RegionCollection;
class AttributeMerger extends \Magento\Checkout\Block\Checkout\AttributeMerger
{
protected $_oneStepConfig;
protected $_regionCollection;
protected $_directoryHelper;
public function __construct(
AddressHelper $addressHelper,
Session $customerSession,
CustomerRepository $customerRepository,
DirectoryHelper $directoryHelper,
OneStepConfig $oneStepConfig,
RegionCollection $regionCollection
)
{
$this->_oneStepConfig = $oneStepConfig;
$this->_regionCollection = $regionCollection;
$this->_directoryHelper = $directoryHelper;
parent::__construct($addressHelper, $customerSession, $customerRepository, $directoryHelper);
}
protected function getDefaultValue($attributeCode)
{
if ($this->_oneStepConfig->getFullRequest() == 'checkout_index_index') {
switch ($attributeCode) {
case 'firstname':
if ($this->getCustomer()) {
return $this->getCustomer()->getFirstname();
}
break;
case 'lastname':
if ($this->getCustomer()) {
return $this->getCustomer()->getLastname();
}
break;
}
return null;
} else {
return parent::getDefaultValue($attributeCode);
}
}
}
How fix this issue? Thanks
No correct solution
OTHER TIPS
Change function declaration to match the one in Magento\Checkout\Block\Checkout\AttributeMerger
protected function getDefaultValue($attributeCode): ?string
Your's missing return type declaration which appeared in 2.3.x
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange