2

How to override the model:

vendor/magento/module-Customer/Model/Address/AbstractAddress.php

For removing the validation of the last name. What can I do?

I have already overriden this file using the around plugin method, but it is still throwing an error.

| improve this question | | | | |
2

Create di.xml File

Path : app/code/{vendorName}/{ModuleName}/etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Customer\Model\Address\AbstractAddres" type="{vendorName}\{ModuleName}\Model\Address\AbstractAddres" />
</config> 

Create Model file

Path : app/code/{vendorName}/{ModuleName}/Model/Address/AbstractAddres.php

namespace {vendorName}\{ModuleName}\Model\Address;

    class AbstractAddres extends \Magento\Customer\Model\Address\AbstractAddres
    {
        public function __construct()
        {
            echo "Model Rewrite Working"; die();

        }

    }
| improve this answer | | | | |
0

remove below code for last name validation.

if (!\Zend_Validate::is($this->getLastname(), 'NotEmpty')) {
    $errors[] = __('Please enter the last name.');
}
| improve this answer | | | | |
  • yes.Removed it.But it throws error like......@Please check shipping information@ – Maha Nov 23 '17 at 16:47
  • that is something different error. Not related with Last Name – Abhishek Panchal Nov 23 '17 at 16:48
  • how to overcome this........... – Maha Nov 23 '17 at 16:49
  • check your recent modification related with shipping – Abhishek Panchal Nov 23 '17 at 16:52
  • or some time the page was loading................. – Maha Nov 23 '17 at 16:52
0

Hello you need to o override that model using plugin.

One more thing you need to change into database

Find last name attribute into eav_attibute and find column is_require.

Change value 1 to 0 for that attribute.

Flush the catch and try it....

Thanks

| improve this answer | | | | |
  • already changed it.but it shows error – Maha Nov 23 '17 at 17:11
  • If you do change into core file then it's work? – Sunil Patel Nov 23 '17 at 17:12
  • yes.it's work in core – Maha Nov 23 '17 at 17:13
  • Can you please put your code into issue of around plugin.make sure it is non protected method. – Sunil Patel Nov 23 '17 at 17:15
  • i'm sure. no non-public method – Maha Nov 23 '17 at 17:17
0

Stackoverflow\Customer\Plugin\Model\Address\AbstractAddress

/**
 * Validate address attribute values
 *
 * @return bool|array
 * @SuppressWarnings(PHPMD.CyclomaticComplexity)
 * @SuppressWarnings(PHPMD.NPathComplexity)
 */
public function aroundValidate(\Magento\Customer\Model\Address\AbstractAddress $subject, \Closure $proceed)
{
    $result = $proceed();

    if (!\Zend_Validate::is($this->getLastname(), 'NotEmpty')) {
        return true;
    }
    return $result;
}
| improve this answer | | | | |
0

Companyname/Modulename/Model/Address/AbstractAddress.php copy core class into above location and make entry in di.xml

| improve this answer | | | | |
-1

You create your CUSTOM\Customer\Model\Address\AbstractAddress.php class extending Magento\Customer\Model\Address\AbstractAddress

And In your di.xml

<preference for="Magento\Customer\Model\Address\AbstractAddress" type="CUSTOM\Customer\Model\Address\AbstractAddress"/>

Or You can create plugin with a function aroundValidate() in class CUSTOM\Customer\Plugin\AbstractAddressPlugin.php

And in yout di.xml

<type name="Magento\Customer\Model\Address\AbstractAddress">
    <plugin name="cutom_customer_address_plugin"
            type="CUSTOM\Customer\Plugin\AbstractAddressPlugin" />
</type>
| improve this answer | | | | |
  • Hi, it didn't work i tried both ways didn't work – jibin george Jul 11 '19 at 11:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.