CustomerNumberRule example

private EntityRepository $conditionRepository;

    private Context $context;

    private CustomerNumberRule $rule;

    protected function setUp(): void
    {
        $this->ruleRepository = $this->getContainer()->get('rule.repository');
        $this->conditionRepository = $this->getContainer()->get('rule_condition.repository');
        $this->context = Context::createDefaultContext();
        $this->rule = new CustomerNumberRule();
    }

    public function testValidateWithMissingNumbers(): void
    {
        try {
            $this->conditionRepository->create([
                [
                    'type' => (new CustomerNumberRule())->getName(),
                    'ruleId' => Uuid::randomHex(),
                ],
            ]$this->context);
            
$customer1->setCustomerNumber('C1');

        $customer2 = new CustomerEntity();
        $customer2->setId('C2');
        $customer2->setCustomerNumber('C2');

        $promotion = new PromotionEntity();
        $promotion->setCustomerRestriction(true);

        $promotion->setPersonaCustomers(new CustomerCollection([$customer1$customer2]));

        $custRule1 = new CustomerNumberRule();
        $custRule1->assign(['numbers' => ['C1'], 'operator' => Rule::OPERATOR_EQ]);

        $custRule2 = new CustomerNumberRule();
        $custRule2->assign(['numbers' => ['C2'], 'operator' => Rule::OPERATOR_EQ]);

        $expected = new AndRule(
            [
                // this is the customer rules OR condition                 new OrRule(
                    [
                        $custRule1,
                        
        if ($this->isCustomerRestriction()) {
            // we use assigned customers             // check if we have customers.             // if so, create customer rules for it and add that also as             // a separate OR condition to our main persona rule             if ($this->getPersonaCustomers() !== null) {
                $personaCustomerOR = new OrRule();

                foreach ($this->getPersonaCustomers()->getElements() as $customer) {
                    // build our new rule for this                     // customer and his/her customer number                     $custRule = new CustomerNumberRule();
                    $custRule->assign(['numbers' => [$customer->getCustomerNumber()], 'operator' => CustomerNumberRule::OPERATOR_EQ]);

                    $personaCustomerOR->addRule($custRule);
                }

                // add the rule to our main rule                 $requirements->addRule($personaCustomerOR);
            }
        } else {
            // we use persona rules.             // check if we have persona rules and add them
/** * @covers \Shopware\Core\Checkout\Customer\Rule\CustomerNumberRule * * @internal */
#[Package('business-ops')] class CustomerNumberRuleTest extends TestCase
{
    public function testExactMatch(): void
    {
        $rule = (new CustomerNumberRule())->assign(['numbers' => ['NO. 1']]);

        $cart = new Cart('test');

        $customer = new CustomerEntity();
        $customer->setCustomerNumber('NO. 1');

        $context = $this->createMock(SalesChannelContext::class);

        $context
            ->method('getCustomer')
            ->willReturn($customer);

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