bindings with email as foreign key was tricky...

@param array $customer
@return boolean
174573
public function getManufacturerRecord($customer)
    {
        $mm = TableRegistry::getTableLocator()->get('Manufacturers');
        $manufacturer = $mm->find('all', [
            'conditions' => [
                'AddressManufacturers.email' => $customer->email
            ],
            'contain' => [
                'AddressManufacturers'
            ]
        ])->first();
        return $manufacturer;
    }
582647
public function getCustomerByExternalUid($customerExternalUid)
    {
        $requestData = new Get\RequestData();
        $requestData->setCustomerExternalUid($customerExternalUid);

        $customers = $this->getCustomers($requestData)->getResponse()->getCustomers();

        return isset($customers[0]) ? $customers[0] : null;
    }
1126564
public function connect($customerUUID, array $subscriptions)
    {
        $arr = [];
        for($i=0; $i < count($subscriptions); $i++) {
            $arr[$i] = $subscriptions[$i];
            if($subscriptions[$i] instanceof Subscription) {
                $arr[$i] = $subscriptions[$i]->toArray();
            }
        }

        array_unshift($arr, $this->toArray());

        $this->getClient()
            ->send('/v1/customers/'.$customerUUID.'/connect_subscriptions', 'POST', [
                'subscriptions' => $arr,
            ]);
        return true;
    }
539915
protected function findByEmail(&$user)
    {
        // Try to find user by socialID
        if (dbQuery($this->dbTable)->cond($this->dbEmailField, $this->user->email)->first($user)) {
            return true;
        } else {
            return false;
        }
    }
152033
protected function isForeignKey($table, $field)
    {
        foreach ($this->foreignKeys['all'] as $entry) {
            if ($entry->COLUMN_NAME == $field && $entry->TABLE_NAME == $table) {
                return true;
            }
        }

        return false;
    }
820688
public function prune($customer = null)
    {
        if ($customer) {
            $this->addUsingAlias(CustomerPeer::ID, $customer->getId(), Criteria::NOT_EQUAL);
        }

        return $this;
    }
668007
private function createCustomerWithUserAccount(
        $email,
        $password,
        $enabled = true,
        $firstName = null,
        $lastName = null,
        $role = null
    ) {
        /** @var ShopUserInterface $user */
        $user = $this->userFactory->createNew();

        /** @var CustomerInterface $customer */
        $customer = $this->customerFactory->createNew();

        $customer->setFirstName($firstName);
        $customer->setLastName($lastName);
        $customer->setEmail($email);

        $user->setUsername($email);
        $user->setPlainPassword($password);
        $user->setEnabled($enabled);
        if (null !== $role) {
            $user->addRole($role);
        }

        $customer->setUser($user);

        $this->sharedStorage->set('customer', $customer);

        return $customer;
    }
17476
public function addCategory(\Magento\Framework\DataObject $customer)
    {
        $email = strtolower(trim($customer->getEmail()));
        if (!isset($this->_customerIds[$email])) {
            $this->_customerIds[$email] = [];
        }
        $this->_customerIds[$email][$customer->getWebsiteId()] = $customer->getId();

        return $this;
    }
1374774
public function notifyCreated(array $order)
    {
        $this->mail->set('order_created_admin', array($order));

        if (is_numeric($order['user_id']) && !empty($order['user_email'])) {
            return $this->mail->set('order_created_customer', array($order));
        }

        return false;
    }
92151
public function delete(string $customer)
    {
        $response = $this->httpDelete('/3/customers/'.$customer);

        if (!$this->hydrator) {
            return $response;
        }

        // Use any valid status code here
        if (204 !== $response->getStatusCode()) {
            $this->handleErrors($response);
        }

        return $this->hydrator->hydrate($response, ApiResponse::class);
    }
563435
public function updateFromEmbeddedApiResponse(array $data): CustomerInterface
    {
        // we cast to int because for some reason Dandomain can (sometimes) have customers where the id is not set
        // and instead of setting the id to 0, Dandomain sets it to ''
        $id = (int) $data['id'];

        $customer = $this->customerRepository->findOneByExternalId($id);
        if (!$customer) {
            $customer = new Customer();
            $customer->setExternalId($id);
        }

        $customer
            ->setAddress($data['address'])
            ->setAddress2($data['address2'])
            ->setAttention($data['attention'])
            ->setCity($data['city'])
            ->setCountry($data['country'])
            ->setCountryId($data['countryId'])
            ->setEan($data['ean'])
            ->setEmail($data['email'])
            ->setFax($data['fax'])
            ->setName($data['name'])
            ->setPhone($data['phone'])
            ->setState($data['state'])
            ->setZipCode($data['zipCode'])
        ;

        return $customer;
    }
1239789
public function createCustomer(Customer $customer)
    {
        $request = new Create\Request($customer);

        return $this->sendRequest($request, Create\ApiResponse::class);
    }
367109
public function setCustomerInfo(array $customerInfo)
    {
        $customerEmail = $this->sanitize($customerInfo, 'email');

        $customerPhone = $this->sanitizeNumber($customerInfo, 'phone');

        $this->custumer['customer'] = [
            'name'      => $this->sanitize($customerInfo, 'name'),
            'email'     => $customerEmail,
        ];

        $this->custumer['customer']['document'] = [
            'type'   => !empty($this->sanitizeNumber($customerInfo, 'customerCPF')) ? 'CPF' : 'CNPJ',
            'value'  => !empty($this->sanitizeNumber($customerInfo, 'customerCPF')) ? $this->sanitizeNumber($customerInfo, 'customerCPF') : $this->sanitizeNumber($customerInfo, 'customerCNPJ'),
        ];

        $this->custumer['customer']['phone'] = [
            'areaCode'  => substr($customerPhone, 0, 2),
            'number'    => substr($customerPhone, 2),
        ];

        $this->validateCustomerInfo($this->custumer['customer']);

        return $this;
    }
183427
public static function connectSubscriptions($customerUUID, array $data = [], ClientInterface $client = null)
    {
        (new static([], $client))
            ->getClient()
            ->setResourcekey(static::class)
            ->send('/v1/customers/'.$customerUUID.'/connect_subscriptions', 'POST', $data);
        return true;
    }
207642
protected function fetchRelation(array $relation)
    {
        /* a relation is of the form
         * [$type, $foreign_class, $foreign_column, $column]
         */
        list($type, $foreign_class, $foreign_column, $column) = $relation;

        switch ($type) {
        case 'has_one':
            return $this->fetchOneToOne($foreign_class, $foreign_column, $column);
        case 'belongs_to':
            return $this->fetchOneToOne($foreign_class, $foreign_column, $column);
        case 'has_many':
            return $this->fetchOneToMany($foreign_class, $foreign_column, $column);
        default:
        }
    }
1336791
public function get(string $customer)
    {
        $response = $this->httpGet('/3/customers/'.$customer);

        if (!$this->hydrator) {
            return $response;
        }

        // Use any valid status code here
        if (200 !== $response->getStatusCode()) {
            $this->handleErrors($response);
        }

        return $this->hydrator->hydrate($response, Model::class);
    }
883078
public function addCustomer(Customer $l)
    {
        if ($this->collCustomers === null) {
            $this->initCustomers();
            $this->collCustomersPartial = true;
        }

        if (!in_array($l, $this->collCustomers->getArrayCopy(), true)) { // only add it if the **same** object is not already associated
            $this->doAddCustomer($l);

            if ($this->customersScheduledForDeletion and $this->customersScheduledForDeletion->contains($l)) {
                $this->customersScheduledForDeletion->remove($this->customersScheduledForDeletion->search($l));
            }
        }

        return $this;
    }