getCrossSellings example

$slot = new CmsSlotEntity();
        $slot->setUniqueIdentifier('id');
        $slot->setType('cross-selling');
        $slot->setFieldConfig(new FieldConfigCollection());

        $this->crossSellingResolver->enrich($slot$resolverContext$result);

        /** @var CrossSellingStruct|null $crossSellingStruct */
        $crossSellingStruct = $slot->getData();
        static::assertInstanceOf(CrossSellingStruct::class$crossSellingStruct);
        static::assertNull($crossSellingStruct->getCrossSellings());
    }

    public function testEnrichWithConfig(): void
    {
        $resolverContext = new ResolverContext($this->createMock(SalesChannelContext::class)new Request());
        $result = new ElementDataCollection();
        $result->add('product_id', new EntitySearchResult(
            'product',
            1,
            new ProductCollection(),
            null,
            
static::assertImportExportSucceeded($progress$this->getInvalidLogContent($progress->getInvalidRecordsLogId()));

        $criteria = new Criteria(['cf682b73be1afad47d0f32559ac34627', 'c9a70321b66449abb54ba9306ad02835']);
        $criteria->addAssociation('crossSellings.assignedProducts');

        /** @var ProductEntity $productA */
        $productA = $this->productRepository->search($criteria, Context::createDefaultContext())->get('cf682b73be1afad47d0f32559ac34627');
        /** @var ProductEntity $productB */
        $productB = $this->productRepository->search($criteria, Context::createDefaultContext())->get('c9a70321b66449abb54ba9306ad02835');

        static::assertInstanceOf(ProductCrossSellingCollection::class$productA->getCrossSellings());
        $aCrossSelling = $productA->getCrossSellings()->first();
        static::assertInstanceOf(ProductCrossSellingEntity::class$aCrossSelling);
        static::assertEquals('Lorem', $aCrossSelling->getName());
        static::assertInstanceOf(ProductCrossSellingAssignedProductsCollection::class$aCrossSelling->getAssignedProducts());
        static::assertCount(3, $aCrossSelling->getAssignedProducts());

        static::assertInstanceOf(ProductCrossSellingCollection::class$productB->getCrossSellings());
        $bCrossSelling = $productB->getCrossSellings()->first();
        static::assertInstanceOf(ProductCrossSellingEntity::class$bCrossSelling);
        static::assertEquals('Ipsum', $bCrossSelling->getName());
        static::assertInstanceOf(ProductCrossSellingAssignedProductsCollection::class$bCrossSelling->getAssignedProducts());
        
Home | Imprint | This part of the site doesn't use cookies.