質問 > フロント機能 > 送料無料の条件 |
フロント機能
フラット表示 | 前のトピック | 次のトピック |
投稿者 | スレッド |
---|---|
susumu |
投稿日時: 2021/3/25 10:31
対応状況: −−−
|
一人前 登録日: 2018/12/17 居住地: 投稿: 104 |
Re: 送料無料の条件 ありがとうございます。
以前はこちら https://a-zumi.net/eccube4-no-free-shipping-pref/ を参考に <?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->setPrice(800); } } } } } } } } をCustomize/Service/PurchaseFlow/Processorディレクトリに設定しました。 404で書き換わったファイルを元のファイルに戻して同様のことをするとカートに入れた後エラーが出たのですが、今住所を沖縄にして実際に買い物をしてみたら、エラーにはなりませんでしたが税込11000円以上の買い物でも割引送料になりませんでした。 |
フラット表示 | 前のトピック | 次のトピック |
題名 | 投稿者 | 日時 |
---|---|---|
送料無料の条件 | susumu | 2021/3/23 12:00 |
Re: 送料無料の条件 | umebius | 2021/3/23 22:37 |
» Re: 送料無料の条件 | susumu | 2021/3/25 10:31 |
Re: 送料無料の条件 | balisys | 2023/11/13 18:26 |