vendor/lm/engine-sample-limit/src/Catalog.php line 28

Open in your IDE?
  1. <?php
  2. namespace Lm\Engine\SampleLimit;
  3. use Lm\Entity\Cart\CartHeader;
  4. use Lm\Entity\OrderHeader;
  5. use Lm\Entity\CatalogLimit;
  6. class Catalog
  7. {
  8.     /**
  9.      * 判定結果: OK
  10.      */
  11.     const RESULT_OK 1;
  12.     /**
  13.      * 判定結果: NG - ほげ
  14.      */
  15.     const RESULT_NG 0;
  16.     /**
  17.      * @param CartHeader $cart
  18.      * @return int
  19.      */
  20.     public static function checkCart(CartHeader $cart)
  21.     {
  22.         if (!$cart->getCustomer()) {
  23.             return ['result' => self::RESULT_OK'message' => 'OK'];
  24.         }
  25.         $catalogLimit CatalogLimit::getInstanceByDevice($cart->getDevice() == OrderHeader::DEVICE_PC 'PC' 'SP');
  26.         if (self::getOrderCountAfterPurchase($cart) >= $catalogLimit->getClNoPurchaseLimit()) {
  27.             $errorMsg sprintf(CatalogLimit::ERROR_NO_PURCHASE_LIMIT$catalogLimit->getClNoPurchaseLimit());
  28.             return ['result' => self::RESULT_NG'message' => $errorMsg];
  29.         }
  30.         if ($catalogLimit->getClNoPurchaseLimit() == 0) {
  31.             return ['result' => self::RESULT_NG'message' => CatalogLimit::ERROR_ZERO_NUMBER_LIMIT];
  32.         }
  33.         if (self::getOrderCountOfToday($cart) >= $catalogLimit->getClNumberLimit()) {
  34.             $errorMsg sprintf(CatalogLimit::ERROR_NUMBER_LIMIT$catalogLimit->getClNumberLimit());
  35.             return ['result' => self::RESULT_NG'message' => $errorMsg];
  36.         }
  37.         return ['result' => self::RESULT_OK'message' => 'OK'];
  38.     }
  39.     /**
  40.      * @param CartHeader $cart
  41.      * @return int
  42.      */
  43.     protected static function getOrderCountOfToday(CartHeader $cart)
  44.     {
  45.         $customerId $cart->getCustomer()->getCustomerId();
  46.         return CatalogLimit::getOrderCountOfToday($customerId);
  47.     }
  48.     /**
  49.      * @param CartHeader $cart
  50.      * @return int
  51.      */
  52.     protected static function getOrderCountAfterPurchase(CartHeader $cart)
  53.     {
  54.         $customerId $cart->getCustomer()->getCustomerId();
  55.         return CatalogLimit::getOrderCountAfterPurchase($customerId);
  56.     }
  57. }