setErrors example

if (!$allowAdderRemover && null !== $adderAccessName && null !== $removerAccessName) {
            $errors[] = [sprintf(
                'The property "%s" in class "%s" can be defined with the methods "%s()" but '.
                'the new value must be an array or an instance of \Traversable',
                $property,
                $reflClass->getName(),
                implode('()", "', [$adderAccessName$removerAccessName])
            )];
        }

        $noneProperty = new PropertyWriteInfo();
        $noneProperty->setErrors(array_merge([], ...$errors));

        return $noneProperty;
    }

    /** * @return Type[]|null */
    private function extractFromMutator(string $class, string $property): ?array
    {
        [$reflectionMethod$prefix] = $this->getMutatorMethod($class$property);
        if (null === $reflectionMethod) {
            

        $mergeableLineItems = $guestCart->getLineItems()->filter(fn (LineItem $item) => ($item->getQuantity() > 0 && $item->isStackable()) || !$customerCart->has($item->getId()));

        $this->eventDispatcher->dispatch(new BeforeCartMergeEvent(
            $customerCart,
            $guestCart,
            $mergeableLineItems,
            $customerContext
        ));

        $errors = $customerCart->getErrors();
        $customerCart->setErrors(new ErrorCollection());

        $customerCartClone = clone $customerCart;
        $customerCart->setErrors($errors);
        $customerCartClone->setErrors($errors);

        $mergedCart = $this->cartService->add($customerCart$mergeableLineItems->getElements()$customerContext);

        $this->eventDispatcher->dispatch(new CartMergedEvent($mergedCart$customerContext$customerCartClone));

        return $mergedCart;
    }

    

    private function payloadExists(): bool
    {
        return EntityDefinitionQueryHelper::columnExists($this->connection, 'cart', 'payload');
    }

    private function serializeCart(Cart $cart, bool $payloadExists): string
    {
        $errors = $cart->getErrors();
        $data = $cart->getData();

        $cart->setErrors(new ErrorCollection());
        $cart->setData(null);

        $this->cartSerializationCleaner->cleanupCart($cart);

        // @deprecated tag:v6.6.0 - remove else part         if ($payloadExists) {
            $serialized = $this->compress ? CacheValueCompressor::compress($cart) : serialize($cart);
        } else {
            $serialized = serialize($cart);
        }

        
/** * @internal * * @covers \Shopware\Storefront\Checkout\Cart\SalesChannel\StorefrontCartFacade */
class StorefrontCartFacadeTest extends TestCase
{
    public function testGetNoBlockedMethods(): void
    {
        $cart = $this->getCart();
        $cart->setErrors($this->getCartErrorCollection());

        $cartFacade = $this->getStorefrontCartFacade($cart);
        $salesChannelContext = $this->getSalesChannelContext();
        $returnedCart = $cartFacade->get('', $salesChannelContext);

        static::assertEquals($this->getCart()$returnedCart);
    }

    public function testGetBlockedShippingMethodAllowFallback(): void
    {
        $errorCollection = $this->getCartErrorCollection(true);

        
$this->save($cart$copyContext);
        $cart->setToken($oldToken);

        $this->delete($oldToken$context);
    }

    private function serializeCart(Cart $cart, SalesChannelContext $context): string
    {
        $errors = $cart->getErrors();
        $data = $cart->getData();

        $cart->setErrors(new ErrorCollection());
        $cart->setData(null);

        $this->cartSerializationCleaner->cleanupCart($cart);

        $content = ['cart' => $cart, 'rule_ids' => $context->getRuleIds()];

        $content = $this->compress ? CacheValueCompressor::compress($content) : \serialize($content);

        $cart->setErrors($errors);
        $cart->setData($data);

        
$controller->setContainer($this->getContainer());
        $controller->setTemplateFinder($twig->getExtension(NodeExtension::class)->getFinder());

        $rendered = $controller->testRenderViewInheritance('@Storefront/storefront/page/plugin/index.html.twig');

        static::assertEquals('plugin', $rendered);
    }

    public static function cartProvider(): \Generator
    {
        $cart = new Cart('test');
        $cart->setErrors(new ErrorCollection(self::getErrors()));

        yield 'cart with salutation errors' => [
            $cart,
        ];
    }

    /** * @return array{ * 0: 'request_stack', * 1: ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, * 2: Stub&RequestStack * } */
$cart->addState('within-test');

        $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();
        
Home | Imprint | This part of the site doesn't use cookies.