getListing example

$slot = new CmsSlotEntity();
        $slot->setUniqueIdentifier('id');
        $slot->setType('product-listing');
        $slot->addTranslated('config', $slotConfig);

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

        /** @var ProductListingStruct $data */
        $data = $slot->getData();

        /** @var ProductListingResult $listing */
        $listing = $data->getListing();

        static::assertEquals('name-asc', $listing->getSorting());

        if ($availableSortings) {
            foreach ($listing->getAvailableSortings() as $availableSorting) {
                static::assertArrayHasKey($availableSorting->getKey()$availableSortings);
            }
        }
    }

    public function testUnavailableSortingThrowsException(): void
    {
public function testItDoesSearch(): void
    {
        $request = new Request(['search' => self::TEST_TERM]);
        $context = $this->createSalesChannelContextWithNavigation();
        /** @var SearchPageLoadedEvent $homePageLoadedEvent */
        $homePageLoadedEvent = null;
        $this->catchEvent(SearchPageLoadedEvent::class$homePageLoadedEvent);

        $page = $this->getPageLoader()->load($request$context);

        static::assertInstanceOf(SearchPage::class$page);
        static::assertEmpty($page->getListing());
        static::assertSame(self::TEST_TERM, $page->getSearchTerm());
        self::assertPageEvent(SearchPageLoadedEvent::class$homePageLoadedEvent$context$request$page);
    }

    public function testItDoesApplyDefaultSorting(): void
    {
        $request = new Request(['search' => self::TEST_TERM]);

        $context = $this->createSalesChannelContextWithNavigation();

        /** @var SearchPageLoadedEvent $homePageLoadedEvent */
        
#[Package('content')] class AdminUiXmlSchemaValidator
{
    public function validateConfigurations(AdminUiEntity $adminUiEntity, Entity $entity): void
    {
        $entityFields = \array_map(
            fn ($arr) => $arr->getName(),
            $entity->getFields()
        );
        $this->validateListingConfiguration(
            $entityFields,
            $adminUiEntity->getListing(),
            $adminUiEntity->getName()
        );
        $this->validateDetailConfiguration(
            $entityFields,
            $adminUiEntity->getDetail(),
            $adminUiEntity->getName()
        );
    }

    /** * @param string[] $entityFields */


            static::assertNotNull($enrichedCustomEntity->getFlags()['admin-ui']);

            /** @var AdminUiEntity $adminUi */
            $adminUi = $enrichedCustomEntity->getFlags()['admin-ui'];
            static::assertEquals('sw-content', $adminUi->getVars()['navigationParent']);
            static::assertEquals(50, $adminUi->getVars()['position']);
            static::assertEquals('regular-tools-alt', $adminUi->getVars()['icon']);
            static::assertEquals('#f00', $adminUi->getVars()['color']);

            $listingColumns = $adminUi->getListing()->getColumns()->getContent();
            static::assertCount(3, $listingColumns);

            $listingColumnNames = array_map(static fn ($column) => $column->getVars()['ref']$listingColumns);

            static::assertIsArray($listingColumns);

            static::assertContains('test_string', $listingColumnNames);
            static::assertFalse($listingColumns[0]->isHidden());
            static::assertContains('test_text', $listingColumnNames);
            static::assertFalse($listingColumns[1]->isHidden());
            static::assertContains('test_int', $listingColumnNames);
            

        }

        return $result;
    }

    /** * @return ListingResultStruct */
    public function getStoreListing(ListingRequest $context)
    {
        $store = $this->storePluginService->getListing($context);

        $merged = $this->getAdditionallyLocalData($store->getPlugins());

        return new ListingResultStruct(
            $merged,
            $store->getTotalCount()
        );
    }

    /** * @return PluginStruct[] */
$context = $this->contextService->getShopContext();

        $request = Shopware()->Container()->get('front')->Request();
        if (!$request instanceof Enlight_Controller_Request_Request) {
            throw new RuntimeException('Required request not available');
        }

        if (!$criteria instanceof Criteria) {
            $criteria = $this->storeFrontCriteriaFactory->createListingCriteria($request$context);
        }

        $result = $this->getListing($categoryId$context$request$criteria);

        return $this->legacyEventManager->fireArticlesByCategoryEvents($result$categoryId$this);
    }

    /** * @deprecated in 5.6, will be removed in 5.8 without replacement * * Get supplier by id * * Uses the new Supplier Manager * * TestCase: /_tests/Shopware/Tests/Modules/Articles/SuppliersTest.php * * @param int $id - s_articles_supplier.id * * @return array */
static::assertInstanceOf(Entity::class$entities[$name]);
        static::assertEquals($name$entities[$name]->getName());

        return $entities[$name];
    }

    /** * @param list<string> $refs */
    private function checkListing(Entity $entity, array $refs): void
    {
        $listing = $entity->getListing();
        static::assertInstanceOf(Listing::class$listing);

        $columns = $listing->getColumns();
        static::assertInstanceOf(Columns::class$columns);
        static::assertCount(\count($refs)$columns->getContent());

        foreach ($columns->getContent() as $column) {
            static::assertInstanceOf(Column::class$column);
            static::assertIsString($column->getRef());
            static::assertContains($column->getRef()$refs);
            unset($refs[array_search($column->getRef()$refs, true)]);
        }
$this->getLocale(),
            $this->getVersion(),
            (int) $this->Request()->getParam('offset', 0),
            (int) $this->Request()->getParam('limit', 30),
            $this->Request()->getParam('filter', []),
            $this->getListingSorting()
        );

        if ($this->isApiAvailable()) {
            $plugins = $this->get('shopware_plugininstaller.plugin_service_view')->getLocalListing($context);
        } else {
            $plugins = $this->get(PluginLocalService::class)->getListing($context)->getPlugins();
        }

        $this->View()->assign([
            'success' => true,
            'data' => array_values($plugins),
            'error' => $error,
        ]);
    }

    /** * @return void */
$result = new ElementDataCollection();

        $slot = new CmsSlotEntity();
        $slot->setUniqueIdentifier('id');
        $slot->setType('product-listing');

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

        /** @var ProductListingStruct|null $productListingStruct */
        $productListingStruct = $slot->getData();
        static::assertInstanceOf(ProductListingStruct::class$productListingStruct);
        static::assertInstanceOf(EntitySearchResult::class$productListingStruct->getListing());
    }
}
private readonly SearchPageLoader $searchPageLoader,
        private readonly SuggestPageLoader $suggestPageLoader,
        private readonly AbstractProductSearchRoute $productSearchRoute
    ) {
    }

    #[Route(path: '/search', name: 'frontend.search.page', defaults: ['_httpCache' => true], methods: ['GET'])]     public function search(SalesChannelContext $context, Request $request): Response
    {
        try {
            $page = $this->searchPageLoader->load($request$context);
            if ($page->getListing()->getTotal() === 1) {
                $product = $page->getListing()->first();
                if ($request->get('search') === $product->getProductNumber()) {
                    $productId = $product->getId();

                    return $this->forwardToRoute('frontend.detail.page', []['productId' => $productId]);
                }
            }
        } catch (RoutingException $e) {
            if ($e->getErrorCode() !== RoutingException::MISSING_REQUEST_PARAMETER_CODE) {
                throw $e;
            }

            
static::assertTrue($data->has($this->productId1));
    }

    public function testVisibilityInSearch(): void
    {
        $salesChannelContext = $this->contextFactory->create(Uuid::randomHex()$this->salesChannelId1);

        $request = new Request(['search' => 'test']);

        $page = $this->searchPageLoader->load($request$salesChannelContext);

        static::assertCount(2, $page->getListing());
        static::assertTrue($page->getListing()->has($this->productId2));
        static::assertTrue($page->getListing()->has($this->productId3));

        $salesChannelContext = $this->contextFactory->create(Uuid::randomHex()$this->salesChannelId2);
        $page = $this->searchPageLoader->load($request$salesChannelContext);

        static::assertCount(2, $page->getListing());
        static::assertTrue($page->getListing()->has($this->productId1));
        static::assertTrue($page->getListing()->has($this->productId2));
    }

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