GenericCartError example

public function getIterator(): \Traversable
    {
        yield from $this->collection;
    }

    /** * @param array<string, mixed> $parameters */
    private function createError(string $key, bool $blockOrder, bool $blockResubmit, array $parameters, int $level, ?string $id = null): void
    {
        $this->collection->add(
            new GenericCartError($id ?? $key$key$parameters$level$blockOrder, true, $blockResubmit)
        );
    }
}
$request = new Request(['foo' => ['bar' => 'baz'], 'another_one' => ['test' => 'foo']]);
        $params = $this->controller->testDecodeParam($request, 'foo');

        static::assertCount(1, $params);

        static::assertArrayHasKey('bar', $params);
        static::assertSame('baz', $params['bar']);
    }

    public function testAddCartErrors(): void
    {
        $error = new GenericCartError(
            'generic_test_error',
            'test.error.message',
            ['test' => 'error'],
            Error::LEVEL_ERROR,
            true,
            true
        );

        $cart = new Cart('foo');
        $cart->addErrors($error);

        
$cart->setPrice(new CartPrice(
            100,
            100,
            100,
            new CalculatedTaxCollection(),
            new TaxRuleCollection(),
            CartPrice::TAX_STATE_GROSS
        ));

        $cart->setErrors(new ErrorCollection([
            new GenericCartError('foo', 'foo', [], 1, false, false),
        ]));

        $facade = new CartFacade(
            $this->createMock(CartFacadeHelper::class),
            $this->createMock(ScriptPriceStubs::class),
            $cart,
            $this->createMock(SalesChannelContext::class)
        );

        $items = $facade->items();
        static::assertCount(3, $items);
        
public function testAddPromotionOtherExceptions(): void
    {
        $code = Uuid::randomHex();

        $request = new Request([]['code' => $code]);
        $cart = new Cart(Uuid::randomHex());
        $context = $this->createMock(SalesChannelContext::class);
        $uniqueKey = PromotionItemBuilder::PLACEHOLDER_PREFIX . $code;
        $item = new LineItem($uniqueKey, PromotionProcessor::LINE_ITEM_TYPE);
        $item->setLabel($code);
        $cart->addErrors(new GenericCartError('d', 's', [], 0, false, true));

        $this->promotionItemBuilderMock->method('buildPlaceholderItem')->willReturn($item);

        $this->cartService->expects(static::once())
            ->method('add')
            ->with($cart$item$context)
            ->willReturn($cart);

        $session = new Session(new MockArraySessionStorage());
        $this->translatorCallback($session);

        

        $request = new Request();
        $request->setSession($this->createMock(Session::class));

        $context = $this->createMock(SalesChannelContext::class);
        $context->method('getCustomer')->willReturn(new CustomerEntity());

        $this->orderServiceMock->expects(static::once())->method('createOrder')->willThrowException(
            CartException::invalidCart(
                new ErrorCollection(
                    [
                        new GenericCartError(
                            Uuid::randomHex(),
                            'message',
                            [],
                            1,
                            true,
                            false
                        ),
                    ]
                )
            )
        );

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