public function setEntity(MageQuote $quote)
    {
        $id    = $this->sgBase->getExternalCustomerId();
        $email = $this->sgBase->getMail();

        try {
            $customer = $id ? $this->customerHelper->getById($id) : $this->customerHelper->getByEmail($email);
        } catch (NoSuchEntityException $e) {
            $customer = new DataObject();
            $this->log->debug('Could not load customer by id or mail.');
        }
        $quote->setCustomerEmail($email)
            ->setRemoteIp($this->sgBase->getCustomerIp());
        if ($this->sgBase->isGuest()) {
            $quote->setCustomerIsGuest(true);
        } elseif ($customer->getId()) {
            $this->session->setCustomerId($customer->getId())->setCustomerGroupId($customer->getGroupId());

            $quote->setCustomer($customer)
                ->setCustomerIsGuest(false);
        } else {
            throw new \ShopgateLibraryException(
                \ShopgateLibraryException::UNKNOWN_ERROR_CODE,
                __('Customer with external id "%1" or email "%2" does not exist', $id, $email)->render()
            );
        }
    }