ProductListingResolvePreviewEvent example

use Shopware\Core\Framework\Log\Package;
use Shopware\Core\System\SalesChannel\SalesChannelContext;

/** * @internal */
#[Package('inventory')] class ProductListingResolvePreviewEventTest extends TestCase
{
    public function testReplace(): void
    {
        $event = new ProductListingResolvePreviewEvent(
            $this->createMock(SalesChannelContext::class),
            new Criteria(),
            ['p1' => 'p1'],
            true
        );

        $event->replace('p1', 'p2');
        static::assertSame(['p1' => 'p2']$event->getMapping());
    }

    public function testReplaceException(): void
    {
$context->getContext()
            );
        }

        $mapping = array_combine($keys$keys);

        $hasOptionFilter = $this->hasOptionFilter($criteria);
        if (!$hasOptionFilter) {
            $mapping = $this->resolvePreviews($keys$context);
        }

        $event = new ProductListingResolvePreviewEvent($context$criteria$mapping$hasOptionFilter);
        $this->eventDispatcher->dispatch($event);
        $mapping = $event->getMapping();

        $read = $criteria->cloneForRead(array_values($mapping));
        $read->addAssociation('options.group');

        $searchResult = $this->productRepository->search($read$context);

        $this->addExtensions($ids$searchResult$mapping);

        $result = new EntitySearchResult(ProductDefinition::ENTITY_NAME, $ids->getTotal()$searchResult->getEntities()$aggregations$origin$context->getContext());
        
Home | Imprint | This part of the site doesn't use cookies.