getVisibilities example

/** @var EntityRepository<ProductCollection> $productRepository */
        $productRepository = $this->getContainer()->get('product.repository');
        $criteria = new Criteria([$productAId]);
        $criteria->addAssociation('visibilities');

        /** @var ProductEntity $productA */
        $productA = $productRepository->search($criteria, Context::createDefaultContext())->first();

        static::assertInstanceOf(ProductEntity::class$productA);

        static::assertInstanceOf(ProductVisibilityCollection::class$productA->getVisibilities());
        static::assertCount(1, $productA->getVisibilities());
        static::assertNotNull($productA->getVisibilities()->filterBySalesChannelId($salesChannelAId)->first());

        $criteria = new Criteria([$productABId]);
        $criteria->addAssociation('visibilities');

        $productB = $productRepository->search($criteria, Context::createDefaultContext())->first();

        static::assertInstanceOf(ProductEntity::class$productB);

        static::assertInstanceOf(ProductVisibilityCollection::class$productB->getVisibilities());
        
        static::assertInstanceOf(EntityWrittenEvent::class$event);
        static::assertCount(2, $event->getWriteResults());

        $criteria = new Criteria([$id]);
        $criteria->addAssociation('visibilities');

        /** @var ProductEntity $product */
        $product = $this->productRepository->search($criteria$context)->first();

        // check visibilities can be loaded as association         static::assertInstanceOf(ProductEntity::class$product);
        static::assertInstanceOf(ProductVisibilityCollection::class$product->getVisibilities());
        static::assertCount(2, $product->getVisibilities());

        // check read for visibilities         $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('product_visibility.productId', $id));

        $visibilities = $this->visibilityRepository->search($criteria$context);
        static::assertCount(2, $visibilities);

        // test filter visibilities over product         $criteria = new Criteria([$id]);

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