1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Eccubeで○○円以上送料無料にする処理

1
Posted at

app/Customize/Service/PurchaseFlow/Processor/CustomDeliveryFeePreprocessor.php というファイルを下記のように作成します。

CustomDeliveryFeePreprocessor.php
<?php

namespace Customize\Service\PurchaseFlow\Processor;

use Eccube\Service\PurchaseFlow\ItemHolderPreprocessor;
use Eccube\Entity\ItemHolderInterface;
use Eccube\Service\PurchaseFlow\PurchaseContext;
use Eccube\Repository\BaseInfoRepository;
use Eccube\Annotation\ShoppingFlow;

/**
 * Description of CustomDeliveryFeePreprocessor
 *
 * @ShoppingFlow
 */
class CustomDeliveryFeePreprocessor implements ItemHolderPreprocessor {

    /** @var BaseInfo */
    protected $BaseInfo;

    /**
     * DeliveryFeePreprocessor constructor.
     *
     * @param BaseInfoRepository $baseInfoRepository
     */
    public function __construct(
            BaseInfoRepository $baseInfoRepository,
    )
    {
        $this->BaseInfo = $baseInfoRepository->get();
    }

    public function process(ItemHolderInterface $itemHolder, PurchaseContext $context)
    {
        $this->updateDeliveryFeeItem($itemHolder);
    }

    /**
     * @param ItemHolderInterface $itemHolder
     */
    private function updateDeliveryFeeItem(ItemHolderInterface $itemHolder)
    {
        // 10,000円を超える場合は送料無料
        $totalPrice = 0.0;
        foreach ($Shipping->getOrderItems() as $item) {
            if (!$item->isDeliveryFee()) {
                $totalPrice = $totalPrice + $item->getTotalPrice();
            }
        }
        if ( $totalPrice >= 10000 ) {
            foreach ($Shipping->getOrderItems() as $item) {
                if ($item->isDeliveryFee()) {
                    $item->setPrice(0);
                }
            }
        }
    }

}

かんたんですね。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?