Skip to content

Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️

663 B
Raw Blame
<?php

namespace HiEvents\Services\Domain\Product;

use HiEvents\DomainObjects\ProductDomainObject;
use HiEvents\Repository\Interfaces\ProductRepositoryInterface;

class ProductOrderingService
{
    public function __construct(
        private readonly ProductRepositoryInterface $productRepository
    ) {}

    public function getOrderForNewProduct(int $eventId, int $productCategoryId): int
    {
        return ($this->productRepository->findWhere([
            'event_id' => $eventId,
            'product_category_id' => $productCategoryId,
        ])
            ->max((static fn (ProductDomainObject $product) => $product->getOrder())) ?? 0) + 1;
    }
}