app/Plugin/QuantityDiscountDx/Service/PurchaseFlow/Processor/QuantityDiscountPreprocessor.php line 85

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright(c) 2019 SYSTEM_KD
  4.  * Date: 2019/03/23
  5.  */
  6. namespace Plugin\QuantityDiscountDx\Service\PurchaseFlow\Processor;
  7. use Eccube\Annotation\CartFlow;
  8. use Eccube\Annotation\ShoppingFlow;
  9. use Eccube\Entity\ItemInterface;
  10. use Eccube\Entity\OrderItem;
  11. use Eccube\Entity\CartItem//20240919@hanari
  12. use Eccube\Service\PurchaseFlow\ItemPreprocessor;
  13. use Eccube\Service\PurchaseFlow\PurchaseContext;
  14. use Plugin\QuantityDiscountDx\Service\ConfigService;
  15. use Plugin\QuantityDiscountDx\Service\QuantityDiscountService;
  16. /**
  17.  * @CartFlow
  18.  * @ShoppingFlow
  19.  *
  20.  * Class QuantityDiscountPreprocessor
  21.  * @package Plugin\QuantityDiscountDx\Service\PurchaseFlow\Processor
  22.  */
  23. class QuantityDiscountPreprocessor implements ItemPreprocessor
  24. {
  25.     /** @var QuantityDiscountService */
  26.     protected $quantityDiscountService;
  27.     /** @var ConfigService  */
  28.     protected $configService;
  29.     public function __construct(
  30.         QuantityDiscountService $quantityDiscountService,
  31.         ConfigService $configService
  32.     )
  33.     {
  34.         $this->quantityDiscountService $quantityDiscountService;
  35.         $this->configService $configService;
  36.     }
  37.     /**
  38.      * 受注データ調整処理。
  39.      *
  40.      * @param ItemInterface $item
  41.      * @param PurchaseContext $context
  42.      */
  43.     public function process(ItemInterface $itemPurchaseContext $context)
  44.     {
  45.         if (!$item->isProduct()) {
  46.             return;
  47.         }
  48.         if ($item instanceof OrderItem) {
  49.             // OrderItem
  50.             $incTax false;
  51.             if (ConfigService::DISCOUNT_BEFORE_PRICE
  52.                 == $this->configService->getKeyInteger(ConfigService::SETTING_KEY_DELIVERY_FEE_MODE)) {
  53.                 return;
  54.             }
  55.         } else {
  56.             // CartItem
  57.             $incTax true;
  58.         }
  59.         //20240915@hanari 
  60.         dump('オプション情報処理');
  61.         if($this->quantityDiscountService->isDiscount($item)){
  62.             // 直接値引
  63.             dump('直接値引',$incTax);
  64.             if($incTax) {
  65.                 $discountPrice $this->quantityDiscountService->getProductClassPriceIncTax($item);
  66.             } else {
  67.                 $discountPrice $this->quantityDiscountService->getProductClassPrice($item);
  68.             }
  69.         }else{
  70.             //値引き前に戻す
  71.             //通常価格の取得
  72.             $discountPrice $item->getProductClass()->getPrice02IncTax();
  73.         }
  74.         dump('オプション追加前',$discountPrice);
  75.         
  76.         // オプション価格の追加 20240915@hanari
  77.         if(method_exists($item,'getCartItemOptions') && is_array$item->getCartItemOptions() )){
  78.             dump($item);
  79.             $CartItemOptions $item->getCartItemOptions();
  80.             $OptionPrice 0;
  81.             $OptionTax 0;
  82.             //$DeliveryDaysMax = 0;
  83.             foreach($CartItemOptions as $CartItemOption){
  84.                 //dump($CartItemOption->getOptionPrice());
  85.                 //dump($CartItemOption->getOptionTax());
  86.                 /*
  87.                 if($DeliveryDaysMax < $CartItemOption->getOptionDeliveryDays()){
  88.                     $DeliveryDaysMax = intval($CartItemOption->getOptionDeliveryDays());
  89.                 }
  90.                 */
  91.                 //dump($DeliveryDaysMax);
  92.                 $OptionPrice += $CartItemOption->getOptionPrice();
  93.                 $OptionTax += $CartItemOption->getOptionTax();
  94.             }
  95.             /*
  96.             if($DeliveryDaysMax > $item->getProductClass()->getDeliveryDateDays()){
  97.                 $item->getProductClass()->setDeliveryDateDays($DeliveryDaysMax);
  98.             }
  99.             */
  100.             dump($item);
  101.             //オプション分を追加
  102.             $discountPrice += $OptionPrice $OptionTax;
  103.         }
  104.         
  105.         if($item instanceof OrderItem){
  106.             $discountPrice $item->getPrice();
  107.         }
  108.         
  109.         dump('オプション追加後',$discountPrice);
  110.         if ($discountPrice 0) {
  111.             return;
  112.         }
  113.         $item->setPrice($discountPrice);
  114.     }
  115. }