diff --git a/src/DependencyInjection/SetonoSyliusOrderEditExtension.php b/src/DependencyInjection/SetonoSyliusOrderEditExtension.php index dceb25a..79e293a 100644 --- a/src/DependencyInjection/SetonoSyliusOrderEditExtension.php +++ b/src/DependencyInjection/SetonoSyliusOrderEditExtension.php @@ -51,6 +51,13 @@ public function prepend(ContainerBuilder $container): void ], ], ], + 'sylius.admin.order.show.summary' => [ + 'blocks' => [ + 'store_notes' => [ + 'template' => '@SetonoSyliusOrderEditPlugin/admin/order/show/_store_notes.html.twig', + ], + ], + ], ], ]); diff --git a/src/Entity/EditableOrderInterface.php b/src/Entity/EditableOrderInterface.php index 3fc0df0..da1f97f 100644 --- a/src/Entity/EditableOrderInterface.php +++ b/src/Entity/EditableOrderInterface.php @@ -13,4 +13,8 @@ public function isAlreadyPaid(): bool; public function getInitialTotal(): int; public function setInitialTotal(int $initialTotal): void; + + public function getStoreNotes(): ?string; + + public function setStoreNotes(?string $storeNotes): void; } diff --git a/src/Entity/EditableOrderTrait.php b/src/Entity/EditableOrderTrait.php index 8338ad8..45ec84c 100644 --- a/src/Entity/EditableOrderTrait.php +++ b/src/Entity/EditableOrderTrait.php @@ -15,6 +15,10 @@ trait EditableOrderTrait #[ORM\Column(type: 'integer')] private int $initialTotal = 0; + /** @ORM\Column(type="text", nullable=true) */ + #[ORM\Column(type: 'text', nullable: true)] + private ?string $storeNotes = null; + public function isAlreadyPaid(): bool { return $this->getPaymentState() === OrderPaymentStates::STATE_PAID; @@ -29,4 +33,14 @@ public function setInitialTotal(int $initialTotal): void { $this->initialTotal = $initialTotal; } + + public function getStoreNotes(): ?string + { + return $this->storeNotes; + } + + public function setStoreNotes(?string $storeNotes): void + { + $this->storeNotes = $storeNotes; + } } diff --git a/src/Form/Extension/OrderTypeExtension.php b/src/Form/Extension/OrderTypeExtension.php index f43dbcb..97dd49f 100644 --- a/src/Form/Extension/OrderTypeExtension.php +++ b/src/Form/Extension/OrderTypeExtension.php @@ -9,6 +9,7 @@ use Sylius\Bundle\OrderBundle\Form\Type\OrderType; use Sylius\Component\Core\Model\OrderInterface; use Symfony\Component\Form\AbstractTypeExtension; +use Symfony\Component\Form\Extension\Core\Type\TextareaType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; @@ -17,6 +18,14 @@ final class OrderTypeExtension extends AbstractTypeExtension { public function buildForm(FormBuilderInterface $builder, array $options): void { + $builder->add('storeNotes', TextareaType::class, [ + 'required' => false, + 'label' => 'setono_sylius_order_edit.ui.store_notes', + 'attr' => [ + 'placeholder' => 'setono_sylius_order_edit.ui.store_notes_placeholder', + ], + ]); + $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event): void { $form = $event->getForm(); /** @var OrderInterface $order */ @@ -26,15 +35,14 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->add('items', OrderItemCollectionType::class, [ 'entry_options' => ['currency_code' => $order->getCurrencyCode()], ]) + ->add('discounts', OrderDiscountCollectionType::class, [ + 'property_path' => 'adjustments', + 'entry_options' => [ + 'currency' => $order->getCurrencyCode(), + ], + 'button_add_label' => 'setono_sylius_order_edit.ui.add_discount', + ]) ; - - $form->add('discounts', OrderDiscountCollectionType::class, [ - 'property_path' => 'adjustments', - 'entry_options' => [ - 'currency' => $order->getCurrencyCode(), - ], - 'button_add_label' => 'setono_sylius_order_edit.ui.add_discount', - ]); }); $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event): void { diff --git a/src/Resources/translations/messages.en.yaml b/src/Resources/translations/messages.en.yaml index a113870..6923488 100644 --- a/src/Resources/translations/messages.en.yaml +++ b/src/Resources/translations/messages.en.yaml @@ -5,3 +5,5 @@ setono_sylius_order_edit: discounts: Discounts order_discounts: Order discounts order_items: Order items + store_notes: Store notes + store_notes_placeholder: If you want to add a note regarding your changes, you can do it here. The customer will not be able to see this note... diff --git a/src/Resources/views/admin/order/show/_store_notes.html.twig b/src/Resources/views/admin/order/show/_store_notes.html.twig new file mode 100644 index 0000000..cef43ae --- /dev/null +++ b/src/Resources/views/admin/order/show/_store_notes.html.twig @@ -0,0 +1,10 @@ +{% if order.storeNotes is not null %} +