I have coded a custom shipping module for Magento 2.4.6 according to Adobe’s documentation here: https://developer.adobe.com/commerce/php/tutorials/frontend/custom-checkout/add-shipping-carrier/
I am receiving the following error upon running a static content deployment:
Fatal error: Type of MyModulesCustomShipping1ModelCarrierCustomshipping::$_isFixed must not be defined (as in class MagentoShippingModelCarrierAbstractCarrier) in /var/www/html/app/code/MyModules/CustomShipping1/Model/Carrier/Customshipping.php on line 18
My code for the Customshipping.php is below:
declare(strict_types=1);
namespace MyModulesCustomShipping1ModelCarrier;
use MagentoFrameworkAppConfigScopeConfigInterface;
use MagentoQuoteModelQuoteAddressRateRequest;
use MagentoQuoteModelQuoteAddressRateResultMethod;
use MagentoQuoteModelQuoteAddressRateResultMethodFactory;
use MagentoQuoteModelQuoteAddressRateResultErrorFactory;
use MagentoShippingModelCarrierAbstractCarrier;
use MagentoShippingModelCarrierCarrierInterface;
use MagentoShippingModelRateResult;
use MagentoShippingModelRateResultFactory;
use PsrLogLoggerInterface;
class Customshipping extends AbstractCarrier implements CarrierInterface
{
protected $_code = 'customshipping';
protected bool $_isFixed = true;
private ResultFactory $rateResultFactory;
private MethodFactory $rateMethodFactory;
public function __construct(
ScopeConfigInterface $scopeConfig,
ErrorFactory $rateErrorFactory,
LoggerInterface $logger,
ResultFactory $rateResultFactory,
MethodFactory $rateMethodFactory,
array $data = []
) {
parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data);
$this->rateResultFactory = $rateResultFactory;
$this->rateMethodFactory = $rateMethodFactory;
}
/**
* Custom Shipping Rates Collector
*
* @param RateRequest $request
* @return MagentoShippingModelRateResult|bool
*/
public function collectRates(RateRequest $request)
{
if (!$this->getConfigFlag('active')) {
return false;
}
/** @var Method $method */
$method = $this->rateMethodFactory->create();
$method->setCarrier($this->_code);
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod($this->_code);
$method->setMethodTitle($this->getConfigData('name'));
$shippingCost = (float) $this->getConfigData('shipping_cost');
$method->setPrice($shippingCost);
$method->setCost($shippingCost);
/** @var Result $result */
$result = $this->rateResultFactory->create();
$result->append($method);
return $result;
}
public function getAllowedMethods(): array
{
return [$this->_code => $this->getConfigData('name')];
}
}
I had changed protected string $_code = ‘customshipping’; to the current iteration shown above to try and solve the issue but that did not work. Any help would be greatly appreciated.