getReviewCount example

protected int $count;

    public function match(RuleScope $scope): bool
    {
        if (!$scope instanceof CheckoutRuleScope) {
            return false;
        }
        if (!$customer = $scope->getSalesChannelContext()->getCustomer()) {
            return RuleComparison::isNegativeOperator($this->operator);
        }

        $numberOfReviews = $customer->getReviewCount();

        return RuleComparison::numeric($numberOfReviews$this->count, $this->operator);
    }

    public function getConstraints(): array
    {
        return [
            'count' => RuleConstraints::int(),
            'operator' => RuleConstraints::numericOperators(false),
        ];
    }

    
'title' => 'Title',
                    'content' => 'Content',
                ],
            ],
        ];

        $this->getContainer()->get('product.repository')
            ->create([$data], Context::createDefaultContext());

        $version = Uuid::randomHex();

        static::assertEquals(1, $this->getReviewCount($id, Defaults::LIVE_VERSION));

        $this->productRepository->createVersion($id, Context::createDefaultContext(), 'test', $version);

        static::assertEquals(1, $this->getReviewCount($id, Defaults::LIVE_VERSION));

        static::assertEquals(0, $this->getReviewCount($id$version));
    }

    public function testMergingIsLocked(): void
    {
        $id = Uuid::randomHex();
        


    public function testCreatingNewReview(): void
    {
        $this->createReviews();

        $customer = $this->customerRepository->search(
            new Criteria([$this->ids->get('customer')]),
            Context::createDefaultContext()
        )->first();
        static::assertInstanceOf(CustomerEntity::class$customer);
        static::assertSame(1, $customer->getReviewCount());
    }

    public function testDeletingNewReview(): void
    {
        $this->createReviews();

        $customer = $this->customerRepository->search(
            new Criteria([$this->ids->get('customer')]),
            Context::createDefaultContext()
        )->first();
        static::assertInstanceOf(CustomerEntity::class$customer);
        
$this->createCustomer('c2');
        $createdReviews[] = $this->createReview('c2', 'p2', true);

        $this->reviewCountService->updateReviewCount($createdReviews);

        $customerRepo = $this->getContainer()->get('customer.repository');
        /** @var CustomerCollection $customers */
        $customers = $customerRepo->search(new Criteria([$this->ids->get('c1')$this->ids->get('c2')]), Context::createDefaultContext());

        $firstCustomer = $customers->get($this->ids->get('c1'));
        static::assertInstanceOf(CustomerEntity::class$firstCustomer);
        static::assertEquals(1, $firstCustomer->getReviewCount());

        $secondCustomer = $customers->get($this->ids->get('c2'));
        static::assertInstanceOf(CustomerEntity::class$secondCustomer);
        static::assertEquals(1, $secondCustomer->getReviewCount());
    }

    private function createCustomer(string $customerNumber): void
    {
        $customer = (new CustomerBuilder(
            $this->ids,
            $customerNumber
        ))
Home | Imprint | This part of the site doesn't use cookies.