updateReviewCountForCustomer example



            $changeset = $result->getChangeSet();
            \assert($changeset instanceof ChangeSet);

            $id = $changeset->getBefore('customer_id');

            if (!\is_string($id)) {
                continue;
            }

            $this->productReviewCountService->updateReviewCountForCustomer($id);
        }
    }

    public function createReview(EntityWrittenEvent $reviewEvent): void
    {
        if ($reviewEvent->getEntityName() !== ProductReviewDefinition::ENTITY_NAME) {
            return;
        }

        /** @var list<string> $ids */
        $ids = $reviewEvent->getIds();

        
$payload = [];
            }
        }

        if (!empty($payload)) {
            $this->writer->upsert($this->productReviewDefinition, $payload$writeContext);

            $context->getConsole()->progressAdvance(\count($payload));
        }

        foreach ($customerIdsWithReviews as $customerId => $_) {
            $this->productReviewCountService->updateReviewCountForCustomer(Uuid::fromHexToBytes($customerId));
        }

        $context->getConsole()->progressFinish();
    }

    /** * @return array<string> */
    private function getCustomerIds(): array
    {
        $sql = 'SELECT LOWER(HEX(id)) as id FROM customer LIMIT 200';

        

        }

        /** @var list<string> $affectedCustomers */
        $affectedCustomers = array_filter($this->connection->fetchFirstColumn(
            'SELECT DISTINCT(`customer_id`) FROM product_review WHERE id IN (:ids)',
            ['ids' => Uuid::fromHexToBytesList($reviewIds)],
            ['ids' => ArrayParameterType::STRING]
        ));

        foreach ($affectedCustomers as $customerId) {
            $this->updateReviewCountForCustomer($customerId);
        }
    }

    public function updateReviewCountForCustomer(string $customerId): void
    {
        $this->connection->executeStatement(
            'UPDATE `customer` SET review_count = ( SELECT COUNT(*) FROM `product_review` WHERE `customer_id` = :id AND `status` = 1 ) WHERE id = :id',
            ['id' => $customerId]
        );
    }
Home | Imprint | This part of the site doesn't use cookies.