setupContext example

return ['data' => $customers, 'total' => $totalResult];
    }

    /** * @param array<string, mixed> $params * * @return CustomerModel */
    public function create(array $params)
    {
        $this->checkPrivilege('create');
        $this->setupContext($params['shopId'] ?? null);

        // Create models         $customer = new CustomerModel();
        $customer->setAttribute(new CustomerAttribute());

        // Normalize call between create and update to allow same parameters         if (isset($params['defaultBillingAddress'])) {
            $params['billing'] = $params['defaultBillingAddress'];
            unset($params['defaultBillingAddress']);
        }

        

        $this->checkPrivilege('create');

        $customerId = !empty($params['customer']) ? (int) $params['customer'] : 0;
        unset($params['customer']);

        $customer = $this->getContainer()->get(ModelManager::class)->find(CustomerModel::class$customerId);
        if (!$customer) {
            throw new NotFoundException(sprintf('Customer by id %s not found', $customerId));
        }

        $this->setupContext($customer->getShop()->getId());

        if (!$params['country']) {
            throw new CustomValidationException('A country is required.');
        }

        $params = $this->prepareAddressData($params);

        $address = new AddressModel();
        $address->fromArray($params);

        $this->addressService->create($address$customer);

        
Home | Imprint | This part of the site doesn't use cookies.