app/Plugin/EccubePaymentLite42/Form/Extension/Admin/OrderTypeExtension.php line 36

Open in your IDE?
  1. <?php
  2. namespace Plugin\EccubePaymentLite42\Form\Extension\Admin;
  3. use Eccube\Common\EccubeConfig;
  4. use Eccube\Entity\Order;
  5. use Eccube\Form\Type\Admin\OrderType;
  6. use Plugin\EccubePaymentLite42\Entity\PaymentStatus;
  7. use Plugin\EccubePaymentLite42\Repository\PaymentStatusRepository;
  8. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  9. use Symfony\Component\Form\AbstractTypeExtension;
  10. use Symfony\Component\Form\FormBuilderInterface;
  11. class OrderTypeExtension extends AbstractTypeExtension
  12. {
  13.     /**
  14.      * @var EccubeConfig
  15.      */
  16.     protected $eccubeConfig;
  17.     /**
  18.      * @var PaymentStatusRepository
  19.      */
  20.     private $paymentStatusRepository;
  21.     public function __construct(
  22.         EccubeConfig $eccubeConfig,
  23.         PaymentStatusRepository $paymentStatusRepository
  24.     ) {
  25.         $this->eccubeConfig $eccubeConfig;
  26.         $this->paymentStatusRepository $paymentStatusRepository;
  27.     }
  28.     /**
  29.      * {@inheritdoc}
  30.      */
  31.     public function buildForm(FormBuilderInterface $builder, array $options)
  32.     {
  33.         /** @var Order $Order */
  34.         $Order $builder->getForm()->getData();
  35.         if (is_null($Order) || !$Order->getId()) {
  36.             return;
  37.         }
  38.         $statuses = [
  39.             PaymentStatus::UNPAID,
  40.             PaymentStatus::CHARGED,
  41.             PaymentStatus::TEMPORARY_SALES,
  42.             PaymentStatus::CANCEL,
  43.         ];
  44.         if ($Order->getPaymentMethod() === $this->eccubeConfig['gmo_epsilon']['pay_name']['deferred']) {
  45.             $statuses[] = PaymentStatus::UNDER_REVIEW;
  46.             $statuses[] = PaymentStatus::SHIPPING_REGISTRATION;
  47.             $statuses[] = PaymentStatus::EXAMINATION_NG;
  48.         }
  49.         $paymentStatuses $this->paymentStatusRepository->findBy(['id' => $statuses], [
  50.             'sort_no' => 'ASC',
  51.         ]);
  52.         $builder
  53.             ->add('PaymentStatus'EntityType::class, [
  54.                 'required' => false,
  55.                 'class' => PaymentStatus::class,
  56.                 'choices' => $paymentStatuses,
  57.                 'placeholder' => '-',
  58.                 'mapped' => false,
  59.                 'data' => $Order->getPaymentStatus(),
  60.             ]);
  61.     }
  62.     /**
  63.      * {@inheritdoc}
  64.      */
  65.     public function getExtendedType()
  66.     {
  67.         return OrderType::class;
  68.     }
  69.     /**
  70.      * Return the class of the type being extended.
  71.      */
  72.     public static function getExtendedTypes(): iterable
  73.     {
  74.         return [OrderType::class];
  75.     }
  76. }