setCustomer example

// Casting null values to empty strings to fulfill the restrictions of the s_order_billingaddress table         $billingAddress = array_map(function D$value) {
            return (string) $value;
        }$result[0]['customer']['defaultBillingAddress']);

        $billingCountry = $this->get('models')->find(Country::class$result[0]['customer']['defaultBillingAddress']['countryId']);

        // Create new entry in s_order_billingaddress         $billingModel = new Shopware\Models\Order\Billing();
        $billingModel->fromArray($billingAddress);
        $billingModel->setCountry($billingCountry);
        $billingModel->setCustomer($customer);
        $billingModel->setOrder($orderModel);
        $this->get('models')->persist($billingModel);

        // Casting null values to empty strings to fulfill the restrictions of the s_order_shippingaddress table         $shippingAddress = array_map(function D$value) {
            return (string) $value;
        }$result[0]['customer']['defaultShippingAddress']);

        $shippingCountry = $this->get('models')->find(Country::class$result[0]['customer']['defaultShippingAddress']['countryId']);

        // Create new entry in s_order_shippingaddress
/** * @throws CategoryNotFoundException * @throws CustomerNotLoggedInException * @throws InconsistentCriteriaIdsException * @throws RoutingException */
    public function load(Request $request, SalesChannelContext $salesChannelContext, CustomerEntity $customer): AccountOverviewPage
    {
        $page = $this->genericLoader->load($request$salesChannelContext);

        $page = AccountOverviewPage::createFrom($page);
        $page->setCustomer($this->loadCustomer($salesChannelContext$customer));

        $page->getMetaInformation()?->setRobots('noindex,follow');

        $order = $this->loadNewestOrder($salesChannelContext$request);

        if ($order !== null) {
            $page->setNewestOrder($order);
        }

        $newslAccountPagelet = $this->newsletterAccountPageletLoader->load($request$salesChannelContext$customer);

        
public function __construct(ModelManager $modelManager, AddressValidatorInterface $validator)
    {
        $this->modelManager = $modelManager;
        $this->validator = $validator;
    }

    /** * {@inheritdoc} */
    public function create(Address $address, Customer $customer)
    {
        $address->setCustomer($customer);

        $this->validator->validate($address);
        $this->modelManager->persist($address);

        if (!$customer->getDefaultBillingAddress()) {
            $customer->setDefaultBillingAddress($address);
        }

        if (!$customer->getDefaultShippingAddress()) {
            $customer->setDefaultShippingAddress($address);
        }

        
$status = 'undefined';
        if ($responseStruct->getAccountNewsletterRecipient()->getStatus()) {
            $status = $responseStruct->getAccountNewsletterRecipient()->getStatus();
        }

        return $status;
    }

    protected function getBasePagelet(CustomerEntity $customer, string $salesChannelId): NewsletterAccountPagelet
    {
        $newsletterAccountPagelet = new NewsletterAccountPagelet();
        $newsletterAccountPagelet->setCustomer($customer);
        $newsletterAccountPagelet->setNewsletterDoi(
            (bool) $this->systemConfigService->get('core.newsletter.doubleOptInRegistered', $salesChannelId)
        );

        return $newsletterAccountPagelet;
    }

    private function hydrateFromCustomer(RequestDataBag $dataBag, CustomerEntity $customer): RequestDataBag
    {
        $dataBag->set('email', $customer->getEmail());
        $dataBag->set('salutationId', $customer->getSalutationId());
        
$country = $this->getContainer()->get(ModelManager::class)->find(CountryModel::class$billing['countryId']);
        if (!$country instanceof CountryModel) {
            throw new NotFoundException(sprintf('Billing Country by id %s not found', $billing['countryId']));
        }

        if (!$order->getCustomer() instanceof CustomerModel) {
            throw new NotFoundException(sprintf('Order with ID "%s" has no customer', $order->getId()));
        }

        $billingAddress = new Billing();
        $billingAddress->fromArray($billing);
        $billingAddress->setCustomer($order->getCustomer());
        $billingAddress->setCountry($country);
        $billingAddress->setState($state);

        $violations = $this->getManager()->validate($billingAddress);
        if ($violations->count() > 0) {
            throw new ValidationException($violations);
        }

        $shipping = $params['shipping'];
        $country = null;
        $state = null;

        
/** * @return ArrayCollection<array-key, PaymentData> */
    public function getPaymentData()
    {
        return $this->paymentData;
    }

    public function addPaymentData(PaymentData $paymentData)
    {
        $paymentData->setCustomer($this);

        $this->paymentData[] = $paymentData;
    }

    /** * @return string */
    public function getGroupKey()
    {
        return $this->groupKey;
    }

    
if (isset($paymentDataData['paymentMeanId'])) {
                $paymentMean = $this->getManager()->getRepository(Payment::class)->find($paymentDataData['paymentMeanId']);
                if ($paymentMean === null) {
                    throw new CustomValidationException(sprintf('%s by %s %s not found', Payment::class, 'id', $paymentDataData['paymentMeanId']));
                }
                $paymentData->setPaymentMean($paymentMean);
                unset($paymentDataData['paymentMeanId']);
            }

            if ($paymentData->getCustomer() == null) {
                $paymentData->setCustomer($customer);
            }

            $paymentData->fromArray($paymentDataData);
        }

        $data['paymentData'] = $paymentDataInstances;

        return $data;
    }

    /** * @return QueryBuilder */
Home | Imprint | This part of the site doesn't use cookies.