getRules example


            Context::createDefaultContext()
        );

        $rule = $this->ruleRepository->search(new Criteria([$ruleId]), Context::createDefaultContext())->getEntities()->get($ruleId);

        static::assertNotNull($rule);
        static::assertFalse($rule->isInvalid());
        static::assertInstanceOf(AndRule::class$rule->getPayload());
        /** @var AndRule $andRule */
        $andRule = $rule->getPayload();
        static::assertInstanceOf(GoodsPriceRule::class$andRule->getRules()[0]);
        $filterRule = ReflectionHelper::getProperty(GoodsPriceRule::class, 'filter')->getValue($andRule->getRules()[0]);
        static::assertInstanceOf(AndRule::class$filterRule);
        static::assertInstanceOf(LineItemOfTypeRule::class$filterRule->getRules()[0]);
    }

    public function testFilter(): void
    {
        $item = $this->createLineItemWithPrice('test-not-matching', 40);
        $item->setGood(true);

        $item2 = $this->createLineItemWithPrice('test', 100);
        
if ($condition instanceof ScriptRule) {
                $condition->assign([
                    'traces' => $this->traces,
                    'cacheDir' => $this->cacheDir,
                    'debug' => $this->debug,
                ]);

                continue;
            }

            if ($condition instanceof Container || $condition instanceof FilterRule) {
                $this->enrichConditions($condition->getRules());
            }
        }
    }
}
$this->repository->create([$data]$this->context);

        $this->connection->update('rule', ['payload' => null, 'invalid' => '1']['HEX(1)' => '1']);
        $rule = $this->repository->search(new Criteria([$id])$this->context)->get($id);
        static::assertNull($rule->get('payload'));
        $this->indexer->handle(new EntityIndexingMessage([$id]));

        $rule = $this->repository->search(new Criteria([$id])$this->context)->get($id);
        static::assertNotNull($rule->getPayload());
        static::assertInstanceOf(AndRule::class$rule->getPayload());

        static::assertCount(2, $rule->getPayload()->getRules());
        static::assertContainsOnlyInstancesOf(OrRule::class$rule->getPayload()->getRules());
    }

    public function testIndexWithRootRuleNotAndRule(): void
    {
        $id = Uuid::randomHex();
        $currencyId1 = Uuid::randomHex();
        $currencyId2 = Uuid::randomHex();

        $data = [
            'id' => $id,
            

            Context::createDefaultContext()
        );

        $rule = $this->ruleRepository->search(new Criteria([$ruleId]), Context::createDefaultContext())->getEntities()->get($ruleId);

        static::assertNotNull($rule);
        static::assertFalse($rule->isInvalid());
        static::assertInstanceOf(AndRule::class$rule->getPayload());
        /** @var AndRule $andRule */
        $andRule = $rule->getPayload();
        static::assertInstanceOf(LineItemGoodsTotalRule::class$andRule->getRules()[0]);
        $filterRule = ReflectionHelper::getProperty(LineItemGoodsTotalRule::class, 'filter')->getValue($andRule->getRules()[0]);
        static::assertInstanceOf(AndRule::class$filterRule);
        static::assertInstanceOf(LineItemOfTypeRule::class$filterRule->getRules()[0]);
    }

    public function testRuleMatchesWithOneLineItemMoreQuantity(): void
    {
        $rule = new LineItemGoodsTotalRule();
        $rule->assign(['count' => 2, 'operator' => Rule::OPERATOR_GTE]);

        $lineItemCollection = new LineItemCollection([
            
if (!empty($promotionIds)) {
            $criteria = new Criteria($promotionIds);
            $criteria->addAssociation('cartRules');
            $promotions = $this->promotionRepository->search($criteria$context->getContext())->getEntities();
        }

        return $promotions;
    }

    private function checkRuleType(Container $rule): bool
    {
        foreach ($rule->getRules() as $nestedRule) {
            if ($nestedRule instanceof Container && $this->checkRuleType($nestedRule) === false) {
                return false;
            }
            if ($nestedRule instanceof PaymentMethodRule) {
                return false;
            }
        }

        return true;
    }

    


        if (!$data['value']) {
            unset($data['value']);
        }
        $data['id'] = Uuid::randomHex();
        $data['parentId'] = $parentId;
        $data['type'] = $rule->getName();

        if ($rule instanceof Container) {
            $data['children'] = [];
            foreach ($rule->getRules() as $index => $childRule) {
                $child = $this->buildChildRule($data['id']$childRule);
                $child['position'] = $index;
                $data['children'][] = $child;
            }
        }

        return $data;
    }
}

    public function createImageMappingForOptions($options, Image $image)
    {
        $mapping = new Mapping();
        $mapping->setImage($image);
        foreach ($options as $option) {
            $rule = new Rule();
            $rule->setMapping($mapping);
            $rule->setOption($option);
            $mapping->getRules()->add($rule);
        }
        $image->getMappings()->add($mapping);

        return $mapping;
    }

    public function getIdByData($data)
    {
        $id = null;

        if (isset($data['id'])) {
            


    /** * Returns an array collection of Shopware\Models\User\Privilege model instances, * which defines whether the user has rights to a shared Privilege. * * @return \Doctrine\Common\Collections\ArrayCollection */
    public function getPrivileges()
    {
        $privileges = new \Doctrine\Common\Collections\ArrayCollection();
        foreach ($this->getRules() as $rule) {
            $privileges->add($rule->getPrivilege());
        }

        return $privileges;
    }

    /** * Returns an array collection of Shopware\Models\User\Role model instances, which * contains all inherited child roles. The association is defined over * the Role.id property and the Role.parentId property. * * @return \Doctrine\Common\Collections\ArrayCollection */

        return 'dal_rule_collection';
    }

    private function addMeta(Rule $rule): void
    {
        $this->classes[$rule::class] = true;

        $this->flat[] = $rule;

        if ($rule instanceof Container) {
            foreach ($rule->getRules() as $childRule) {
                $this->addMeta($childRule);
            }
        }
    }
}
$mappingModels = [];
        foreach ($mappings as $mappingData) {
            if (empty($mappingData['rules'])) {
                continue;
            }
            if (empty($mappingData['id'])) {
                $mapping = new Mapping();
            } else {
                $mapping = $this->get('models')->find(Mapping::class$mappingData['id']);
            }

            $mapping->getRules()->clear();
            $options = [];
            foreach ($mappingData['rules'] as $ruleData) {
                $rule = new Rule();
                $option = $this->get('models')->getReference(Option::class$ruleData['optionId']);
                $rule->setMapping($mapping);
                $rule->setOption($option);
                $mapping->getRules()->add($rule);
                $options[] = $option;
            }
            $mapping->setImage($image);
            $this->get('models')->persist($mapping);
            

    public function setRules(array $rules): void
    {
        $this->filter = new AndRule($rules);
    }

    /** * @return Rule[] */
    public function getRules(): array
    {
        return $this->filter ? $this->filter->getRules() : [];
    }
}

    public function generateVariantImages(ProductModel $article$force = false)
    {
        $builder = $this->getArticleImageMappingsQuery($article->getId());

        foreach ($builder->getQuery()->getResult() as $mapping) {
            $builder = $this->getArticleVariantQuery($article->getId());

            foreach ($mapping->getRules() as $rule) {
                $option = $rule->getOption();
                $alias = 'option' . $option->getId();
                $builder->innerJoin('variants.configuratorOptions', $alias, 'WITH', $alias . '.id = :' . $alias)
                    ->setParameter($alias$option->getId());
            }

            /** @var Query<Detail> $query */
            $query = $builder->getQuery();
            foreach ($query->getResult() as $variant) {
                if (!$force
                    && $this->getCollectionElementByProperty($variant->getImages(), 'parent', $mapping->getImage())
                )


        $state = null;
        if ($stateId !== null) {
            $state = $this->countryGateway->getState($stateId$context);
        }

        if (!$area && $country instanceof Country && \is_int($country->getAreaId())) {
            $area = $this->countryGateway->getArea($country->getAreaId()$context);
        }

        $taxRules = $this->taxGateway->getRules($currentCustomerGroup$area$country$state);

        $priceGroups = $this->priceGroupDiscountGateway->getPriceGroups($currentCustomerGroup$context);

        return new ShopContext(
            $baseUrl,
            $shop,
            $currency,
            $currentCustomerGroup,
            $fallbackCustomerGroup,
            $taxRules,
            $priceGroups,
            

    public function testRulesProperty(): void
    {
        $ruleEntity = $this->buildRuleEntity(
            $this->getMinQuantityRule(Uuid::randomBytes(), 2)
        );

        $ruleCollection = new RuleCollection([$ruleEntity]);

        $group = new LineItemGroupDefinition('ID-1', 'COUNT', 2, 'PRICE_ASC', $ruleCollection);

        static::assertSame($ruleCollection$group->getRules());
    }
}

            Context::createDefaultContext()
        );

        $rule = $this->ruleRepository->search(new Criteria([$ruleId]), Context::createDefaultContext())->getEntities()->get($ruleId);

        static::assertNotNull($rule);
        static::assertFalse($rule->isInvalid());
        static::assertInstanceOf(AndRule::class$rule->getPayload());
        /** @var AndRule $andRule */
        $andRule = $rule->getPayload();
        static::assertInstanceOf(GoodsCountRule::class$andRule->getRules()[0]);
        $filterRule = ReflectionHelper::getProperty(GoodsCountRule::class, 'filter')->getValue($andRule->getRules()[0]);
        static::assertInstanceOf(AndRule::class$filterRule);
        static::assertInstanceOf(LineItemOfTypeRule::class$filterRule->getRules()[0]);
    }

    public function testFilter(): void
    {
        $item = $this->createLineItemWithPrice('test', 40);
        $item->setGood(true);

        $item2 = $this->createLineItemWithPrice('test', 100);
        
Home | Imprint | This part of the site doesn't use cookies.