0

app/code/Magento/Quote/Model/QuoteValidator.php

What to make of this code

 foreach ($this->quoteValidationRule->validate($quote) as $validationResult) {
            if ($validationResult->isValid()) {
                continue;
            }

            $messages = $validationResult->getErrors();
            $defaultMessage = array_shift($messages);
            if ($defaultMessage && !empty($messages)) {
                $defaultMessage .= ' %1';
            }
            $logger->info('v1',$messages);
            if ($defaultMessage) {
                throw new LocalizedException(__($defaultMessage, implode(' ', $messages)));
            }
           
        }

        return $this;
4
  • Can you please add a description? what exactly do you want? May 26 at 6:01
  • I don't know how this code always executes, but this code gives me the following message,["\"firstname\" is required. Enter and try again.","\"lastname\" is required. Enter and try again.","\"telephone\" is required. Enter and try again.","\"countryId\" is required. Enter and try again."]
    – sq y
    May 26 at 6:30
  • I am a guest order and I want to remove validation from the firstname lastname field
    – sq y
    May 26 at 6:32
  • When the code flow comes here, I don't know how to modify it
    – sq y
    May 26 at 6:32

1 Answer 1

0

Here is a high-level stack trace of how the $this->quoteValidationRule->validate($quote) code validates first and last name for the shipping address:

  1. \Magento\Quote\Model\ValidationRules\QuoteValidationComposite::validate()
  2. \Magento\Quote\Model\ValidationRules\ShippingAddressValidationRule::validate()
  3. \Magento\Customer\Model\Address\AbstractAddress::validate()
  4. \Magento\Customer\Model\Address\CompositeValidator::validate()
  5. \Magento\Customer\Model\Address\Validator\General::validate()

Inside of \Magento\Customer\Model\Address\Validator\General::validate() you will find the following code:

if (!\Zend_Validate::is($address->getFirstname(), 'NotEmpty')) {
    $errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'firstname']);
}

if (!\Zend_Validate::is($address->getLastname(), 'NotEmpty')) {
    $errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'lastname']);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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