Short answer: what you're trying to do is not possible. Your extending of and preference for the abstract class are valid, however these will never be used.
Inheritance of classes is native PHP functionality and will not be resolved by the object manager. Therefore, you can only use DI preferences for actual classes, not for abstract parent classes.
That being said, the method you are trying to alter is a public method, so you could use a Plugin.
You will have to register this plugin for each class which extends AbstractCarrierOnline. In this example I will show how to do this for the built-in DHL and UPS carriers (which both extend AbstractCarrierOnline).
In your di.xml
add the following:
<type name="Magento\Dhl\Model\Carrier">
<plugin name="custom_shippingmaxweight_dhlplugin" type="Custom\ShippingMaxWeight\Plugin\Shipping\OnlineCarrierPlugin" />
</type>
<type name="Magento\Ups\Model\Carrier">
<plugin name="custom_shippingmaxweight_upsplugin" type="Custom\ShippingMaxWeight\Plugin\Shipping\OnlineCarrierPlugin" />
</type>
Create the plugin class: Custom/ShippingMaxWeight/Plugin/Shipping/OnlineCarrierPlugin.php
namespace Custom\ShippingMaxWight\Plugin\Shipping;
// use ...;
class OnlineCarrierPlugin {
public function aroundProcessAdditionalValidation (\Magento\Shipping\Model\Carrier\AbstractCarrierOnline $carrier, callable $proceed, \Magento\Framework\DataObject $request) {
// do stuff
// $result = ...?
// $result can be an instance of \Magento\Quote\Model\Quote\Address\RateResult\Error, a boolean false, or the $carrier object.
return $result;
}
}
Please review http://devdocs.magento.com/guides/v2.1/extension-dev-guide/plugins.html#around-methods for more information about the arguments used in an 'around' plugin.
You don't have to call the $proceed method. You could also c/p and alter the code from the abstract class. The choice is yours.
If you have any more questions about this, feel free to ask.
try this, just add 'validation' => ['required-entry' => true] like below in LayoutProcessor plugin
'config' => [
'customScope' => 'shippingAddress',
'template' => 'ui/form/field',
'elementTmpl' => 'ui/form/element/input',
'options' => [],
'id' => 'custom_field'
],
'dataScope' => 'customfield',
'label' => 'custom field # :',
'provider' => 'checkoutProvider',
'validation' => ['required-entry' => true],
'visible' => true,
'sortOrder' => 250,
'id' => 'custom_field'
Best Answer
The above error is triggered when the specified shipping method is not available or is invalid.
As we can see at vendor/magento/module-checkout/Model/ShippingInformationManagement.php:209 if
getShippingRateByCode
returns false, it throws this exception.Inside this method we can see that it's not very complex to understand...
I can think of 3 possible reasons for that:
I hope any of these suggestions help.