Skip to content

Commit

Permalink
Order から Payment の外部参照をはずしてみる
Browse files Browse the repository at this point in the history
  • Loading branch information
nanasess committed Sep 14, 2017
1 parent c2f76c2 commit d3f583f
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 8 deletions.
35 changes: 30 additions & 5 deletions src/Eccube/Entity/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -562,13 +562,14 @@ public function getTotalPrice() {
*/
private $Job;

/**
* @var integer
* @ORM\Column(name="payment_id", type="integer", options={"unsigned":true}, nullable=true)
*/
private $payment_id;

/**
* @var \Eccube\Entity\Payment
*
* @ORM\ManyToOne(targetEntity="Eccube\Entity\Payment")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="payment_id", referencedColumnName="payment_id")
* })
*/
private $Payment;

Expand Down Expand Up @@ -1914,4 +1915,28 @@ public function getQuantity()

return $quantity;
}

/**
* Set paymentId
*
* @param integer $paymentId
*
* @return Order
*/
public function setPaymentId($paymentId)
{
$this->payment_id = $paymentId;

return $this;
}

/**
* Get paymentId
*
* @return integer
*/
public function getPaymentId()
{
return $this->payment_id;
}
}
3 changes: 2 additions & 1 deletion src/Eccube/Form/Type/Admin/OrderType.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Eccube\Annotation\Inject;
use Eccube\Application;
use Eccube\Entity\BaseInfo;
use Eccube\Entity\Payment;
use Eccube\Common\Constant;
use Eccube\Form\DataTransformer;
use Eccube\Form\Type\AddressType;
Expand Down Expand Up @@ -338,7 +339,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
// 選択された支払い方法の名称をエンティティにコピーする
$builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
$Order = $event->getData();
$Payment = $Order->getPayment();
$Payment = $this->entityManager->find(Payment::class, $Order->getPaymentId());
if (!is_null($Payment)) {
$Order->setPaymentMethod($Payment->getMethod());
}
Expand Down
5 changes: 5 additions & 0 deletions src/Eccube/Form/Type/Shopping/OrderType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Eccube\Annotation\Inject;
use Eccube\Application;
use Eccube\Entity\Order;
use Eccube\Entity\Payment;
use Eccube\Entity\ShipmentItem;
use Eccube\Repository\DeliveryRepository;
use Eccube\Repository\OrderRepository;
Expand Down Expand Up @@ -145,8 +146,12 @@ function (FormEvent $event) {
function (FormEvent $event) {
/** @var Order $Order */
$Order = $event->getData();
// $Payment = $this->paymentRepository->find($Order->getPaymentId());
$Payment = $Order->getPayment();
$Order->setPaymentId($Order->getPayment()->getId());
$Order->setPaymentMethod($Payment ? $Payment->getMethod() : null);
// $form = ['Payment' => $Payment];
// $event->setData($form);
// TODO CalculateChargeStrategy でセットする
// $Order->setCharge($Payment ? $Payment->getCharge() : null);
}
Expand Down
1 change: 1 addition & 0 deletions src/Eccube/Service/OrderHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ public function setDefaultPayment(Order $Order)

// 初期の支払い方法を設定.
$Payment = current($Payments);
$Order->setPaymentId($Payment->getId());
$Order->setPayment($Payment);
$Order->setPaymentMethod($Payment->getMethod());
// TODO CalculateChargeStrategy でセットする
Expand Down
12 changes: 12 additions & 0 deletions src/Eccube/Service/ShoppingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,18 @@ public function getOrder($status = null)
}

$Order = $this->orderRepository->findOneBy($condition);
// WITH で join すると[0 => Order, 1 => Payment] になってしまうからイケてない
// $qb = $this->orderRepository->getQueryBuilderBySearchData([]);
// $qb->select('o, p');
// $qb->leftJoin('\Eccube\Entity\Payment', 'p', 'WITH', 'o.payment_id = p.id');
// $qb->andWhere('o.pre_order_id = :pre_order_id')
// ->setParameter('pre_order_id', $preOrderId);
// $Orders = $qb->getQuery()->getResult();
// dump($Orders);

// OrderRepository でこれをやるか?
$Payment = $this->paymentRepository->find($Order->getPaymentId());
$Order->setPayment($Payment);

return $Order;

Expand Down
5 changes: 3 additions & 2 deletions tests/Eccube/Tests/Fixture/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,13 +430,14 @@ public function createOrder(Customer $Customer, array $ProductClasses = array(),
$statusType = 'order_processing';
}
$OrderStatus = $this->app['eccube.repository.order_status']->find($this->app['config'][$statusType]);
$Payment = $Payments[$faker->numberBetween(0, count($Payments) - 1)];
$Order = new Order($OrderStatus);
$Order->setCustomer($Customer);
$Order->copyProperties($Customer);
$Order
->setPref($Pref)
->setPayment($Payments[$faker->numberBetween(0, count($Payments) - 1)])
->setPaymentMethod($Order->getPayment()->getMethod())
->setPaymentId($Payment->getId())
->setPaymentMethod($Payment->getMethod())
->setMessage($faker->text())
->setNote($faker->text());
$this->app['orm.em']->persist($Order);
Expand Down

0 comments on commit d3f583f

Please sign in to comment.