BillingCountryRule example

$countryId = $country?->getId() ?? '';

        // create rule for that country now, so it is set in the order         $ruleId = Uuid::randomHex();
        $this->getContainer()->get('rule.repository')->create([
            [
                'id' => $ruleId,
                'name' => 'test',
                'priority' => 1,
                'conditions' => [
                    [
                        'type' => (new BillingCountryRule())->getName(),
                        'value' => [
                            'operator' => '=',
                            'countryIds' => [$countryId],
                        ],
                    ],
                ],
            ],
        ], Context::createDefaultContext());

        $this->getContainer()->get('product.repository')->create([
            (new ProductBuilder($ids, '1000'))
                
private EntityRepository $conditionRepository;

    private Context $context;

    private BillingCountryRule $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 BillingCountryRule();
    }

    public function testValidationWithMissingCountryIds(): void
    {
        try {
            $this->conditionRepository->create([
                [
                    'type' => (new BillingCountryRule())->getName(),
                    'ruleId' => Uuid::randomHex(),
                ],
            ]$this->context);
            
/** * @covers \Shopware\Core\Checkout\Customer\Rule\BillingCountryRule * * @internal */
#[Package('business-ops')] class BillingCountryRuleTest extends TestCase
{
    public function testWithExactMatch(): void
    {
        $rule = (new BillingCountryRule())->assign(['countryIds' => ['SWAG-AREA-COUNTRY-ID-1']]);

        $cart = new Cart('test');

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

        $country = new CountryEntity();
        $country->setId('SWAG-AREA-COUNTRY-ID-1');

        $billing = new CustomerAddressEntity();
        $billing->setCountry($country);

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