![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/cartforge.co/vendor/magento/module-customer/Model/Address/Validator/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ declare(strict_types=1); namespace Magento\Customer\Model\Address\Validator; use Magento\Customer\Model\Address\AbstractAddress; use Magento\Customer\Model\Address\ValidatorInterface; use Magento\Customer\Model\AddressFactory; use Magento\Quote\Api\Data\AddressInterface as QuoteAddressInterface; /** * Validates that current Address is related to given Customer. */ class Customer implements ValidatorInterface { /** * @var AddressFactory */ private $addressFactory; /** * @param AddressFactory $addressFactory */ public function __construct(AddressFactory $addressFactory) { $this->addressFactory = $addressFactory; } /** * @inheritDoc */ public function validate(AbstractAddress $address): array { $errors = []; $addressId = $address instanceof QuoteAddressInterface ? $address->getCustomerAddressId() : $address->getId(); if ($addressId !== null) { $addressCustomerId = (int) $address->getCustomerId(); $originalAddressCustomerId = (int) $this->addressFactory->create() ->load($addressId) ->getCustomerId(); if ($originalAddressCustomerId !== 0 && $originalAddressCustomerId !== $addressCustomerId) { $errors[] = __( 'Provided customer ID "%customer_id" isn\'t related to current customer address.', ['customer_id' => $addressCustomerId] ); } } return $errors; } }