ProductSortingEntity example


    private $productSortingRepository;

    protected function setUp(): void
    {
        parent::setUp();
        $this->productSortingRepository = $this->getContainer()->get('product_sorting.repository');
    }

    public function testProductSortingFieldPriority(): void
    {
        $productSortingEntity = new ProductSortingEntity();
        $productSortingEntity->setFields(
            [
                ['field' => 'product.name', 'order' => 'asc', 'priority' => 1, 'naturalSorting' => 1],
                ['field' => 'product.cheapestPrice', 'order' => 'asc', 'priority' => 1000, 'naturalSorting' => 1],
            ]
        );

        /** @var FieldSorting[] $sortings */
        $sortings = $productSortingEntity->createDalSorting();

        static::assertCount(2, $sortings);
        
public static function unknownSortingProvider(): \Generator
    {
        yield 'Requested unknown sorting will throw exception' => ['unknown'];
        yield 'Requested empty sorting will throw exception' => [''];
        yield 'Requested null sorting will throw exception' => [null];
        yield 'Requested empty array sorting will throw exception' => [[]];
    }

    private function buildSortings(): ProductSortingCollection
    {
        return new ProductSortingCollection([
            (new ProductSortingEntity())->assign([
                '_uniqueIdentifier' => 'foo',
                'key' => 'foo',
                'fields' => [
                    ['field' => 'foo', 'priority' => 1, 'order' => 'DESC'],
                    ['field' => 'id', 'priority' => 2, 'order' => 'ASC'],
                ],
            ]),
            (new ProductSortingEntity())->assign([
                '_uniqueIdentifier' => 'bar',
                'key' => 'bar',
                'fields' => [
                    [
Home | Imprint | This part of the site doesn't use cookies.