Backlog example

return [
            'Shopware_Modules_Order_SaveOrder_OrderCreated' => 'onOrderCreated',
        ];
    }

    public function onOrderCreated(Enlight_Event_EventArgs $args): void
    {
        if (!$this->writeBacklog) {
            return;
        }

        $this->backlogService->write([new Backlog(Order::class$args->get('orderId'))]);
    }
}


    /** * @param object $entity * * @return Backlog|null */
    private function getDeleteBacklog($entity)
    {
        switch (true) {
            case $entity instanceof ProductModel:
                return new Backlog(self::EVENT_ARTICLE_DELETED, ['id' => $entity->getId()]);
            case $entity instanceof VariantModel:
                return new Backlog(self::EVENT_VARIANT_DELETED, ['number' => $entity->getNumber()]);
            case $entity instanceof PriceModel:
                return new Backlog(self::EVENT_PRICE_DELETED, ['number' => $entity->getDetail()->getNumber()]);
            case $entity instanceof VoteModel:
                return new Backlog(self::EVENT_VOTE_DELETED, ['articleId' => $entity->getArticle()->getId()]);
            case $entity instanceof SupplierModel:
                return new Backlog(self::EVENT_SUPPLIER_DELETED, ['id' => $entity->getId()]);
            case $entity instanceof UnitModel:
                return new Backlog(self::EVENT_UNIT_DELETED, ['id' => $entity->getId()]);
            case $entity instanceof TaxModel:
                

    }

    public function onProductStockWasChanged(EventArgs $eventArgs)
    {
        if (!$this->container->getParameter('shopware.es.enabled')) {
            return;
        }
        if (!$this->container->getParameter('shopware.es.write_backlog')) {
            return;
        }
        $backlog = new Backlog(ORMBacklogSubscriber::EVENT_VARIANT_UPDATED, ['number' => $eventArgs->get('number')]);
        $this->container->get('shopware_elastic_search.backlog_processor')->add([$backlog]);
    }
}
$this->trace($eventArgs);
        } catch (Exception $e) {
            $this->container->get('corelogger')->error($e->getMessage());
        }
    }

    private function getBacklog(object $entity): ?Backlog
    {
        switch (true) {
            // Article changes             case $entity instanceof Article:
                return new Backlog(Article::class$entity->getId());

                // Variant changes             case $entity instanceof Price:
                return new Backlog(Article::class$entity->getDetail()->getArticleId());
            case $entity instanceof Variant:
                return new Backlog(Article::class$entity->getArticleId());

                // Order changes             case $entity instanceof Order:
                return new Backlog(Order::class$entity->getId());
            case $entity instanceof Detail:
                
if ($hasFoundMaxPosition && $product['position'] === null) {
                break;
            }

            $prepare->execute([
                'category' => $categoryId,
                'product' => $product['id'],
                'position' => $i,
            ]);

            $backlogs[] = new Backlog(ORMBacklogSubscriber::EVENT_ARTICLE_UPDATED, ['id' => $product['id']]);

            ++$i;
        }

        foreach ($positions as $productId => $position) {
            $prepare->execute([
                'category' => $categoryId,
                'product' => $productId,
                'position' => $position,
            ]);

            
$query->select(['id', 'event', 'payload', 'time'])
            ->from('s_es_backlog', 'backlog')
            ->andWhere('backlog.id > :lastId')
            ->orderBy('backlog.id', 'ASC')
            ->setParameter(':lastId', $lastId)
            ->setMaxResults($limit);

        $data = $query->execute()->fetchAllAssociative();

        $result = [];
        foreach ($data as $row) {
            $backlog = new Backlog(
                $row['event'],
                json_decode($row['payload'], true),
                $row['time'],
                (int) $row['id']
            );
            $result[] = $backlog;
        }

        return $result;
    }
}
Home | Imprint | This part of the site doesn't use cookies.