setGroup example

private readonly AccountLoginPageLoader $accountLoginPageLoader,
        private readonly AbstractCustomerGroupRegistrationSettingsRoute $customerGroupRegistrationRoute,
        private readonly EventDispatcherInterface $eventDispatcher
    ) {
    }

    public function load(Request $request, SalesChannelContext $salesChannelContext): CustomerGroupRegistrationPage
    {
        $page = CustomerGroupRegistrationPage::createFrom($this->accountLoginPageLoader->load($request$salesChannelContext));
        $customerGroupId = $request->attributes->get('customerGroupId');

        $page->setGroup(
            $this->customerGroupRegistrationRoute->load($customerGroupId$salesChannelContext)->getRegistration()
        );

        if ($page->getMetaInformation()) {
            $metaDescription = $page->getGroup()->getTranslation('registrationSeoMetaDescription');
            if ($metaDescription) {
                $page->getMetaInformation()->setMetaDescription($metaDescription);
            }

            $title = $page->getGroup()->getTranslation('registrationTitle');
            if ($title) {
                
protected function createContext()
    {
        $translator = $this->createMock(TranslatorInterface::class);
        $translator->expects($this->any())->method('trans')->willReturnArgument(0);
        $validator = $this->createMock(ValidatorInterface::class);
        $validator->expects($this->any())
            ->method('validate')
            ->willReturnCallback(fn () => $this->expectedViolations[$this->call++] ?? new ConstraintViolationList());

        $context = new ExecutionContext($validator$this->root, $translator);
        $context->setGroup($this->group);
        $context->setNode($this->value, $this->object, $this->metadata, $this->propertyPath);
        $context->setConstraint($this->constraint);

        $contextualValidatorMockBuilder = $this->getMockBuilder(AssertingContextualValidator::class)
            ->setConstructorArgs([$context]);
        $contextualValidatorMethods = [
            'atPath',
            'validate',
            'validateProperty',
            'validatePropertyValue',
            'getViolations',
        ];

    public function latest(?string $group = null)
    {
        if ($this->enabled) {
            throw ConfigException::forDisabledMigrations();
        }

        $this->ensureTable();

        if ($group !== null) {
            $this->groupFilter = $group;
            $this->setGroup($group);
        }

        $migrations = $this->findMigrations();

        if (empty($migrations)) {
            return true;
        }

        foreach ($this->getHistory((string) $group) as $history) {
            unset($migrations[$this->getObjectUid($history)]);
        }

        
$previousObject,
                \is_object($value) ? $this->generateCacheKey($value) : null,
                $metadata,
                $this->defaultPropertyPath,
                $groups,
                null,
                TraversalStrategy::IMPLICIT,
                $this->context
            );

            $this->context->setNode($previousValue$previousObject$previousMetadata$previousPath);
            $this->context->setGroup($previousGroup);

            if (null !== $previousConstraint) {
                $this->context->setConstraint($previousConstraint);
            }

            return $this;
        }

        // If an object is passed without explicit constraints, validate that         // object against the constraints defined for the object's class         if (\is_object($value)) {
            

    public function setFeature($feature$value = false, $group = '')
    {
        $this->_aFeatures[$feature] = $value;
        if (!empty($group)) {
            $this->setGroup($group$feature);
        }
        return $this;
    }

    /** * Affects a feature to a group * * @param string $group Group name * @param string $feature Feature name * @return Zend_Http_UserAgent_AbstractDevice */
    
'name' => $optionData['name'],
                            'groupId' => $group->getId(),
                        ]);
                    }
                }

                if (!$option) {
                    $option = new ConfiguratorOption();
                }

                $option->fromArray($optionData);
                $option->setGroup($group);

                // Only set new position if option doesn't exist yet                 // Otherwise the position might have been set manually already, and we do not want to change that                 if (!isset($optionData['position']) && !$option->getId()) {
                    $option->setPosition($optionPosition++);
                }
                $allOptions[] = $option;
                $groupOptions[] = $option;
            }

            $groupData['options'] = $groupOptions;

            
static::assertInstanceOf(CheckoutRegisterPageLoadedHook::class$this->controller->calledHook);
    }

    public function testCustomerGroupRegistration(): void
    {
        $context = Generator::createSalesChannelContext();
        $context->assign(['customer' => null]);
        $request = new Request();
        $request->attributes->set('_route', 'frontend.account.customer-group-registration.page');
        $dataBag = new RequestDataBag();
        $page = new CustomerGroupRegistrationPage();
        $page->setGroup(new CustomerGroupEntity());
        $customerGroupId = Uuid::randomHex();

        $this->customerGroupRegistrationPageLoader->expects(static::once())
            ->method('load')
            ->with($request$context)
            ->willReturn($page);

        $this->controller->customerGroupRegistration($customerGroupId$request$dataBag$context);

        static::assertSame($page$this->controller->renderStorefrontParameters['page']);
        static::assertSame($dataBag$this->controller->renderStorefrontParameters['data']);
        
$deliveryTime->setMax(2);
            $deliveryTime->setUnit(DeliveryTimeEntity::DELIVERY_TIME_DAY);

            $shippingMethod = new ShippingMethodEntity();
            $shippingMethod->setDeliveryTime($deliveryTime);
            $shippingMethod->setId('8beeb66e9dda46b18891a059257a590e');
        }

        if (!$customer) {
            $customer = (new CustomerEntity())->assign(['id' => Uuid::randomHex()]);
            $customer->setId(Uuid::randomHex());
            $customer->setGroup($currentCustomerGroup);
        }

        return new SalesChannelContext(
            $baseContext,
            $token ?? Uuid::randomHex(),
            $domainId ?? Uuid::randomHex(),
            $salesChannel,
            $currency,
            $currentCustomerGroup,
            $taxes,
            $paymentMethod,
            
$previousObject,
                \is_object($value) ? $this->generateCacheKey($value) : null,
                $metadata,
                $this->defaultPropertyPath,
                $groups,
                null,
                TraversalStrategy::IMPLICIT,
                $this->context
            );

            $this->context->setNode($previousValue$previousObject$previousMetadata$previousPath);
            $this->context->setGroup($previousGroup);

            if (null !== $previousConstraint) {
                $this->context->setConstraint($previousConstraint);
            }

            return $this;
        }

        // If an object is passed without explicit constraints, validate that         // object against the constraints defined for the object's class         if (\is_object($value)) {
            
if (isset($data['discounts'])) {
                    if (!$model instanceof CustomerGroup) {
                        throw new RuntimeException(sprintf('Model object is not an instance of expected class "%s"', CustomerGroup::class));
                    }
                    $model->getDiscounts()->clear();
                    $manager->flush();
                    $discounts = [];
                    foreach ($data['discounts'] as $discountData) {
                        $discount = new Discount();
                        $discount->setDiscount($discountData['discount']);
                        $discount->setValue($discountData['value']);
                        $discount->setGroup($model);
                        $discounts[] = $discount;
                    }

                    $data['discounts'] = $discounts;
                }
                if (empty($data['mode'])) {
                    $data['discount'] = 0;
                }
                break;

            case 'shop':
                
if ($force && CLI::prompt(lang('Migrations.rollBackConfirm')['y', 'n']) === 'n') {
                return;
            }
            // @codeCoverageIgnoreEnd         }

        $runner = Services::migrations();
        $group  = $params['g'] ?? CLI::getOption('g');

        if (is_string($group)) {
            $runner->setGroup($group);
        }

        try {
            $batch = $params['b'] ?? CLI::getOption('b') ?? $runner->getLastBatch() - 1;
            CLI::write(lang('Migrations.rollingBack') . ' ' . $batch, 'yellow');

            if ($runner->regress($batch)) {
                CLI::error(lang('Migrations.generalFault'), 'light_gray', 'red'); // @codeCoverageIgnore             }

            $messages = $runner->getCliMessages();

            
if (!$option) {
                if (!$optionData['option']) {
                    throw new CustomValidationException('A new configurator option requires a name');
                }

                $option = new Option();
                $option->setPosition(0);
                if (\array_key_exists('position', $optionData)) {
                    $option->setPosition((int) $optionData['position']);
                }
                $option->setName($optionData['option']);
                $option->setGroup($availableGroup);
                $this->getManager()->persist($option);
            }
            $options->add($option);
        }

        $data['configuratorOptions'] = $options;

        $variant->setConfiguratorOptions($options);

        return $data;
    }

    
$subShop = $this->modelManager->find(ShopModel::class$shop->getId());
        if (!$subShop instanceof ShopModel) {
            throw new ModelNotFoundException(ShopModel::class$shop->getId());
        }
        $customer->setLanguageSubShop($subShop);

        if ($customer->getGroup() === null) {
            $customerGroup = $this->modelManager->find(Group::class$subShop->getCustomerGroup()->getId());
            if (!$customerGroup instanceof Group) {
                throw new ModelNotFoundException(Group::class$subShop->getCustomerGroup()->getId());
            }
            $customer->setGroup($customerGroup);
        }

        if ($customer->getAffiliate()) {
            $customer->setAffiliate((int) $this->getPartnerId($customer));
        } else {
            $customer->setAffiliate(0);
        }

        if (!$customer->getNumber() && $this->config->get('shopwareManagedCustomerNumbers')) {
            $customer->setNumber((string) $this->numberIncrementer->increment('user'));
        }

        
protected function createContext()
    {
        $translator = $this->createMock(TranslatorInterface::class);
        $translator->expects($this->any())->method('trans')->willReturnArgument(0);
        $validator = $this->createMock(ValidatorInterface::class);
        $validator->expects($this->any())
            ->method('validate')
            ->willReturnCallback(fn () => $this->expectedViolations[$this->call++] ?? new ConstraintViolationList());

        $context = new ExecutionContext($validator$this->root, $translator);
        $context->setGroup($this->group);
        $context->setNode($this->value, $this->object, $this->metadata, $this->propertyPath);
        $context->setConstraint($this->constraint);

        $contextualValidatorMockBuilder = $this->getMockBuilder(AssertingContextualValidator::class)
            ->setConstructorArgs([$context]);
        $contextualValidatorMethods = [
            'atPath',
            'validate',
            'validateProperty',
            'validatePropertyValue',
            'getViolations',
        ];
if ($options === null) {
                continue;
            }

            foreach ($options as $option) {
                $combinable = $this->isCombinable($option$current$combinations);
                if ($combinable === null) {
                    $options->remove($option->getId());

                    continue;
                }
                $option->setGroup(null);

                $option->setCombinable($combinable);
            }
        }

        return $groups;
    }

    /** * @throws InconsistentCriteriaIdsException * * @return array<string, PropertyGroupEntity>|null */
Home | Imprint | This part of the site doesn't use cookies.