src/Eccube/Service/PurchaseFlow/Processor/DeliverySettingValidator.php line 57

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Eccube\Service\PurchaseFlow\Processor;
  13. use Eccube\Entity\ItemInterface;
  14. use Eccube\Repository\DeliveryRepository;
  15. use Eccube\Service\PurchaseFlow\InvalidItemException;
  16. use Eccube\Service\PurchaseFlow\ItemValidator;
  17. use Eccube\Service\PurchaseFlow\PurchaseContext;
  18. /**
  19.  * 販売種別に配送業者が設定されているかどうか.
  20.  */
  21. class DeliverySettingValidator extends ItemValidator
  22. {
  23.     /**
  24.      * @var DeliveryRepository
  25.      */
  26.     protected $deliveryRepository;
  27.     /**
  28.      * DeliverySettingValidator constructor.
  29.      *
  30.      * @param DeliveryRepository $deliveryRepository
  31.      */
  32.     public function __construct(DeliveryRepository $deliveryRepository)
  33.     {
  34.         $this->deliveryRepository $deliveryRepository;
  35.     }
  36.     /**
  37.      * validate
  38.      *
  39.      * @param ItemInterface $item
  40.      * @param PurchaseContext $context
  41.      *
  42.      * @throws InvalidItemException
  43.      */
  44.     /**
  45.      * @param ItemInterface $item
  46.      * @param PurchaseContext $context
  47.      *
  48.      * @throws InvalidItemException
  49.      */
  50.     protected function validate(ItemInterface $itemPurchaseContext $context)
  51.     {
  52.         if (!$item->isProduct()) {
  53.             return;
  54.         }
  55.         $SaleType $item->getProductClass()->getSaleType();
  56.         $Deliveries $this->deliveryRepository->findBy(['SaleType' => $SaleType'visible' => true]);
  57.         if (empty($Deliveries)) {
  58.             $this->throwInvalidItemException('front.shopping.in_preparation'$item->getProductClass());
  59.         }
  60.     }
  61.     /**
  62.      * handle
  63.      *
  64.      * @param ItemInterface $item
  65.      * @param PurchaseContext $context
  66.      */
  67.     protected function handle(ItemInterface $itemPurchaseContext $context)
  68.     {
  69.         $item->setQuantity(0);
  70.     }
  71. }