EC-CUBE4で特定の都道府県のみ送料無料条件の適用を外す方法です。
以下のDeliveryFeeFreeByShippingPreprocessor.phpをCustomize/Service/PurchaseFlow/Processorディレクトリに設定して下さい。
<?php /* * Copyright (C) 2019 Akira Kurozumi <info@a-zumi.net>. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301 USA */ namespace Customize\Service\PurchaseFlow\Processor; use Eccube\Annotation\ShoppingFlow; use Eccube\Entity\BaseInfo; use Eccube\Entity\ItemHolderInterface; use Eccube\Entity\Order; use Eccube\Repository\BaseInfoRepository; use Eccube\Repository\Master\PrefRepository; use Eccube\Service\PurchaseFlow\ItemHolderPreprocessor; use Eccube\Service\PurchaseFlow\Processor\DeliveryFeePreprocessor; use Eccube\Service\PurchaseFlow\PurchaseContext; /** * 送料無料条件を適用する. * お届け先ごとに条件判定を行う. * * @ShoppingFlow() */ class DeliveryFeeFreeByShippingPreprocessor implements ItemHolderPreprocessor { /** * @var BaseInfo */ protected $BaseInfo; /** * @var PrefRepository */ private $prefRepository; public function __construct( BaseInfoRepository $baseInfoRepository, PrefRepository $prefRepository ) { $this->BaseInfo = $baseInfoRepository->get(); $this->prefRepository = $prefRepository; } /** * @param ItemHolderInterface $itemHolder * @param PurchaseContext $context */ public function process(ItemHolderInterface $itemHolder, PurchaseContext $context) { if (!($this->BaseInfo->getDeliveryFreeAmount() || $this->BaseInfo->getDeliveryFreeQuantity())) { return; } // Orderの場合はお届け先ごとに判定する. if ($itemHolder instanceof Order) { // 送料無料条件適用を除外する都道府県を指定 $noFreePref = '沖縄県'; /** @var Order $Order */ $Order = $itemHolder; foreach ($Order->getShippings() as $Shipping) { $isFree = false; $total = 0; $quantity = 0; foreach ($Shipping->getProductOrderItems() as $Item) { $total += $Item->getPriceIncTax() * $Item->getQuantity(); $quantity += $Item->getQuantity(); } // 送料無料(金額)を超えている if ($this->BaseInfo->getDeliveryFreeAmount()) { if ($total >= $this->BaseInfo->getDeliveryFreeAmount()) { $isFree = true; } } // 送料無料(個数)を超えている if ($this->BaseInfo->getDeliveryFreeQuantity()) { if ($quantity >= $this->BaseInfo->getDeliveryFreeQuantity()) { $isFree = true; } } if ($isFree) { foreach ($Shipping->getOrderItems() as $Item) { if ($Item->getProcessorName() == DeliveryFeePreprocessor::class) { // 送料無料条件適用を除外する都道府県とマッチしたら送料明細の数量を1とする if ($Shipping->getPref() == $this->prefRepository->findOneBy(['name' => $noFreePref])) { $Item->setQuantity(1); // 都道府県別送料設定で設定した送料と別の送料にしたい場合はこちらを追加 // $Item->getPrice(500); } } } } } } } }
投稿 EC-CUBE4で特定の都道府県のみ送料無料条件の適用を外す方法 は あずみ.net に最初に表示されました。