diff --git a/src/Form/Type/OrderItemType.php b/src/Form/Type/OrderItemType.php index e251d2d..a935463 100644 --- a/src/Form/Type/OrderItemType.php +++ b/src/Form/Type/OrderItemType.php @@ -5,10 +5,9 @@ namespace Setono\SyliusOrderEditPlugin\Form\Type; use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; +use Sylius\Bundle\ResourceBundle\Form\Type\ResourceAutocompleteChoiceType; use Sylius\Component\Core\Model\OrderItemInterface; -use Sylius\Component\Core\Model\ProductVariant; use Sylius\Component\Order\Modifier\OrderItemQuantityModifierInterface; -use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\Extension\Core\Type\IntegerType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormEvent; @@ -37,10 +36,13 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $this->orderItemQuantityModifier->modify($orderItem, $quantity); }, ]) - // TODO: change to autocomplete type for product variant - ->add('variant', EntityType::class, [ - 'class' => ProductVariant::class, - 'choice_label' => 'code', + ->add('variant', ResourceAutocompleteChoiceType::class, [ + 'label' => false, + 'multiple' => false, + 'required' => true, + 'choice_name' => 'descriptor', + 'choice_value' => 'id', + 'resource' => 'sylius.product_variant', ]) ; diff --git a/src/Resources/public/js/order-edit.js b/src/Resources/public/js/order-edit.js index 1898c05..437e4d0 100644 --- a/src/Resources/public/js/order-edit.js +++ b/src/Resources/public/js/order-edit.js @@ -23,7 +23,11 @@ document.querySelector('button.add-order-item').addEventListener('click', (event orderItemTable.dataset.index++; var rows = orderItemTable.querySelectorAll('form[name="sylius_order"] tbody tr'); - var lastItemRowDeleteButton = rows[rows.length - 2].querySelector('button.delete-order-item'); + var lastItemRow = rows[rows.length - 2]; + var lastItemRowDeleteButton = lastItemRow.querySelector('button.delete-order-item'); + + $(lastItemRow).find('.sylius-autocomplete').autoComplete(); + lastItemRowDeleteButton.addEventListener('click', (event) => { var row = event.currentTarget.closest('tr'); row.nextElementSibling.remove(); diff --git a/src/Resources/views/admin/order/update/theme.html.twig b/src/Resources/views/admin/order/update/theme.html.twig index 3ec8e54..b6cb8cb 100644 --- a/src/Resources/views/admin/order/update/theme.html.twig +++ b/src/Resources/views/admin/order/update/theme.html.twig @@ -3,7 +3,14 @@ {% block _sylius_order_items_entry_widget %}