From ca530260078b12ba9ba030b13bbb36fb19c680fd Mon Sep 17 00:00:00 2001 From: Carnage Date: Sun, 17 Dec 2017 17:01:12 +0000 Subject: [PATCH 1/5] refactored to send full purchase through to form + add extra display information --- src/Controller/TicketController.php | 2 +- src/Form/PurchaseForm.php | 5 +++-- view/tickets/ticket/purchase.phtml | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Controller/TicketController.php b/src/Controller/TicketController.php index 7883099..0539431 100644 --- a/src/Controller/TicketController.php +++ b/src/Controller/TicketController.php @@ -199,7 +199,7 @@ public function purchaseAction() return $this->redirect()->toRoute('tickets/complete', ['purchaseId' => $purchaseId]); } - $form = new PurchaseForm($purchase->getTicketCount()); + $form = new PurchaseForm($purchase); if ($this->getRequest()->isPost()) { $noPayment = true; diff --git a/src/Form/PurchaseForm.php b/src/Form/PurchaseForm.php index 9019aac..278b557 100644 --- a/src/Form/PurchaseForm.php +++ b/src/Form/PurchaseForm.php @@ -2,6 +2,7 @@ namespace ConferenceTools\Tickets\Form; +use ConferenceTools\Tickets\Domain\ReadModel\TicketRecord\PurchaseRecord; use ConferenceTools\Tickets\Domain\ValueObject\Delegate; use ConferenceTools\Tickets\Form\Fieldset\DelegateInformation; use ConferenceTools\Tickets\Hydrator\DelegateHydrator; @@ -15,7 +16,7 @@ class PurchaseForm extends Form { - public function __construct($tickets) + public function __construct(PurchaseRecord $purchase) { parent::__construct('delegate-form'); $this->add(['type' => Hidden::class, 'name' => 'stripe_token']); @@ -28,7 +29,7 @@ public function __construct($tickets) ] ]); - for ($i = 0; $i < $tickets; $i++) { + foreach ($purchase->getTickets() as $i => $ticket) { $this->add(['type' => DelegateInformation::class, 'name' => 'delegates_' . $i]); } diff --git a/view/tickets/ticket/purchase.phtml b/view/tickets/ticket/purchase.phtml index ec27b9a..7e3b905 100644 --- a/view/tickets/ticket/purchase.phtml +++ b/view/tickets/ticket/purchase.phtml @@ -28,11 +28,11 @@ $this->headLink()->appendStylesheet('/css/card.css'); - getTicketCount(); $i++):?> + purchase->getTickets() as $i => $ticket):?>
-

Delegate Information

+

Delegate Information getTicketType()->getDisplayName()?>

@@ -41,7 +41,7 @@ $this->headLink()->appendStylesheet('/css/card.css'); formCollection($this->form->get('delegates_' . $i));?>
- + formHidden($this->form->get('security'))?> From da9d7a0d36f65070f237449a7408bdc704b47061 Mon Sep 17 00:00:00 2001 From: Carnage Date: Sun, 17 Dec 2017 17:08:35 +0000 Subject: [PATCH 2/5] Minor visual tweeks --- assets/css/card.css | 5 +++++ view/tickets/ticket/purchase.phtml | 9 +++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/assets/css/card.css b/assets/css/card.css index 12fe0e5..afae2b9 100644 --- a/assets/css/card.css +++ b/assets/css/card.css @@ -40,6 +40,11 @@ body { margin-top:20px; } vertical-align: middle; width: 50%; } +.credit-card-box .display-td-full { + display: table-cell; + vertical-align: middle; + width: 100%; +} /* Just looks nicer */ .credit-card-box .panel-heading img { min-width: 180px; diff --git a/view/tickets/ticket/purchase.phtml b/view/tickets/ticket/purchase.phtml index 7e3b905..98e225a 100644 --- a/view/tickets/ticket/purchase.phtml +++ b/view/tickets/ticket/purchase.phtml @@ -28,17 +28,18 @@ $this->headLink()->appendStylesheet('/css/card.css'); - purchase->getTickets() as $i => $ticket):?> + purchase->getTickets() as $id => $ticket):?>
-

Delegate Information getTicketType()->getDisplayName()?>

-
+

Delegate Information (getTicketType()->getDisplayName()?>)

You can complete this information later if you wish

- formCollection($this->form->get('delegates_' . $i));?> + formCollection($this->form->get('delegates_' . $id));?>
From 04ff00996f96f724c3c3b9c50cdb7b06d30611b9 Mon Sep 17 00:00:00 2001 From: Carnage Date: Sun, 17 Dec 2017 17:24:59 +0000 Subject: [PATCH 3/5] Fix type error when user defines no discount codes --- src/Domain/Service/Configuration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Domain/Service/Configuration.php b/src/Domain/Service/Configuration.php index a6bf58e..0364b2d 100644 --- a/src/Domain/Service/Configuration.php +++ b/src/Domain/Service/Configuration.php @@ -112,7 +112,7 @@ class Configuration * * @var DiscountCode[] */ - private $discountCodes; + private $discountCodes = []; /** * Contains metadata about tickets eg when they are available for sale From 4ac2a3f2681632d66db3314147ca288fbe8f03f6 Mon Sep 17 00:00:00 2001 From: Carnage Date: Sun, 17 Dec 2017 19:01:02 +0000 Subject: [PATCH 4/5] Ignore delegate info for supplimentry tickets --- src/Controller/TicketController.php | 8 ++++++-- src/Domain/Service/Configuration.php | 3 ++- src/Domain/ValueObject/TicketType.php | 22 ++++++++++++++++++++-- src/Form/PurchaseForm.php | 6 +++++- view/tickets/ticket/complete.phtml | 5 ++++- 5 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/Controller/TicketController.php b/src/Controller/TicketController.php index 0539431..1cd9015 100644 --- a/src/Controller/TicketController.php +++ b/src/Controller/TicketController.php @@ -219,8 +219,12 @@ public function purchaseAction() $delegateInfo = []; - for ($i = 0; $i < $purchase->getTicketCount(); $i++) { - $delegateInfo[] = Delegate::fromArray($data['delegates_' . $i]); + foreach ($purchase->getTickets() as $i => $ticket) { + if (!$ticket->getTicketType()->isSupplementary()) { + $delegateInfo[] = Delegate::fromArray($data['delegates_' . $i]); + } else { + $delegateInfo[] = Delegate::emptyObject(); + } } $command = new CompletePurchase($purchaseId, $data['purchase_email'], ...$delegateInfo); diff --git a/src/Domain/Service/Configuration.php b/src/Domain/Service/Configuration.php index 0364b2d..1df9cd8 100644 --- a/src/Domain/Service/Configuration.php +++ b/src/Domain/Service/Configuration.php @@ -179,7 +179,8 @@ private function addTicketInformation(array $ticket, string $identifier) $identifier, $price, $ticket['name'], - $ticket['description'] ?? '' + $ticket['description'] ?? '', + $ticket['supplementary'] ?? false ); $this->avaliableTickets[$identifier] = $ticket['available']; diff --git a/src/Domain/ValueObject/TicketType.php b/src/Domain/ValueObject/TicketType.php index 409b779..bdc8597 100644 --- a/src/Domain/ValueObject/TicketType.php +++ b/src/Domain/ValueObject/TicketType.php @@ -40,12 +40,25 @@ final class TicketType */ private $description; - public function __construct(string $identifier, Price $price, string $displayName, string $description = '') - { + /** + * @var boolean + * @Jms\Type("boolean") + * @ORM\Column(type="boolean") + */ + private $supplementary = false; + + public function __construct( + string $identifier, + Price $price, + string $displayName, + string $description = '', + bool $supplementary = false + ) { $this->identifier = $identifier; $this->price = $price; $this->displayName = $displayName; $this->description = $description; + $this->supplementary = $supplementary; } public function getIdentifier(): string @@ -67,4 +80,9 @@ public function getDescription(): string { return $this->description; } + + public function isSupplementary(): bool + { + return $this->supplementary; + } } \ No newline at end of file diff --git a/src/Form/PurchaseForm.php b/src/Form/PurchaseForm.php index 278b557..1a15a66 100644 --- a/src/Form/PurchaseForm.php +++ b/src/Form/PurchaseForm.php @@ -3,6 +3,7 @@ namespace ConferenceTools\Tickets\Form; use ConferenceTools\Tickets\Domain\ReadModel\TicketRecord\PurchaseRecord; +use ConferenceTools\Tickets\Domain\ReadModel\TicketRecord\TicketRecord; use ConferenceTools\Tickets\Domain\ValueObject\Delegate; use ConferenceTools\Tickets\Form\Fieldset\DelegateInformation; use ConferenceTools\Tickets\Hydrator\DelegateHydrator; @@ -30,7 +31,10 @@ public function __construct(PurchaseRecord $purchase) ]); foreach ($purchase->getTickets() as $i => $ticket) { - $this->add(['type' => DelegateInformation::class, 'name' => 'delegates_' . $i]); + /** @var TicketRecord $ticket */ + if (!$ticket->getTicketType()->isSupplementary()) { + $this->add(['type' => DelegateInformation::class, 'name' => 'delegates_' . $i]); + } } $this->add(new Csrf('security')); diff --git a/view/tickets/ticket/complete.phtml b/view/tickets/ticket/complete.phtml index a688956..fc5cda5 100644 --- a/view/tickets/ticket/complete.phtml +++ b/view/tickets/ticket/complete.phtml @@ -21,7 +21,10 @@ getTicketType()->getDisplayName()?> - Manage + getTicketType()->isSupplementary()): ?> + Manage + + From 7daaf27f902f4199a1b88cc27a0c0cd489bc7198 Mon Sep 17 00:00:00 2001 From: Carnage Date: Sun, 17 Dec 2017 19:21:15 +0000 Subject: [PATCH 5/5] Minor fixes --- view/tickets/ticket/complete.phtml | 4 ++-- view/tickets/ticket/purchase.phtml | 28 +++++++++++++++++----------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/view/tickets/ticket/complete.phtml b/view/tickets/ticket/complete.phtml index fc5cda5..afafcec 100644 --- a/view/tickets/ticket/complete.phtml +++ b/view/tickets/ticket/complete.phtml @@ -21,9 +21,9 @@ getTicketType()->getDisplayName()?> - getTicketType()->isSupplementary()): ?> + getTicketType()->isSupplementary()): ?> Manage - + diff --git a/view/tickets/ticket/purchase.phtml b/view/tickets/ticket/purchase.phtml index 98e225a..16c7af1 100644 --- a/view/tickets/ticket/purchase.phtml +++ b/view/tickets/ticket/purchase.phtml @@ -30,19 +30,25 @@ $this->headLink()->appendStylesheet('/css/card.css'); purchase->getTickets() as $id => $ticket):?> -
-
-
-

Delegate Information (getTicketType()->getDisplayName()?>)

+ foreach ($this->purchase->getTickets() as $id => $ticket): + if (!$ticket->getTicketType()->isSupplementary()):?> + +
+
+
+

Delegate Information (getTicketType()->getDisplayName()?>)

+
+
+
+

You can complete this information later if you wish

+ formCollection($this->form->get('delegates_' . $id));?>
-
-

You can complete this information later if you wish

- formCollection($this->form->get('delegates_' . $id));?> -
-
- + + formHidden($this->form->get('security'))?>