Skip to content

Commit

Permalink
Merge branch 'develop' into add-products
Browse files Browse the repository at this point in the history
# Conflicts:
#	backend/app/DomainObjects/ProductDomainObject.php
#	backend/app/Services/Handlers/Order/CompleteOrderHandler.php
#	frontend/src/components/routes/product-widget/SelectProducts/Prices/Tiered/index.tsx
#	frontend/src/components/routes/product-widget/SelectProducts/index.tsx
#	frontend/src/locales/de.js
#	frontend/src/locales/de.po
#	frontend/src/locales/en.js
#	frontend/src/locales/en.po
#	frontend/src/locales/es.js
#	frontend/src/locales/es.po
#	frontend/src/locales/fr.js
#	frontend/src/locales/fr.po
#	frontend/src/locales/pt-br.js
#	frontend/src/locales/pt-br.po
#	frontend/src/locales/pt.js
#	frontend/src/locales/pt.po
#	frontend/src/locales/ru.js
#	frontend/src/locales/ru.po
#	frontend/src/locales/zh-cn.js
#	frontend/src/locales/zh-cn.po
  • Loading branch information
daveearley committed Sep 23, 2024
2 parents 8871867 + 7db9dcd commit d007041
Show file tree
Hide file tree
Showing 29 changed files with 3,424 additions and 2,922 deletions.
2 changes: 1 addition & 1 deletion backend/app/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ final class Constants
*
* @var int
*/
public const INFINITE = PHP_INT_MAX;
public const INFINITE = 999999999;
}
8 changes: 8 additions & 0 deletions backend/app/DomainObjects/ProductDomainObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Carbon\Carbon;
use HiEvents\DomainObjects\Enums\ProductPriceType;
use HiEvents\Constants;
use HiEvents\DomainObjects\Interfaces\IsSortable;
use HiEvents\DomainObjects\SortingAndFiltering\AllowedSorts;
use Illuminate\Support\Collection;
Expand Down Expand Up @@ -98,6 +99,13 @@ public function getQuantityAvailable(): int
return 0;
}

// This is to address a case where prices have an unlimited quantity available and the user has
// enabled show_quantity_remaining.
if ($this->getShowQuantityRemaining()
&& $this->getProductPrices()->first(fn(ProductPriceDomainObject $price) => $price->getQuantityAvailable() === null)) {
return Constants::INFINITE;
}

return $availableCount;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use HiEvents\Events\OrderStatusChangedEvent;
use HiEvents\Jobs\Order\SendOrderDetailsEmailJob;

readonly class SendOrderDetailsEmailListener
class SendOrderDetailsEmailListener
{
public function handle(OrderStatusChangedEvent $changedEvent): void
{
Expand Down
26 changes: 23 additions & 3 deletions backend/app/Services/Handlers/Order/CompleteOrderHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use HiEvents\Events\OrderStatusChangedEvent;
use HiEvents\Exceptions\ResourceConflictException;
use HiEvents\Helper\IdHelper;
use HiEvents\Repository\Eloquent\Value\Relationship;
use HiEvents\Repository\Interfaces\AttendeeRepositoryInterface;
use HiEvents\Repository\Interfaces\OrderRepositoryInterface;
use HiEvents\Repository\Interfaces\QuestionAnswerRepositoryInterface;
Expand Down Expand Up @@ -89,13 +90,14 @@ public function handle(string $orderShortId, CompleteOrderDTO $orderData): Order
private function createAttendees(Collection $attendees, OrderDomainObject $order): void
{
$inserts = [];

$productsPrices = $this->productPriceRepository->findWhereIn(
field: ProductPriceDomainObjectAbstract::ID,
values: $attendees->pluck('product_price_id')->toArray(),
);

$this->validateProductPriceIdsMatchOrder($order, $productsPrices);
$this->validateAttendees($order, $attendees);

foreach ($attendees as $attendee) {
$productId = $productsPrices->first(
Expand Down Expand Up @@ -191,7 +193,7 @@ private function createAttendeeQuestions(
private function validateOrder(OrderDomainObject $order): void
{
if ($order->getEmail() !== null) {
throw new ResourceConflictException(__('This order is has already been processed'));
throw new ResourceConflictException(__('This order has already been processed'));
}

if (Carbon::createFromTimeString($order->getReservedUntil())->isPast()) {
Expand All @@ -209,7 +211,11 @@ private function validateOrder(OrderDomainObject $order): void
private function getOrder(string $orderShortId): OrderDomainObject
{
$order = $this->orderRepository
->loadRelation(OrderItemDomainObject::class)
->loadRelation(
new Relationship(
domainObject: OrderItemDomainObject::class,
nested: [new Relationship(TicketDomainObject::class, name: 'ticket')]
))
->findByShortId($orderShortId);

if ($order === null) {
Expand Down Expand Up @@ -257,4 +263,18 @@ private function validateProductPriceIdsMatchOrder(OrderDomainObject $order, Col
throw new ResourceConflictException(__('There is an unexpected product price ID in the order'));
}
}

/**
* @throws ResourceConflictException
*/
private function validateAttendees(OrderDomainObject $order, Collection $attendees): void
{
$orderAttendeeCount = $order->getOrderItems()->sum(fn(OrderItemDomainObject $orderItem) => $orderItem->getQuantity());

if ($orderAttendeeCount !== $attendees->count()) {
throw new ResourceConflictException(
__('The number of attendees does not match the number of tickets in the order')
);
}
}
}
2 changes: 1 addition & 1 deletion backend/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<env name="APP_ENV" value="testing"/>
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="DB_DATABASE" value="testing"/>
<!-- <env name="DB_DATABASE" value="testing"/>-->
<env name="MAIL_MAILER" value="array"/>
<env name="QUEUE_CONNECTION" value="sync"/>
<env name="SESSION_DRIVER" value="array"/>
Expand Down
Loading

0 comments on commit d007041

Please sign in to comment.