From e77a1e46383b0c36b02a10ae11fb59b90cdfb874 Mon Sep 17 00:00:00 2001 From: Chihiro Adachi <8196725+chihiro-adachi@users.noreply.github.com> Date: Fri, 20 Jul 2018 10:55:38 +0900 Subject: [PATCH] =?UTF-8?q?=E8=B5=A4=E9=9B=BB=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/Admin/Order/EditController.php | 179 +---------- src/Eccube/Entity/Master/TaxType.php | 2 +- src/Eccube/Entity/Order.php | 2 +- src/Eccube/Entity/OrderItem.php | 2 +- src/Eccube/Form/Type/Admin/OrderItemType.php | 282 +++++++----------- src/Eccube/Form/Type/Admin/OrderType.php | 57 ++-- .../bootstrap_4_horizontal_layout.html.twig | 34 +++ .../Resource/template/admin/Order/edit.twig | 91 +++--- .../admin/Order/order_item_prototype.twig | 53 +--- .../template/admin/Order/order_item_type.twig | 21 +- .../template/admin/Order/search_product.twig | 124 +++----- .../Web/Admin/Order/EditControllerTest.php | 23 +- 12 files changed, 284 insertions(+), 586 deletions(-) diff --git a/src/Eccube/Controller/Admin/Order/EditController.php b/src/Eccube/Controller/Admin/Order/EditController.php index ad1bb3e0605..15fd17152b9 100644 --- a/src/Eccube/Controller/Admin/Order/EditController.php +++ b/src/Eccube/Controller/Admin/Order/EditController.php @@ -18,9 +18,7 @@ use Eccube\Controller\AbstractController; use Eccube\Entity\Customer; use Eccube\Entity\Master\CustomerStatus; -use Eccube\Entity\Master\DeviceType; use Eccube\Entity\Master\OrderItemType; -use Eccube\Entity\Master\OrderStatus; use Eccube\Entity\Order; use Eccube\Entity\Shipping; use Eccube\Event\EccubeEvents; @@ -158,15 +156,14 @@ public function index(Request $request, $id = null) { $TargetOrder = null; $OriginOrder = null; - $isNewOrder = false; - if (is_null($id)) { + if (null === $id) { // 空のエンティティを作成. - $TargetOrder = $this->newOrder(); - $isNewOrder = true; + $TargetOrder = new Order(); + $TargetOrder->addShipping((new Shipping())->setOrder($TargetOrder)); } else { $TargetOrder = $this->orderRepository->find($id); - if (is_null($TargetOrder)) { + if (null === $TargetOrder) { throw new NotFoundHttpException(); } } @@ -203,14 +200,14 @@ public function index(Request $request, $id = null) $form = $builder->getForm(); // 単数配送の場合は配送先の編集ができる - if ($TargetOrder->isMultiple() == false) { + if (!$TargetOrder->isMultiple()) { $form['Shipping']->setData($TargetOrder->getShippings()[0]); } $form->handleRequest($request); $purchaseContext = new PurchaseContext($OriginOrder, $OriginOrder->getCustomer()); - if ($form->isSubmitted()) { + if ($form->isSubmitted() && $form['OrderItems']->isValid()) { $event = new EventArgs( [ 'builder' => $builder, @@ -223,9 +220,9 @@ public function index(Request $request, $id = null) $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_PROGRESS, $event); $flowResult = $this->purchaseFlow->validate($TargetOrder, $purchaseContext); + if ($flowResult->hasWarning()) { foreach ($flowResult->getWarning() as $warning) { - // TODO Warning の場合の処理 $this->addWarning($warning->getMessage(), 'admin'); } } @@ -241,7 +238,7 @@ public function index(Request $request, $id = null) case 'register': log_info('受注登録開始', [$TargetOrder->getId()]); - if ($flowResult->hasError() === false && $form->isValid()) { + if (!$flowResult->hasError() && $form->isValid()) { try { $this->purchaseFlow->prepare($TargetOrder, $purchaseContext); $this->purchaseFlow->commit($TargetOrder, $purchaseContext); @@ -289,21 +286,6 @@ public function index(Request $request, $id = null) } break; - - case 'add_delivery': - // お届け先情報の新規追加 - - $form = $builder->getForm(); - - $Shipping = new Shipping(); - $TargetOrder->addShipping($Shipping); - - $Shipping->setOrder($TargetOrder); - - $form->setData($TargetOrder); - - break; - default: break; } @@ -361,69 +343,6 @@ public function index(Request $request, $id = null) ]; } - /** - * 顧客情報を検索する. - * - * @Route("/%eccube_admin_route%/order/search/customer", name="admin_order_search_customer") - * - * @param Request $request - * - * @return \Symfony\Component\HttpFoundation\JsonResponse - */ - public function searchCustomer(Request $request) - { - if ($request->isXmlHttpRequest()) { - log_debug('search customer start.'); - - $searchData = [ - 'multi' => $request->get('search_word'), - ]; - - $qb = $this->customerRepository->getQueryBuilderBySearchData($searchData); - - $event = new EventArgs( - [ - 'qb' => $qb, - 'data' => $searchData, - ], - $request - ); - $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_SEARCH, $event); - - /** @var Customer[] $Customers */ - $Customers = $qb->getQuery()->getResult(); - - if (empty($Customers)) { - log_debug('search customer not found.'); - } - - $data = []; - $formatName = '%s%s(%s%s)'; - foreach ($Customers as $Customer) { - $data[] = [ - 'id' => $Customer->getId(), - 'name' => sprintf($formatName, $Customer->getName01(), $Customer->getName02(), - $Customer->getKana01(), - $Customer->getKana02()), - 'phone_number' => $Customer->getPhoneNumber(), - 'email' => $Customer->getEmail(), - ]; - } - - $event = new EventArgs( - [ - 'data' => $data, - 'Customers' => $Customers, - ], - $request - ); - $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_COMPLETE, $event); - $data = $event->getArgument('data'); - - return $this->json($data); - } - } - /** * 顧客情報を検索する. * @@ -438,7 +357,7 @@ public function searchCustomer(Request $request) */ public function searchCustomerHtml(Request $request, $page_no = null, Paginator $paginator) { - if ($request->isXmlHttpRequest()) { + if ($request->isXmlHttpRequest() && $this->isTokenValid()) { log_debug('search customer start.'); $page_count = $this->eccubeConfig['eccube_default_page_count']; $session = $this->session; @@ -532,7 +451,7 @@ public function searchCustomerHtml(Request $request, $page_no = null, Paginator */ public function searchCustomerById(Request $request) { - if ($request->isXmlHttpRequest()) { + if ($request->isXmlHttpRequest() && $this->isTokenValid()) { log_debug('search customer by id start.'); /** @var $Customer \Eccube\Entity\Customer */ @@ -591,7 +510,7 @@ public function searchCustomerById(Request $request) */ public function searchProduct(Request $request, $page_no = null, Paginator $paginator) { - if ($request->isXmlHttpRequest()) { + if ($request->isXmlHttpRequest() && $this->isTokenValid()) { log_debug('search product start.'); $page_count = $this->eccubeConfig['eccube_default_page_count']; $session = $this->session; @@ -686,7 +605,7 @@ public function searchProduct(Request $request, $page_no = null, Paginator $pagi */ public function searchOrderItemType(Request $request) { - if ($request->isXmlHttpRequest()) { + if ($request->isXmlHttpRequest() && $this->isTokenValid()) { log_debug('search order item type start.'); $criteria = Criteria::create(); @@ -713,78 +632,4 @@ public function searchOrderItemType(Request $request) ]; } } - - protected function newOrder() - { - $Order = new Order(); - // device type - $DeviceType = $this->deviceTypeRepository->find(DeviceType::DEVICE_TYPE_ADMIN); - $Order->setDeviceType($DeviceType); - - $Shipping = new Shipping(); - $Order->addShipping($Shipping); - $Shipping->setOrder($Order); - - return $Order; - } - - /** - * 受注ステータスに応じて, 受注日/入金日/発送日を更新する, - * 発送済ステータスが設定された場合は, お届け先情報の発送日も更新を行う. - * - * 編集の場合 - * - 受注ステータスが他のステータスから発送済へ変更された場合に発送日を更新 - * - 受注ステータスが他のステータスから入金済へ変更された場合に入金日を更新 - * - * 新規登録の場合 - * - 受注日を更新 - * - 受注ステータスが発送済に設定された場合に発送日を更新 - * - 受注ステータスが入金済に設定された場合に入金日を更新 - * - * @param $app - * @param $TargetOrder - * @param $OriginOrder - * - * TODO Service へ移動する - */ - protected function updateDate($app, $TargetOrder, $OriginOrder) - { - $dateTime = new \DateTime(); - - // 編集 - if ($TargetOrder->getId()) { - // 発送済 - if ($TargetOrder->getOrderStatus()->getId() == OrderStatus::DELIVERED) { - // 編集前と異なる場合のみ更新 - if ($TargetOrder->getOrderStatus()->getId() != $OriginOrder->getOrderStatus()->getId()) { - // お届け先情報の発送日も更新する. - $Shippings = $TargetOrder->getShippings(); - foreach ($Shippings as $Shipping) { - $Shipping->setShippingDate($dateTime); - } - } - // 入金済 - } elseif ($TargetOrder->getOrderStatus()->getId() == OrderStatus::PAID) { - // 編集前と異なる場合のみ更新 - if ($TargetOrder->getOrderStatus()->getId() != $OriginOrder->getOrderStatus()->getId()) { - $TargetOrder->setPaymentDate($dateTime); - } - } - // 新規 - } else { - // 発送済 - if ($TargetOrder->getOrderStatus()->getId() == OrderStatus::DELIVERED) { - // お届け先情報の発送日も更新する. - $Shippings = $TargetOrder->getShippings(); - foreach ($Shippings as $Shipping) { - $Shipping->setShippingDate($dateTime); - } - // 入金済 - } elseif ($TargetOrder->getOrderStatus()->getId() == OrderStatus::PAID) { - $TargetOrder->setPaymentDate($dateTime); - } - // 受注日時 - $TargetOrder->setOrderDate($dateTime); - } - } } diff --git a/src/Eccube/Entity/Master/TaxType.php b/src/Eccube/Entity/Master/TaxType.php index 6859a4fdd0e..ce7ccfde97f 100644 --- a/src/Eccube/Entity/Master/TaxType.php +++ b/src/Eccube/Entity/Master/TaxType.php @@ -48,5 +48,5 @@ class TaxType extends \Eccube\Entity\Master\AbstractMasterEntity * * @var integer */ - const TAX_EXEMPT = 2; + const TAX_EXEMPT = 3; } diff --git a/src/Eccube/Entity/Order.php b/src/Eccube/Entity/Order.php index b67357a3657..a09b9be98b4 100644 --- a/src/Eccube/Entity/Order.php +++ b/src/Eccube/Entity/Order.php @@ -1352,7 +1352,7 @@ public function removeShipping(\Eccube\Entity\Shipping $Shipping) public function getShippings() { $criteria = Criteria::create() - ->orderBy(['name01' => Criteria::ASC, 'name02' => Criteria::ASC]); + ->orderBy(['name01' => Criteria::ASC, 'name02' => Criteria::ASC, 'id' => Criteria::ASC]); return $this->Shippings->matching($criteria); } diff --git a/src/Eccube/Entity/OrderItem.php b/src/Eccube/Entity/OrderItem.php index e6220dbd3eb..3362e8574e4 100644 --- a/src/Eccube/Entity/OrderItem.php +++ b/src/Eccube/Entity/OrderItem.php @@ -202,7 +202,7 @@ public function isTax() /** * @var string * - * @ORM\Column(name="quantity", type="decimal", precision=10, scale=0, options={"unsigned":true,"default":0}) + * @ORM\Column(name="quantity", type="decimal", precision=10, scale=0, options={"default":0}) */ private $quantity = 0; diff --git a/src/Eccube/Form/Type/Admin/OrderItemType.php b/src/Eccube/Form/Type/Admin/OrderItemType.php index 94a16221490..20253025249 100644 --- a/src/Eccube/Form/Type/Admin/OrderItemType.php +++ b/src/Eccube/Form/Type/Admin/OrderItemType.php @@ -15,16 +15,22 @@ use Doctrine\ORM\EntityManagerInterface; use Eccube\Common\EccubeConfig; +use Eccube\Entity\BaseInfo; use Eccube\Entity\Master\OrderItemType as OrderItemTypeMaster; use Eccube\Entity\Master\TaxDisplayType; use Eccube\Entity\Master\TaxType; +use Eccube\Entity\OrderItem; +use Eccube\Entity\ProductClass; use Eccube\Form\DataTransformer; use Eccube\Form\Type\PriceType; +use Eccube\Repository\BaseInfoRepository; use Eccube\Repository\Master\OrderItemTypeRepository; use Eccube\Repository\OrderItemRepository; use Eccube\Repository\ProductClassRepository; +use Eccube\Repository\TaxRuleRepository; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\HiddenType; +use Symfony\Component\Form\Extension\Core\Type\IntegerType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormEvent; @@ -45,6 +51,11 @@ class OrderItemType extends AbstractType */ protected $eccubeConfig; + /** + * @var BaseInfoRepository + */ + protected $BaseInfo; + /** * @var ProductClassRepository */ @@ -61,9 +72,9 @@ class OrderItemType extends AbstractType protected $orderItemTypeRepository; /** - * @var RequestStack + * @var TaxRuleRepository */ - protected $requestStack; + protected $taxRuleRepository; /** * OrderItemType constructor. @@ -77,17 +88,19 @@ class OrderItemType extends AbstractType public function __construct( EntityManagerInterface $entityManager, EccubeConfig $eccubeConfig, + BaseInfo $BaseInfo, ProductClassRepository $productClassRepository, OrderItemRepository $orderItemRepository, OrderItemTypeRepository $orderItemTypeRepository, - RequestStack $requestStack + TaxRuleRepository $taxRuleRepository ) { $this->entityManager = $entityManager; $this->eccubeConfig = $eccubeConfig; + $this->BaseInfo = $BaseInfo; $this->productClassRepository = $productClassRepository; $this->orderItemRepository = $orderItemRepository; $this->orderItemTypeRepository = $orderItemTypeRepository; - $this->requestStack = $requestStack; + $this->taxRuleRepository = $taxRuleRepository; } /** @@ -96,211 +109,126 @@ public function __construct( public function buildForm(FormBuilderInterface $builder, array $options) { $builder - ->add('new', HiddenType::class, [ - 'required' => false, - 'mapped' => false, - 'data' => 1, - ]) - ->add('id', HiddenType::class, [ - 'required' => false, - 'mapped' => false, - ]) - ->add('price', PriceType::class, [ - 'accept_minus' => true, - ]) - ->add('quantity', TextType::class, [ + ->add('product_name', TextType::class, [ 'constraints' => [ new Assert\NotBlank(), new Assert\Length([ - 'max' => $this->eccubeConfig['eccube_int_len'], + 'max' => $this->eccubeConfig['eccube_mtext_len'], ]), ], ]) - ->add('tax_rate', TextType::class, [ - 'constraints' => [ - new Assert\NotBlank(), - new Assert\Length([ - 'max' => $this->eccubeConfig['eccube_int_len'], - ]), - new Assert\Regex([ - 'pattern' => "/^\d+(\.\d+)?$/u", - 'message' => 'form.type.float.invalid', - ]), - ], + ->add('price', PriceType::class, [ ]) - ->add('product_name', TextType::class, [ + ->add('quantity', IntegerType::class, [ 'constraints' => [ - new Assert\NotBlank(), new Assert\Length([ - 'max' => $this->eccubeConfig['eccube_mtext_len'], + 'max' => $this->eccubeConfig['eccube_int_len'], ]), ], - ]) - ->add('product_code', HiddenType::class) - ->add('class_name1', HiddenType::class) - ->add('class_name2', HiddenType::class) - ->add('class_category_name1', HiddenType::class) - ->add('class_category_name2', HiddenType::class) - ->add('tax_rule', HiddenType::class)// ->add('order_id', HiddenType::class) - ; + ]); $builder ->add($builder->create('order_item_type', HiddenType::class) ->addModelTransformer(new DataTransformer\EntityToIdTransformer( $this->entityManager, - '\Eccube\Entity\Master\OrderItemType' - ))) - ->add($builder->create('tax_type', HiddenType::class) - ->addModelTransformer(new DataTransformer\EntityToIdTransformer( - $this->entityManager, - '\Eccube\Entity\Master\TaxType' - ))) - ->add($builder->create('tax_display_type', HiddenType::class) - ->addModelTransformer(new DataTransformer\EntityToIdTransformer( - $this->entityManager, - '\Eccube\Entity\Master\TaxDisplayType' - ))) - ->add($builder->create('Product', HiddenType::class) - ->addModelTransformer(new DataTransformer\EntityToIdTransformer( - $this->entityManager, - '\Eccube\Entity\Product' + OrderItemTypeMaster::class ))) ->add($builder->create('ProductClass', HiddenType::class) ->addModelTransformer(new DataTransformer\EntityToIdTransformer( $this->entityManager, - '\Eccube\Entity\ProductClass' - ))) - ->add($builder->create('Order', HiddenType::class) - ->addModelTransformer(new DataTransformer\EntityToIdTransformer( - $this->entityManager, - '\Eccube\Entity\Order' - ))) - ->add($builder->create('Shipping', HiddenType::class) - ->addModelTransformer(new DataTransformer\EntityToIdTransformer( - $this->entityManager, - '\Eccube\Entity\Shipping' + ProductClass::class ))); - // XXX price を priceIncTax にセットし直す - // OrderItem::getTotalPrice でもやっているので、どこか一箇所にまとめたい $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) { - /** @var \Eccube\Entity\OrderItem $OrderItem */ + /** @var OrderItem $OrderItem */ $OrderItem = $event->getData(); - $TaxDisplayType = $OrderItem->getTaxDisplayType(); - if (!$TaxDisplayType) { - return; - } - switch ($TaxDisplayType->getId()) { - // 税込価格 - case TaxDisplayType::INCLUDED: - $OrderItem->setPriceIncTax($OrderItem->getPrice()); - break; - // 税別価格の場合は税額を加算する - case TaxDisplayType::EXCLUDED: - // TODO 課税規則を考慮する - $OrderItem->setPriceIncTax($OrderItem->getPrice() + $OrderItem->getPrice() * $OrderItem->getTaxRate() / 100); - break; - } - - $event->setData($OrderItem); - }); - $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) { - // モーダルからのPOST時に、金額等をセットする. - if ('modal' === $this->requestStack->getCurrentRequest()->get('modal')) { - $data = $event->getData(); - // 受注済み明細の場合 - if (array_key_exists('id', $data) && isset($data['id'])) { - /** @var \Eccube\Entity\OrderItem $OrderItem */ - $OrderItem = $this->orderItemRepository - ->find($data['id']); - $data = array_merge($data, $OrderItem->toArray([ - 'Order', - 'Product', - 'ProductClass', - 'Shipping', - 'TaxType', - 'TaxDisplayType', - 'OrderItemType', - ])); - if (is_object($OrderItem->getOrder())) { - $data['Order'] = $OrderItem->getOrder()->getId(); + $OrderItemType = $OrderItem->getOrderItemType(); + switch ($OrderItemType->getId()) { + case OrderItemTypeMaster::PRODUCT: + $ProductClass = $OrderItem->getProductClass(); + $Product = $ProductClass->getProduct(); + $OrderItem->setProduct($Product); + if (null === $OrderItem->getPrice()) { + $OrderItem->setPrice($ProductClass->getPrice02()); + } + if (null === $OrderItem->getProductCode()) { + $OrderItem->setProductCode($ProductClass->getCode()); + } + if (null === $OrderItem->getClassName1() && $ProductClass->hasClassCategory1()) { + $ClassCategory1 = $ProductClass->getClassCategory1(); + $OrderItem->setClassName1($ClassCategory1->getClassName()->getName()); + $OrderItem->setClassCategoryName1($ClassCategory1->getName()); + } + if (null === $OrderItem->getClassName2() && $ProductClass->hasClassCategory2()) { + if ($ClassCategory2 = $ProductClass->getClassCategory2()) { + $OrderItem->setClassName2($ClassCategory2->getClassName()->getName()); + $OrderItem->setClassCategoryName2($ClassCategory2->getName()); + } + } + // 商品明細は税抜表示・課税 + if (null === $OrderItem->getTaxDisplayType()) { + $OrderItem->setTaxDisplayType($this->entityManager->find(TaxDisplayType::class, + TaxDisplayType::EXCLUDED)); + } + if (null === $OrderItem->getTaxType()) { + $OrderItem->setTaxType($this->entityManager->find(TaxType::class, TaxType::TAXATION)); + } + if (null === $OrderItem->getTaxRule()) { + $TaxRule = $this->taxRuleRepository->getByRule($Product, $ProductClass); + $OrderItem->setTaxRule($TaxRule->getId()); + $OrderItem->setTaxRate($TaxRule->getTaxRate()); } - if (is_object($OrderItem->getProduct())) { - $data['Product'] = $OrderItem->getProduct()->getId(); + break; + case OrderItemTypeMaster::DELIVERY_FEE: + // 送料明細は税込表示・課税 + if (null === $OrderItem->getTaxDisplayType()) { + $OrderItem->setTaxDisplayType($this->entityManager->find(TaxDisplayType::class, + TaxDisplayType::INCLUDED)); + } + if (null === $OrderItem->getTaxType()) { + $OrderItem->setTaxType($this->entityManager->find(TaxType::class, TaxType::TAXATION)); } - if (is_object($OrderItem->getProduct())) { - $data['ProductClass'] = $OrderItem->getProductClass()->getId(); + if (null === $OrderItem->getTaxRule()) { + $TaxRule = $this->taxRuleRepository->getByRule(); + $OrderItem->setTaxRule($TaxRule->getId()); + $OrderItem->setTaxRate($TaxRule->getTaxRate()); } - if (is_object($OrderItem->getTaxType())) { - $data['tax_type'] = $OrderItem->getTaxType()->getId(); + // no break + case OrderItemTypeMaster::CHARGE: + // 手数料明細は税込表示・課税 + if (null === $OrderItem->getTaxDisplayType()) { + $OrderItem->setTaxDisplayType($this->entityManager->find(TaxDisplayType::class, + TaxDisplayType::INCLUDED)); } - if (is_object($OrderItem->getTaxDisplayType())) { - $data['tax_display_type'] = $OrderItem->getTaxDisplayType()->getId(); + if (null === $OrderItem->getTaxType()) { + $OrderItem->setTaxType($this->entityManager->find(TaxType::class, TaxType::TAXATION)); } - if (is_object($OrderItem->getOrderItemType())) { - $data['order_item_type'] = $OrderItem->getOrderItemType()->getId(); + if (null === $OrderItem->getTaxRule()) { + $TaxRule = $this->taxRuleRepository->getByRule(); + $OrderItem->setTaxRule($TaxRule->getId()); + $OrderItem->setTaxRate($TaxRule->getTaxRate()); + } + break; + case OrderItemTypeMaster::DISCOUNT: + // 値引き明細は税抜表示・課税 + if (null === $OrderItem->getTaxDisplayType()) { + $OrderItem->setTaxDisplayType($this->entityManager->find(TaxDisplayType::class, + TaxDisplayType::EXCLUDED)); } - } else { - // 新規受注登録時の場合 - $data['price'] = 0; - $data['quantity'] = 1; - $data['product_code'] = null; - $data['class_name1'] = null; - $data['class_name2'] = null; - $data['class_category_name1'] = null; - $data['class_category_name2'] = null; - switch ($data['order_item_type']) { - case OrderItemTypeMaster::DELIVERY_FEE: - $data['product_name'] = $this->orderItemTypeRepository - ->find(OrderItemTypeMaster::DELIVERY_FEE) - ->getName(); - $data['tax_type'] = TaxType::TAXATION; - $data['tax_display_type'] = TaxDisplayType::INCLUDED; - break; - case OrderItemTypeMaster::CHARGE: - $data['product_name'] = $this->orderItemTypeRepository - ->find(OrderItemTypeMaster::CHARGE) - ->getName(); - $data['tax_type'] = TaxType::TAXATION; - $data['tax_display_type'] = TaxDisplayType::INCLUDED; - break; - case OrderItemTypeMaster::DISCOUNT: - $data['product_name'] = $this->orderItemTypeRepository - ->find(OrderItemTypeMaster::DISCOUNT) - ->getName(); - $data['tax_type'] = TaxType::NON_TAXABLE; - $data['tax_display_type'] = TaxDisplayType::INCLUDED; - break; - case OrderItemTypeMaster::PRODUCT: - default: - /** @var \Eccube\Entity\ProductClass $ProductClass */ - $ProductClass = $this->productClassRepository - ->find($data['ProductClass']); - /** @var \Eccube\Entity\Product $Product */ - $Product = $ProductClass->getProduct(); - $data['product_name'] = $Product->getName(); - $data['product_code'] = $ProductClass->getCode(); - $data['class_name1'] = $ProductClass->hasClassCategory1() ? - $ProductClass->getClassCategory1()->getClassName() : - null; - $data['class_name2'] = $ProductClass->hasClassCategory2() ? - $ProductClass->getClassCategory2()->getClassName() : - null; - $data['class_category_name1'] = $ProductClass->hasClassCategory1() ? - $ProductClass->getClassCategory1()->getName() : - null; - $data['class_category_name2'] = $ProductClass->hasClassCategory2() ? - $ProductClass->getClassCategory2()->getName() : - null; - $data['price'] = $ProductClass->getPrice02(); - $data['quantity'] = empty($data['quantity']) ? 1 : $data['quantity']; - $data['tax_type'] = TaxType::TAXATION; - $data['tax_display_type'] = TaxDisplayType::EXCLUDED; + if (null === $OrderItem->getTaxType()) { + $OrderItem->setTaxType($this->entityManager->find(TaxType::class, TaxType::TAXATION)); } - } - $event->setData($data); + if (null === $OrderItem->getTaxRule()) { + $TaxRule = $this->taxRuleRepository->getByRule(); + $OrderItem->setTaxRule($TaxRule->getId()); + $OrderItem->setTaxRate($TaxRule->getTaxRate()); + } + break; } + + // TaxRuleEventSubscriberを呼ぶため. + $this->entityManager->persist($OrderItem); }); } @@ -310,7 +238,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ - 'data_class' => 'Eccube\Entity\OrderItem', + 'data_class' => OrderItem::class, ]); } diff --git a/src/Eccube/Form/Type/Admin/OrderType.php b/src/Eccube/Form/Type/Admin/OrderType.php index cdc0865a136..a13d52133ac 100644 --- a/src/Eccube/Form/Type/Admin/OrderType.php +++ b/src/Eccube/Form/Type/Admin/OrderType.php @@ -15,7 +15,10 @@ use Doctrine\ORM\EntityManagerInterface; use Eccube\Common\EccubeConfig; -use Eccube\Entity\BaseInfo; +use Eccube\Entity\Master\OrderStatus; +use Eccube\Entity\Order; +use Eccube\Entity\OrderItem; +use Eccube\Entity\Payment; use Eccube\Form\DataTransformer; use Eccube\Form\Type\AddressType; use Eccube\Form\Type\KanaType; @@ -50,23 +53,16 @@ class OrderType extends AbstractType */ protected $eccubeConfig; - /** - * @var BaseInfo - */ - protected $BaseInfo; - /** * OrderType constructor. * * @param EntityManagerInterface $entityManager * @param EccubeConfig $eccubeConfig - * @param BaseInfo $BaseInfo */ - public function __construct(EntityManagerInterface $entityManager, EccubeConfig $eccubeConfig, BaseInfo $BaseInfo) + public function __construct(EntityManagerInterface $entityManager, EccubeConfig $eccubeConfig) { $this->entityManager = $entityManager; $this->eccubeConfig = $eccubeConfig; - $this->BaseInfo = $BaseInfo; } /** @@ -212,7 +208,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ], ]) ->add('OrderStatus', EntityType::class, [ - 'class' => 'Eccube\Entity\Master\OrderStatus', + 'class' => OrderStatus::class, 'choice_label' => 'name', 'placeholder' => 'order.placeholder.select', 'query_builder' => function ($er) { @@ -225,9 +221,13 @@ public function buildForm(FormBuilderInterface $builder, array $options) ]) ->add('Payment', EntityType::class, [ 'required' => false, - 'class' => 'Eccube\Entity\Payment', + 'class' => Payment::class, 'choice_label' => 'method', 'placeholder' => 'order.placeholder.select', + 'query_builder' => function ($er) { + return $er->createQueryBuilder('o') + ->orderBy('o.sort_no', 'ASC'); + }, 'constraints' => [ new Assert\NotBlank(), ], @@ -255,26 +255,50 @@ public function buildForm(FormBuilderInterface $builder, array $options) // 選択された支払い方法の名称をエンティティにコピーする $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) { + /** @var Order $Order */ $Order = $event->getData(); - $Payment = $Order->getPayment(); - if (!is_null($Payment)) { + if ($Payment = $Order->getPayment()) { $Order->setPaymentMethod($Payment->getMethod()); } // 会員受注の場合、会員の性別/職業/誕生日をエンティティにコピーする - $Customer = $Order->getCustomer(); - if (!is_null($Customer)) { + if ($Customer = $Order->getCustomer()) { $Order->setSex($Customer->getSex()); $Order->setJob($Customer->getJob()); $Order->setBirth($Customer->getBirth()); } $form = $event->getForm(); + /** @var OrderItem[] $OrderItems */ $OrderItems = $form['OrderItems']->getData(); if (empty($OrderItems) || count($OrderItems) < 1) { // 画面下部にエラーメッセージを表示させる $form['OrderItemsErrors']->addError(new FormError(trans('admin.order.edit.product.error'))); } + + // 明細とOrder, Shippingを紐付ける. + // 新規の明細のみが対象, 更新時はスキップする. + foreach ($OrderItems as $OrderItem) { + // 更新時はスキップ + if (!$OrderItem->getId()) { + continue; + } + + $OrderItem->setOrder($Order); + + // 送料明細の紐付けを行う. + // 複数配送の場合は, 常に最初のShippingと紐付ける. + // Order::getShippingsは氏名でソートされている. + if ($OrderItem->isDeliveryFee()) { + $OrderItem->setShipping($Order->getShippings()->first()); + } + + // 商品明細の紐付けを行う. + // 複数配送時は, 明細の追加は行われないためスキップする. + if ($OrderItem->isProduct() && !$Order->isMultiple()) { + $OrderItem->setShipping($Order->getShippings()->first()); + } + } }); } @@ -284,8 +308,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ - 'data_class' => 'Eccube\Entity\Order', - 'orign_order' => null, + 'data_class' => Order::class, 'SortedItems' => null, ]); } diff --git a/src/Eccube/Resource/template/admin/Form/bootstrap_4_horizontal_layout.html.twig b/src/Eccube/Resource/template/admin/Form/bootstrap_4_horizontal_layout.html.twig index 24d76fcec4d..383ec0821a9 100644 --- a/src/Eccube/Resource/template/admin/Form/bootstrap_4_horizontal_layout.html.twig +++ b/src/Eccube/Resource/template/admin/Form/bootstrap_4_horizontal_layout.html.twig @@ -36,3 +36,37 @@ file that was distributed with this source code. {%- endblock -%} + +{% block price_widget -%} + {%- set prepend = not (money_pattern starts with '{{') -%} + {%- set append = not (money_pattern ends with '}}') -%} + {%- if prepend or append -%} +
+ {# 税込/税抜を表示する #} + {%- if append and tax_display_type is defined -%} +
+ {{ tax_display_type.name }} +
+ {%- endif -%} + {%- if prepend -%} +
+ {{ money_pattern|form_encode_currency }} +
+ {%- endif -%} + {{- block('form_widget_simple') -}} + {%- if append -%} +
+ {{ money_pattern|form_encode_currency }} +
+ {%- endif -%} + {# 税込/税抜を表示する #} + {%- if prepend and tax_display_type is defined -%} +
+ {{ tax_display_type.name }} +
+ {%- endif -%} +
+ {%- else -%} + {{- block('form_widget_simple') -}} + {%- endif -%} +{%- endblock price_widget %} \ No newline at end of file diff --git a/src/Eccube/Resource/template/admin/Order/edit.twig b/src/Eccube/Resource/template/admin/Order/edit.twig index d70bfd3f4fb..bac71008cf7 100644 --- a/src/Eccube/Resource/template/admin/Order/edit.twig +++ b/src/Eccube/Resource/template/admin/Order/edit.twig @@ -85,7 +85,7 @@ file that was distributed with this source code. }); }); - // Trigger paging after append + // ページング処理 $(document).on('click', '#searchProductModalList ul.pagination li.page-item a.page-link', function(e) { e.preventDefault(); var list = $('#searchProductModalList'); @@ -104,7 +104,7 @@ file that was distributed with this source code. // 商品追加 $collectionHolder = $('#table-form-field'); - index = $collectionHolder.find('.input-price').length; + index = $collectionHolder.find('tbody > tr').length; $(document).on('click', '.delete', function(e) { // 商品削除 @@ -572,7 +572,6 @@ file that was distributed with this source code.
-
{# 複数配送の場合は商品追加できない #} @@ -640,28 +639,30 @@ file that was distributed with this source code. {% for orderItemForm in form.OrderItems %} + {% set OrderItem = orderItemForm.vars.data %} + {# hidden values #} + {{ form_widget(orderItemForm.ProductClass) }} + {{ form_widget(orderItemForm.order_item_type) }} - {{ form_widget(orderItemForm.Order) }}

- {% if orderItemForm.vars.value.OrderItemType.isProduct %} - {{ orderItemForm.vars.value.product_name }} - {{ form_widget(orderItemForm.product_name, {'attr': {'class': 'd-none'}}) }} + {% if OrderItem.OrderItemType.isProduct %} + {{ OrderItem.product_name }} + {{ form_widget(orderItemForm.product_name, { 'type': 'hidden' }) }} {% else %} {{ form_widget(orderItemForm.product_name) }} - {{ form_errors(orderItemForm.product_name) }} {% endif %}

- {{ orderItemForm.vars.value.product_code }} - {% if orderItemForm.vars.value.class_category_name1 is not empty %} + {{ OrderItem.product_code }} + {% if OrderItem.class_category_name1 is not empty %} / ( - {{ orderItemForm.vars.value.class_name1 }}: - {{ orderItemForm.vars.value.class_category_name1 }} - {% if orderItemForm.vars.value.class_category_name2 is not empty %} + {{ OrderItem.class_name1 }}: + {{ OrderItem.class_category_name1 }} + {% if OrderItem.class_category_name2 is not empty %} / - {{ orderItemForm.vars.value.class_name2 }}: - {{ orderItemForm.vars.value.class_category_name2 }} + {{ OrderItem.class_name2 }}: + {{ OrderItem.class_category_name2 }} {% endif %} ) {% endif %} @@ -669,16 +670,16 @@ file that was distributed with this source code. {{ form_errors(orderItemForm.product_name) }} -
- {{ form_widget(orderItemForm.price, {'attr': {'class': 'input-price'}}) }} +
+ {{ form_widget(orderItemForm.price, { 'tax_display_type': OrderItem.TaxDisplayType }) }} {{ form_errors(orderItemForm.price) }}
{# 複数配送の場合は商品の個数を変更できない #} - {% if Order.isMultiple and orderItemForm.vars.value.orderItemType.id == 1 %} - {{ orderItemForm.vars.value.quantity }} + {% if Order.isMultiple and OrderItem.orderItemType.id == 1 %} + {{ OrderItem.quantity }} {{ form_widget(orderItemForm.quantity, {'attr': {'class': 'd-none'}}) }} {{ form_errors(orderItemForm.quantity) }} {% else %} @@ -689,26 +690,23 @@ file that was distributed with this source code.
- {{ orderItemForm.vars.value.tax_rate }} - {{ form_widget(orderItemForm.tax_rate, {'attr': {'class': 'd-none'}}) }} - {{ form_errors(orderItemForm.tax_rate) }} + {{ OrderItem.tax_rate }}
- {{ orderItemForm.vars.value.tax_type }} + {{ OrderItem.tax_type }}
- {{ orderItemForm.vars.value.total_price|price }} - ({{ 'admin.common.label.taxinc'|trans }}) + {{ OrderItem.total_price|price }}
{# 複数配送の場合は商品を削除できない #} - {% if Order.isMultiple and orderItemForm.vars.value.orderItemType.id == 1 %} + {% if Order.isMultiple and OrderItem.orderItemType.id == 1 %} - {{ form_widget(orderItemForm.Order) }} - {{ form_widget(orderItemForm.Shipping) }} - {{ form_widget(orderItemForm.Product) }} - {{ form_widget(orderItemForm.ProductClass) }} - {{ form_widget(orderItemForm.product_name) }} - {{ form_widget(orderItemForm.product_code) }} - {{ form_widget(orderItemForm.class_name1) }} - {{ form_widget(orderItemForm.class_name2) }} - {{ form_widget(orderItemForm.class_category_name1) }} - {{ form_widget(orderItemForm.class_category_name2) }} - {{ form_widget(orderItemForm.tax_rule) }} - {{ form_widget(orderItemForm.tax_type) }} - {{ form_widget(orderItemForm.tax_display_type) }} - {{ form_widget(orderItemForm.order_item_type) }} {% endfor %}
- {# TODO 小計,内値引き,内送料,内手数料の金額が明細と合わない #} +
{{ 'admin.order.edit.276'|trans }}
{{ Order.subtotal|price }}
+
{{ 'admin.order.edit.277'|trans }}
-
- {{ Order.discount|price }}
+
{{ Order.discount|price }}
+
{{ 'admin.order.edit.279'|trans }}
{{ Order.delivery_fee_total|price }}
+
{{ 'admin.order.edit.280'|trans }}
{{ Order.charge|price }}
+
{{ 'admin.common.label.add_point'|trans }}
- - {{ form_widget(form.add_point) }} - {{ form_errors(form.add_point) }} - + + {{ form_widget(form.add_point) }} + {{ form_errors(form.add_point) }} +
+
{{ 'admin.common.label.use_point'|trans }}
- - {{ form_widget(form.use_point) }} - {{ form_errors(form.use_point) }} - + + {{ form_widget(form.use_point) }} + {{ form_errors(form.use_point) }} +

+
{{ 'admin.common.label.total'|trans }}
{{ Order.total|price }}
+
{{ 'admin.common.label.payment_total'|trans }}
{{ Order.payment_total|price }}
diff --git a/src/Eccube/Resource/template/admin/Order/order_item_prototype.twig b/src/Eccube/Resource/template/admin/Order/order_item_prototype.twig index 147a65b85b0..9d806c1d6e3 100644 --- a/src/Eccube/Resource/template/admin/Order/order_item_prototype.twig +++ b/src/Eccube/Resource/template/admin/Order/order_item_prototype.twig @@ -9,51 +9,12 @@ For the full copyright and license information, please view the LICENSE file that was distributed with this source code. #} - - -

-

+ + + {{ form_widget(orderItemForm.product_name) }} + {{ form_widget(orderItemForm.ProductClass) }} + {{ form_widget(orderItemForm.order_item_type) }} + {{ form_widget(orderItemForm.price) }} + {{ form_widget(orderItemForm.quantity) }} - -
- {{ form_widget(orderItemForm.price, {'attr': {'class': 'input-price'}}) }} - {{ form_errors(orderItemForm.price) }} -
- - -
- {{ form_widget(orderItemForm.quantity) }} - {{ form_errors(orderItemForm.quantity) }} -
- - -
- {{ form_widget(orderItemForm.tax_rate, {'attr': {'class': 'd-none'}}) }} - {{ form_errors(orderItemForm.tax_rate) }} -
- - -
-
- - -
- ({{ 'admin.common.label.taxinc'|trans }}) -
- - - {{ form_widget(orderItemForm.Order) }} - {{ form_widget(orderItemForm.Shipping) }} - {{ form_widget(orderItemForm.Product) }} - {{ form_widget(orderItemForm.ProductClass) }} - {{ form_widget(orderItemForm.product_name) }} - {{ form_widget(orderItemForm.product_code) }} - {{ form_widget(orderItemForm.class_name1) }} - {{ form_widget(orderItemForm.class_name2) }} - {{ form_widget(orderItemForm.class_category_name1) }} - {{ form_widget(orderItemForm.class_category_name2) }} - {{ form_widget(orderItemForm.tax_rule) }} - {{ form_widget(orderItemForm.tax_type) }} - {{ form_widget(orderItemForm.tax_display_type) }} - {{ form_widget(orderItemForm.order_item_type) }} diff --git a/src/Eccube/Resource/template/admin/Order/order_item_type.twig b/src/Eccube/Resource/template/admin/Order/order_item_type.twig index 9665ae6a5fa..5508c81f958 100644 --- a/src/Eccube/Resource/template/admin/Order/order_item_type.twig +++ b/src/Eccube/Resource/template/admin/Order/order_item_type.twig @@ -11,13 +11,6 @@ file that was distributed with this source code.