Method called to associate a UserCustomerRelation object to this object
through the UserCustomerRelation foreign key attribute.

@param    UserCustomerRelation $l UserCustomerRelation
@return Customer The current object (for fluent API support)
542298
public function addUserCustomerRelation(UserCustomerRelation $l)
    {
        if ($this->collUserCustomerRelations === null) {
            $this->initUserCustomerRelations();
            $this->collUserCustomerRelationsPartial = true;
        }

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

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

        return $this;
    }
397433
public function setNewCustomer(Customers $customer)
    {
        $this->client->addQueryString('new_customer', true);

        $this->data->customer = $customer->jsonSerialize();

        return $this;
    }
416685
public function getProductListCollectionByIdCustomerId(
        CustomerTransfer $customerTransfer
    ): ProductListCollectionTransfer {
        $customerTransfer->requireIdCustomer();

        return $this->productListCustomerRepository
            ->getProductListCollectionByIdCustomer($customerTransfer->getIdCustomer());
    }
76987
public function addTeamI18n(ChildTeamI18n $l)
    {
        if ($l && $locale = $l->getLocale()) {
            $this->setLocale($locale);
            $this->currentTranslations[$locale] = $l;
        }
        if ($this->collTeamI18ns === null) {
            $this->initTeamI18ns();
            $this->collTeamI18nsPartial = true;
        }

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

        return $this;
    }
1241071
private function createCustomer(
        $email,
        $firstName = null,
        $lastName = null,
        \DateTimeInterface $createdAt = null,
        $phoneNumber = null
    ) {
        /** @var CustomerInterface $customer */
        $customer = $this->customerFactory->createNew();

        $customer->setFirstName($firstName);
        $customer->setLastName($lastName);
        $customer->setEmail($email);
        $customer->setPhoneNumber($phoneNumber);
        if (null !== $createdAt) {
            $customer->setCreatedAt($createdAt);
        }

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

        return $customer;
    }
841855
public function addObject(ChildObject $l)
    {
        if ($this->collObjects === null) {
            $this->initObjects();
            $this->collObjectsPartial = true;
        }

        if (!$this->collObjects->contains($l)) {
            $this->doAddObject($l);
        }

        return $this;
    }
1171785
public function get()
    {
        $customer = null;
        $user = null;

        if (true === $this->securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
            // user is authenticated
            $user = $this->securityContext->getToken()->getUser();

            if (!$user instanceof UserInterface) {
                throw new \RuntimeException('User must be an instance of Symfony\Component\Security\Core\User\UserInterface');
            }

            $customer = $this->customerManager->findOneBy([
                'user' => $user->getId(),
            ]);
        }

        if (!$customer) {
            $basket = $this->getBasket();

            if ($basket && $basket->getCustomer()) {
                $customer = $basket->getCustomer();
            }
        }

        if (!$customer) {
            $customer = $this->customerManager->create();
        }

        if (!$customer->getLocale()) {
            $customer->setLocale($this->locale);
        }

        if ($user && $customer) {
            $customer->setUser($user);
        }

        return $customer;
    }
325717
public function setCustomer(ChildCustomer $v = null)
    {
        if ($v === null) {
            $this->setCustomerId(NULL);
        } else {
            $this->setCustomerId($v->getId());
        }

        $this->aCustomer = $v;

        // Add binding for other direction of this n:n relationship.
        // If this object has already been added to the ChildCustomer object, it will not be re-added.
        if ($v !== null) {
            $v->addCustomerCustomerGroup($this);
        }


        return $this;
    }
1162115
private function addBillingJoinAttributesToCustomerCollection($customerCollection)
    {
        $customerCollection = $customerCollection->joinAttribute(
            'billing_street',
            'customer_address/street',
            'default_billing',
            null,
            'left'
        )
            ->joinAttribute(
                'billing_city',
                'customer_address/city',
                'default_billing',
                null,
                'left'
            )
            ->joinAttribute(
                'billing_country_code',
                'customer_address/country_id',
                'default_billing',
                null,
                'left'
            )
            ->joinAttribute(
                'billing_postcode',
                'customer_address/postcode',
                'default_billing',
                null,
                'left'
            )
            ->joinAttribute(
                'billing_telephone',
                'customer_address/telephone',
                'default_billing',
                null,
                'left'
            )
            ->joinAttribute(
                'billing_region',
                'customer_address/region',
                'default_billing',
                null,
                'left'
            )
            ->joinAttribute(
                'billing_company',
                'customer_address/company',
                'default_billing',
                null,
                'left'
            );

        return $customerCollection;
    }
747157
protected function getCustomer()
    {
        if (null === $this->customer) {
            $this->customer = $this->getSession() ? $this->getSession()->getCustomerUser() : null;
        }

        return $this->customer;
    }
908440
public function getCustomer(): Customer
    {
        $body = $this->getJson();

        $resource = HalDeserializer::deserializeResource(
            Customer::class,
            HalDeserializer::deserializeDocument($body)
        );

        return $resource->getEntity();
    }
393276
public function create()
    {
        /**
         * @var Customer $customer
         */
        $classNamespace = $this->getEntityNamespace();
        $customer = new $classNamespace();
        $customer
            ->setGender(ElcodiUserProperties::GENDER_UNKNOWN)
            ->setGuest(false)
            ->setNewsletter(false)
            ->setAddresses(new ArrayCollection())
            ->setCarts(new ArrayCollection())
            ->setOrders(new ArrayCollection())
            ->setToken($this->generator->generate(2))
            ->setEnabled(true)
            ->setCreatedAt($this->now());

        return $customer;
    }
772484
public function getCustomer(int $gatewayId, User $user): Customer
    {
        $result = $this->_createCustomerQuery()
            ->where(['userId' => $user->id, 'gatewayId' => $gatewayId])
            ->one();

        if ($result !== null) {
            return new Customer($result);
        }

        Stripe::setApiKey(Craft::parseEnv(Commerce::getInstance()->getGateways()->getGatewayById($gatewayId)->apiKey));
        Stripe::setAppInfo(StripePlugin::getInstance()->name, StripePlugin::getInstance()->version, StripePlugin::getInstance()->documentationUrl);
        Stripe::setApiVersion(Gateway::STRIPE_API_VERSION);

        /** @var StripeCustomer $stripeCustomer */
        $stripeCustomer = StripeCustomer::create([
            'description' => Craft::t('commerce-stripe', 'Customer for Craft user with ID {id}', ['id' => $user->id]),
            'email' => $user->email
        ]);

        $customer = new Customer([
            'userId' => $user->id,
            'gatewayId' => $gatewayId,
            'reference' => $stripeCustomer->id,
            'response' => $stripeCustomer->jsonSerialize()
        ]);

        if (!$this->saveCustomer($customer)) {
            throw new CustomerException('Could not save customer: ' . implode(', ', $customer->getErrorSummary(true)));
        }

        return $customer;
    }
456597
public function setUser($user)
    {

        // Clear cache
        $this->user = null;

        // Find element
        if (!$user = $this->findUserElement($user)) {
            // Clear property / cache
            $this->userId = $this->user = null;
        } else {
            // Set property
            $this->userId = $user->getId();

            // Set cache
            $this->user = $user;
        }

        return $this;
    }
1366895
public static function create($modelAlias = null, $criteria = null)
    {
        if ($criteria instanceof UserCustomerRelationQuery) {
            return $criteria;
        }
        $query = new UserCustomerRelationQuery(null, null, $modelAlias);

        if ($criteria instanceof Criteria) {
            $query->mergeWith($criteria);
        }

        return $query;
    }
794968
public function addUserRole(ChildUserRole $l)
    {
        if ($this->collUserRoles === null) {
            $this->initUserRoles();
            $this->collUserRolesPartial = true;
        }

        if (!$this->collUserRoles->contains($l)) {
            $this->doAddUserRole($l);
        }

        return $this;
    }
1278193
public function getProductListCustomerRelation(
        ProductListCustomerRelationTransfer $productListCustomerRelationTransfer
    ): ProductListCustomerRelationTransfer {
        $productListCustomerRelationTransfer->requireIdProductList();

        $customerIds = $this->productListCustomerRepository->getRelatedCustomerIdsByIdProductList(
            $productListCustomerRelationTransfer->getIdProductList()
        );

        $productListCustomerRelationTransfer->setCustomerIds($customerIds);

        return $productListCustomerRelationTransfer;
    }