forked from BitBagCommerce/SyliusBlacklistPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OP-466 - Add autocomplete to customer field
- Loading branch information
Showing
10 changed files
with
148 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
/* | ||
* This file has been created by developers from BitBag. | ||
* Feel free to contact us once you face any issues or want to start | ||
* You can find more information about us on https://bitbag.io and write us | ||
* an email on [email protected]. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitBag\SyliusBlacklistPlugin\Form\Type; | ||
|
||
use Sylius\Bundle\ResourceBundle\Form\Type\ResourceAutocompleteChoiceType; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\FormInterface; | ||
use Symfony\Component\Form\FormView; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
final class CustomerAutocompleteChoiceType extends AbstractType | ||
{ | ||
public function configureOptions(OptionsResolver $resolver): void | ||
{ | ||
$resolver->setDefaults([ | ||
'resource' => 'sylius.customer', | ||
'choice_name' => 'email', | ||
'choice_value' => 'id', | ||
]); | ||
} | ||
|
||
public function buildView(FormView $view, FormInterface $form, array $options): void | ||
{ | ||
$view->vars['remote_criteria_type'] = 'contains'; | ||
$view->vars['remote_criteria_name'] = 'email'; | ||
} | ||
|
||
public function getBlockPrefix(): string | ||
{ | ||
return 'bitbag_sylius_customer_autocomplete_choice'; | ||
} | ||
|
||
public function getParent(): string | ||
{ | ||
return ResourceAutocompleteChoiceType::class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,42 @@ | ||
<?php | ||
|
||
/* | ||
* This file was created by developers working at BitBag | ||
* Do you need more information about us and what we do? Visit our https://bitbag.io website! | ||
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career | ||
*/ | ||
* This file has been created by developers from BitBag. | ||
* Feel free to contact us once you face any issues or want to start | ||
* You can find more information about us on https://bitbag.io and write us | ||
* an email on [email protected]. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitBag\SyliusBlacklistPlugin\Form\Type; | ||
|
||
use BitBag\SyliusBlacklistPlugin\Entity\FraudPrevention\FraudSuspicionInterface; | ||
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; | ||
use Symfony\Bridge\Doctrine\Form\Type\EntityType; | ||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||
use Symfony\Component\Form\Extension\Core\Type\TextareaType; | ||
use Symfony\Component\Form\Extension\Core\Type\TextType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\Validator\Constraints\NotNull; | ||
|
||
final class FraudSuspicionType extends AbstractResourceType | ||
{ | ||
/** @var string */ | ||
private $customerClass; | ||
|
||
public function __construct( | ||
string $dataClass, | ||
string $customerClass, | ||
array $validationGroups = [] | ||
array $validationGroups = [], | ||
) { | ||
parent::__construct($dataClass, $validationGroups); | ||
|
||
$this->customerClass = $customerClass; | ||
} | ||
|
||
public function buildForm(FormBuilderInterface $builder, array $options): void | ||
{ | ||
$builder | ||
->add('customer', EntityType::class, [ | ||
'class' => $this->customerClass, | ||
->add('customer', CustomerAutocompleteChoiceType::class, [ | ||
'label' => 'sylius.ui.customer', | ||
'priority' => 1, | ||
'constraints' => [ | ||
new NotNull(), | ||
], | ||
]) | ||
->add('company', TextType::class, [ | ||
'required' => false, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
/* | ||
* This file has been created by developers from BitBag. | ||
* Feel free to contact us once you face any issues or want to start | ||
* You can find more information about us on https://bitbag.io and write us | ||
* an email on [email protected]. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitBag\SyliusBlacklistPlugin\Repository; | ||
|
||
trait CustomerRepositoryTrait | ||
{ | ||
|
||
public function findByEmailPart(string $email, ?int $limit = null): array | ||
{ | ||
return $this->createQueryBuilder('c') | ||
->andWhere('c.email LIKE :email') | ||
->setParameter('email', '%' . $email . '%') | ||
->setMaxResults($limit) | ||
->getQuery() | ||
->getResult(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{% extends '@SyliusUi/Form/theme.html.twig' %} | ||
|
||
{% block bitbag_sylius_customer_autocomplete_choice_row %} | ||
{{ form_row(form, { | ||
'remote_url': path('bitbag_sylius_blacklist_plugin_admin_ajax_customer_by_email'), | ||
'load_edit_url': path('bitbag_sylius_blacklist_plugin_admin_ajax_customer_by_id') | ||
}) }} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
/* | ||
* This file has been created by developers from BitBag. | ||
* Feel free to contact us once you face any issues or want to start | ||
* You can find more information about us on https://bitbag.io and write us | ||
* an email on [email protected]. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\BitBag\SyliusBlacklistPlugin\Repository; | ||
|
||
use BitBag\SyliusBlacklistPlugin\Repository\CustomerRepositoryTrait; | ||
use Sylius\Bundle\CoreBundle\Doctrine\ORM\CustomerRepository as BaseCustomerRepository; | ||
|
||
class CustomerRepository extends BaseCustomerRepository | ||
{ | ||
use CustomerRepositoryTrait; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters