Skip to content

Commit

Permalink
Merge pull request #2343 from nanasess/fix-calcstrategy
Browse files Browse the repository at this point in the history
明細の集計方法を修正
  • Loading branch information
chihiro-adachi authored May 29, 2017
2 parents fdfb667 + bfa7a8d commit e275172
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 9 deletions.
2 changes: 0 additions & 2 deletions src/Eccube/Controller/Admin/Order/EditController.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ public function index(Application $app, Request $request, $id = null)
$ShipmentItem->setOrder($TargetOrder);
}

// TODO 手数料, 値引きの集計は CalculateService で
$TargetOrder->setDeliveryFeeTotal($TargetOrder->calculateDeliveryFeeTotal()); // FIXME
$app['orm.em']->persist($TargetOrder);
$app['orm.em']->flush();

Expand Down
38 changes: 37 additions & 1 deletion src/Eccube/Entity/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,43 @@ function($ShipmentItem) {
return $ShipmentItem->isDeliveryFee();
}),
function($total, $ShipmentItem) {
return $total + $ShipmentItem->getPriceIncTax();
return $total + $ShipmentItem->getPriceIncTax() * $ShipmentItem->getQuantity();
}, 0);
}

/**
* この注文にかかる値引きの合計を返す.
*
* @return integer
*/
public function calculateDiscountTotal()
{
// TODO filter を外出ししたい
return array_reduce(
array_filter($this->getShipmentItems()->toArray(),
function($ShipmentItem) {
return $ShipmentItem->isDiscount();
}),
function($total, $ShipmentItem) {
return $total + $ShipmentItem->getPriceIncTax() * $ShipmentItem->getQuantity();
}, 0);
}

/**
* この注文にかかる手数料の合計を返す.
*
* @return integer
*/
public function calculateChargeTotal()
{
// TODO filter を外出ししたい
return array_reduce(
array_filter($this->getShipmentItems()->toArray(),
function($ShipmentItem) {
return $ShipmentItem->isCharge();
}),
function($total, $ShipmentItem) {
return $total + $ShipmentItem->getPriceIncTax() * $ShipmentItem->getQuantity();
}, 0);
}

Expand Down
8 changes: 8 additions & 0 deletions src/Eccube/Form/Type/Admin/OrderType.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,14 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$Order->setPaymentMethod($Payment->getMethod());
}
});
// TODO 手数料, 値引きの集計は CalculateService で
$builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
$Order = $event->getData();
$Order->setDiscount($Order->calculateDiscountTotal());
$Order->setCharge($Order->calculateChargeTotal());
$Order->setDeliveryFeeTotal($Order->calculateDeliveryFeeTotal());
$event->setData($Order);
});
// 会員受注の場合、会員の性別/職業/誕生日をエンティティにコピーする
$builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
$Order = $event->getData();
Expand Down
20 changes: 20 additions & 0 deletions src/Eccube/Form/Type/Admin/ShipmentItemType.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,26 @@ public function buildForm(FormBuilderInterface $builder, array $options)
)));

$app = $this->app;
// XXX price を priceIncTax にセットし直す
// どこか一箇所にまとめたい
$builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use ($app) {
/** @var \Eccube\Entity\ShipmentItem $ShipmentItem */
$ShipmentItem = $event->getData();
$TaxDisplayType = $ShipmentItem->getTaxDisplayType();
switch ($TaxDisplayType->getId()) {
// 税込価格
case TaxDisplayType::INCLUDED:
$ShipmentItem->setPriceIncTax($ShipmentItem->getPrice());
break;
// 税別価格の場合は税額を加算する
case TaxDisplayType::EXCLUDED:
// TODO 課税規則を考慮する
$ShipmentItem->setPriceIncTax($ShipmentItem->getPrice() + $ShipmentItem->getPrice() * $ShipmentItem->getTaxRate() / 100);
break;
}

$event->setData($ShipmentItem);
});
$builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) use ($app) {
// モーダルからのPOST時に、金額等をセットする.
if ('modal' === $app['request_stack']->getCurrentRequest()->get('modal')) {
Expand Down
9 changes: 3 additions & 6 deletions src/Eccube/Resource/template/admin/Order/edit.twig
Original file line number Diff line number Diff line change
Expand Up @@ -472,18 +472,15 @@ var setModeAndSubmit = function(mode, keyname, keyid) {
<dd>{{ Order.subtotal|price }}</dd>
<dt id="product_info_result_box__discount">内値引き:</dt>
<dd class="form-group form-inline">
{{ form_widget(form.discount) }}
{{ form_errors(form.discount) }}
▲{{ Order.discount|price }}
</dd>
<dt id="product_info_result_box__delivery_fee_total">内送料:</dt>
<dd class="form-group form-inline">
{{ form_widget(form.delivery_fee_total) }}
{{ form_errors(form.delivery_fee_total) }}
{{ Order.delivery_fee_total|price }}
</dd>
<dt id="product_info_result_box__charge">内手数料:</dt>
<dd class="form-group form-inline">
{{ form_widget(form.charge) }}
{{ form_errors(form.charge) }}
{{ Order.charge|price }}
</dd>
</dl>
</div>
Expand Down

0 comments on commit e275172

Please sign in to comment.