public function exists($customerId, array $addressToCheck)
    {
        unset($addressToCheck['email']);
        if (empty($addressToCheck['company'])) {
            // company would be cast to an empty string, which does not match NULL in the database
            unset($addressToCheck['company']);
        }
        $addressCollection = $this->addressFactory->create()
                                                  ->getCollection()
                                                  ->addFieldToFilter('parent_id', $customerId);

        foreach ($addressToCheck as $addressField => $fieldValue) {
            $addressCollection->addFieldToFilter(
                $addressField,
                $fieldValue
            );
        }

        return $addressCollection->count() > 0;
    }
public function exists($customerId, array $addressToCheck)
    {
        unset($addressToCheck['email']);
        if (empty($addressToCheck['company'])) {
            // company would be cast to an empty string, which does not match NULL in the database
            unset($addressToCheck['company']);
        }
        $addressCollection = $this->addressFactory->create()
                                                  ->getCollection()
                                                  ->addFieldToFilter('parent_id', $customerId);

        foreach ($addressToCheck as $addressField => $fieldValue) {
            $addressCollection->addFieldToFilter(
                $addressField,
                $fieldValue
            );
        }

        return $addressCollection->count() > 0;
    }
public function exists ( $ customerId , array $ addressToCheck ) { unset ( $ addressToCheck [ 'email' ] ) ; if ( empty ( $ addressToCheck [ 'company' ] ) ) { // company would be cast to an empty string, which does not match NULL in the database unset ( $ addressToCheck [ 'company' ] ) ; } $ addressCollection = $ this -> addressFactory -> create ( ) -> getCollection ( ) -> addFieldToFilter ( 'parent_id' , $ customerId ) ; foreach ( $ addressToCheck as $ addressField => $ fieldValue ) { $ addressCollection -> addFieldToFilter ( $ addressField , $ fieldValue ) ; } return $ addressCollection -> count ( ) > 0 ; }
Checks if provided address is also saved as an address for the given customer
by filtering its customer address

@param int   $customerId
@param array $addressToCheck

@return bool

@throws \Magento\Framework\Exception\LocalizedException
Checks if provided address is also saved as an address for the given customer by filtering its customer address