getCustomFieldAllowList example


class CartBeforeSerializationEventTest extends TestCase
{
    public function testConstructor(): void
    {
        $cart = new Cart('cart');
        $customFieldAllowList = ['foo', 'bar'];

        $event = new CartBeforeSerializationEvent($cart$customFieldAllowList);

        static::assertSame($cart$event->getCart());
        static::assertSame($customFieldAllowList$event->getCustomFieldAllowList());
    }

    public function testSetCustomFieldAllowList(): void
    {
        $customFieldAllowList = ['foo', 'bar'];

        $event = new CartBeforeSerializationEvent(new Cart('cart')$customFieldAllowList);
        $event->setCustomFieldAllowList(['boo']);

        static::assertSame(['boo']$event->getCustomFieldAllowList());
    }

    
private readonly EventDispatcherInterface $eventDispatcher
    ) {
    }

    public function cleanupCart(Cart $cart): void
    {
        $customFieldAllowList = $this->connection->fetchFirstColumn('SELECT `name` FROM `custom_field` WHERE `allow_cart_expose` = 1;');

        $event = new CartBeforeSerializationEvent($cart$customFieldAllowList);
        $this->eventDispatcher->dispatch($event);

        $this->cleanupLineItems($cart->getLineItems()$event->getCustomFieldAllowList());

        foreach ($cart->getDeliveries() as $delivery) {
            $this->cleanupLineItems($delivery->getPositions()->getLineItems()$event->getCustomFieldAllowList());
        }
    }

    /** * @param array<mixed> $customFieldAllowList */
    private function cleanupLineItems(LineItemCollection $lineItems, array $customFieldAllowList): void
    {
        
Home | Imprint | This part of the site doesn't use cookies.