Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

受注編集画面にポイント付与率を追加 #5571

Merged
merged 9 commits into from Sep 14, 2022
Merged
13 changes: 12 additions & 1 deletion src/Eccube/Form/Type/Admin/OrderItemType.php
Expand Up @@ -153,7 +153,18 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'message' => 'form_error.float_only',
]),
],
]);
])
->add('point_rate', HiddenType::class, [
'required' => false,
'constraints' => [
new Assert\Range(['min' => 0]),
new Assert\Regex([
'pattern' => "/^\d+(\.\d+)?$/u",
'message' => 'form_error.float_only',
]),
],
])
;

$builder
->add($builder->create('order_item_type', HiddenType::class)
Expand Down
1 change: 1 addition & 0 deletions src/Eccube/Resource/locale/messages.en.yaml
Expand Up @@ -824,6 +824,7 @@ admin.order.amount: Price
admin.order.quantity: Qty
admin.order.tax_rate: Tax
admin.order.tax_type: Tax Type
admin.order.point_rate: Point Rate
admin.order.subtotal: Subtotal
admin.order.discount: Discount
admin.order.delivery_fee: Shipping Charge
Expand Down
1 change: 1 addition & 0 deletions src/Eccube/Resource/locale/messages.ja.yaml
Expand Up @@ -824,6 +824,7 @@ admin.order.amount: 金額
admin.order.quantity: 数量
admin.order.tax_rate: 税率
admin.order.tax_type: 課税区分
admin.order.point_rate: ポイント付与率
admin.order.subtotal: 小計
admin.order.discount: 値引き
admin.order.delivery_fee: 送料
Expand Down
1 change: 1 addition & 0 deletions src/Eccube/Resource/template/admin/Order/edit.twig
Expand Up @@ -744,6 +744,7 @@ file that was distributed with this source code.
{# hidden values #}
{{ form_widget(orderItemForm.ProductClass) }}
{{ form_widget(orderItemForm.order_item_type) }}
{{ form_widget(orderItemForm.point_rate) }}
{{ form_widget(orderItemForm.tax_type) }}
<!-- 商品名 -->
<td class="align-middle w-25 ps-3">
Expand Down
Expand Up @@ -17,5 +17,6 @@ file that was distributed with this source code.
{{ form_widget(orderItemForm.price) }}
{{ form_widget(orderItemForm.quantity) }}
{{ form_widget(orderItemForm.tax_type) }}
{{ form_widget(orderItemForm.point_rate) }}
</td>
</tr>
7 changes: 7 additions & 0 deletions src/Eccube/Resource/template/admin/Order/order_item_type.twig
Expand Up @@ -11,6 +11,12 @@ file that was distributed with this source code.
<script>
// 受注明細行を追加する.
function fnAddOrderItem($row, product_id, type, product_name, tax_type) {
// 既存の受注明細のポイント付与率を取得する. 取得できない場合は店舗基本情報の付与率を設定する.
var point_rate = $('input[type=hidden][id$=point_rate]').first().val();
if (point_rate === undefined) {
point_rate = '{{ BaseInfo.basic_point_rate }}';
}

var prototype = $collectionHolder.data('prototype');
index++;
var newForm = prototype.replace(/__name__/g, index);
Expand All @@ -22,6 +28,7 @@ file that was distributed with this source code.
$($lastRow).find(formIdPrefix + index + '_order_item_type').val(type);
$($lastRow).find(formIdPrefix + index + '_product_name').val(product_name);
$($lastRow).find(formIdPrefix + index + '_tax_type').val(tax_type);
$($lastRow).find(formIdPrefix + index + '_point_rate').val(point_rate);

// モーダル閉じる.
$('#addOrderItemType').modal('hide');
Expand Down
7 changes: 7 additions & 0 deletions src/Eccube/Resource/template/admin/Order/search_product.twig
Expand Up @@ -86,6 +86,12 @@ file that was distributed with this source code.
}
}

// 既存の受注明細のポイント付与率を取得する. 取得できない場合は店舗基本情報の付与率を設定する.
var point_rate = $('input[type=hidden][id$=point_rate]').first().val();
if (point_rate === undefined) {
point_rate = '{{ BaseInfo.basic_point_rate }}';
}

var prototype = $collectionHolder.data('prototype');
index++;
var newForm = prototype.replace(/__name__/g, index);
Expand All @@ -97,6 +103,7 @@ file that was distributed with this source code.
$($lastRow).find(formIdPrefix + index + '_quantity').val(quantity);
$($lastRow).find(formIdPrefix + index + '_order_item_type').val(type);
$($lastRow).find(formIdPrefix + index + '_product_name').val(product_name);
$($lastRow).find(formIdPrefix + index + '_point_rate').val(point_rate);

// モーダル閉じる.
$('#searchProductModal').modal('hide');
Expand Down
1 change: 1 addition & 0 deletions src/Eccube/Resource/template/admin/Order/shipping.twig
Expand Up @@ -557,6 +557,7 @@ file that was distributed with this source code.
{# hidden values #}
{{ form_widget(orderItemForm.ProductClass) }}
{{ form_widget(orderItemForm.order_item_type) }}
{{ form_widget(orderItemForm.point_rate) }}
{{ form_widget(orderItemForm.tax_type) }}
{{ form_widget(orderItemForm.tax_rate, {'type': 'hidden'}) }}
<td class="align-middle w-25 ps-3">
Expand Down
11 changes: 11 additions & 0 deletions src/Eccube/Service/PointHelper.php
Expand Up @@ -122,9 +122,20 @@ public function addPointDiscountItem(ItemHolderInterface $itemHolder, $discount)
$TaxInclude = $this->entityManager->find(TaxDisplayType::class, TaxDisplayType::INCLUDED);
$Taxation = $this->entityManager->find(TaxType::class, TaxType::NON_TAXABLE);

// 商品明細に保持しているポイント付与率を取得して設定する.
// 商品明細が取得できない場合は店舗基本情報のポイント付与率を設定する.
$Baseinfo = $this->baseInfoRepository->get();
$pointRate = $Baseinfo->getBasicPointRate();
// 商品別ポイントは未実装なので, 商品明細のポイント付与率はすべて同じ値が設定されているはず
$ProductOrderItem = $itemHolder->getItems()->getProductClasses()->current();
if ($ProductOrderItem instanceof OrderItem && $ProductOrderItem->getPointRate() !== null) {
$pointRate = $ProductOrderItem->getPointRate();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nanasess
#5571 (comment) の通り、商品明細のポイント付与率がnullの場合もありうるので、商品明細の付与率 => 基本情報の付与率の順に判定したほうがよいかもしれません。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ProductOrderItem instanceof OrderItem && $ProductOrderItem->getPointRate() !== null という条件にしてみました

}

$OrderItem = new OrderItem();
$OrderItem->setProductName($DiscountType->getName())
->setPrice($discount)
->setPointRate($pointRate)
->setQuantity(1)
->setTax(0)
->setTaxRate(0)
Expand Down
Expand Up @@ -17,6 +17,7 @@
use Eccube\Entity\ItemHolderInterface;
use Eccube\Entity\ItemInterface;
use Eccube\Entity\Order;
use Eccube\Entity\OrderItem;
use Eccube\Repository\BaseInfoRepository;
use Eccube\Service\PurchaseFlow\ItemHolderPostValidator;
use Eccube\Service\PurchaseFlow\PurchaseContext;
Expand Down Expand Up @@ -70,7 +71,9 @@ private function calculateAddPoint(ItemHolderInterface $itemHolder)
// 明細ごとのポイントを集計
$totalPoint = array_reduce($itemHolder->getItems()->toArray(),
function ($carry, ItemInterface $item) use ($basicPointRate) {
$pointRate = $item->isProduct() ? $item->getProductClass()->getPointRate() : null;

$pointRate = $item->getPointRate() ? $item->getPointRate() : null;

if ($pointRate === null) {
$pointRate = $basicPointRate;
}
Expand Down