As described here, you can override single classes by (ab)using composer autoload definitions like this:
"files": ["app/code/Magento/CatalogImportExport/Model/Import/Product/Validator/Media.php"]
But just because you can, does not mean you should. Always prefer plugins if possible, and fall back to DI preferences if not. There are very rare cases where a hack like this is really necessary.
Regarding your concrete issue: while you cannot override a constant using preferences, you can override its usages. In Magento 2.1 this constant is only used once, in Magento\CatalogImportExport\Model\Import\Product\Validator\Media::checkValidUrl()
. Since it is a protected method, you cannot write a plugin for it, but you can replace the class using preferences with:
class MediaValidator extends Magento\CatalogImportExport\Model\Import\Product\Validator\Media
{
const URL_REGEXP = '|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i'; // <-- change this line
protected function checkValidUrl($string)
{
return preg_match(self::URL_REGEXP, $string);
}
}
Here, self
refers to the new class instead of the parent class.
And just for your info, in Magento 2.2 this method is not used anymore and marked as deprecated:
* @deprecated As this method doesn't give a guarantee of correct URL validation.
* @see \Magento\Framework\Url\Validator::isValid() It provides better URL validation.
To add SKU create a layout file sales_order_view.xml
under Vendor/Module/view/adminhtml/layout
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<body>
<referenceBlock name="column_name">
<action method="setTemplate">
<argument name="template" xsi:type="string">Vendor_Module::items/column/name.phtml</argument>
</action>
</referenceBlock>
</body>
</page>
Best Answer
You can override model function using before, after & around method. In below example, We can override export function behavior using before and after method