ProductNoLongerAvailableEvent example

'ids' => ArrayParameterType::STRING]
            );
        });

        $updated = $this->connection->fetchFirstColumn(
            'SELECT LOWER(HEX(id)) FROM product WHERE available = 0 AND id IN (:ids) AND product.version_id = :version',
            ['ids' => $bytes, 'version' => Uuid::fromHexToBytes($context->getVersionId())],
            ['ids' => ArrayParameterType::STRING]
        );

        if (!empty($updated)) {
            $this->dispatcher->dispatch(new ProductNoLongerAvailableEvent($updated$context));
        }
    }

    /** * @param list<array{referenced_id: string, quantity: string}> $products */
    private function updateStockAndSales(array $products, int $stockMultiplier): void
    {
        $query = new RetryableQuery(
            $this->connection,
            $this->connection->prepare('UPDATE product SET stock = stock + :quantity, sales = sales - :quantity WHERE id = :id AND version_id = :version')
        );

                $this->tags = array_values($event->getKeys());
            }
        };

        $eventDispatcher->addListener(InvalidateCacheEvent::class$listener);

        foreach ($scenarios as $scenario) {
            /** @var list<string> $productsIds */
            $productsIds = array_map(fn (string $product) => $this->ids->get($product)$scenario['invalidate']);

            $this->subscriber->invalidateDetailRoute(new ProductNoLongerAvailableEvent(
                $productsIds,
                Context::createDefaultContext()
            ));

            static::assertSame(
                array_map(fn (string $product) => 'product-detail-route-' . $this->ids->get($product)$scenario['expected']),
                $listener->tags
            );
        }
    }

    
'ids' => ArrayParameterType::STRING]
            );
        });

        $updated = $this->connection->fetchFirstColumn(
            'SELECT LOWER(HEX(id)) FROM product WHERE available = 0 AND id IN (:ids) AND product.version_id = :version',
            ['ids' => $bytes, 'version' => Uuid::fromHexToBytes($context->getVersionId())],
            ['ids' => ArrayParameterType::STRING]
        );

        if (!empty($updated)) {
            $this->dispatcher->dispatch(new ProductNoLongerAvailableEvent($updated$context));
        }
    }
}
Home | Imprint | This part of the site doesn't use cookies.