vendor/lm/engine-ec/src/Entity/SkuWithPrice.php line 60

Open in your IDE?
  1. <?php
  2. namespace Lm\Engine\EC\Entity;
  3. use Lm\Engine\SokujitsuHassou\SokujitsuHassou;
  4. use Lm\Engine\Tax\TaxRule;
  5. use Lm\Engine\Zaiko\Entity\SkuExtended;
  6. use Lm\Service\Cache\CacheService;
  7. class SkuWithPrice extends SkuExtended
  8. {
  9.     /**
  10.      * @var int キャンペーン価格(税込)
  11.      */
  12.     protected $cpPriceInTax;
  13.     /**
  14.      * @var int 通常価格(税抜)
  15.      */
  16.     protected $gpPriceExTax;
  17.     /**
  18.      * @var int 定価(税込)
  19.      */
  20.     protected $gpTeikaInTax;
  21.     /**
  22.      * @var int 売価(税抜)
  23.      */
  24.     protected $priceExTax;
  25.     /**
  26.      * @var int 売価(税込)
  27.      */
  28.     protected $priceInTax;
  29.     /**
  30.      * @var int 希望小売価格(税込)
  31.      */
  32.     protected $teikaInTax;
  33.     /**
  34.      * @var int 希望小売価格(税抜)
  35.      */
  36.     protected $teikaExTax;
  37.     /**
  38.      * @var bool 即日発送可否
  39.      */
  40.     protected $isSokujitsuHassouAvailable;
  41.     /**
  42.      * キャンペーン価格(税込)
  43.      *
  44.      * @return int|null
  45.      */
  46.     public function getCpPriceInTax()
  47.     {
  48.         return self::intNullable($this->cpPriceInTax);
  49.     }
  50.     /**
  51.      * 通常価格(税抜)
  52.      *
  53.      * @return int|null
  54.      */
  55.     public function getGpPriceExTax()
  56.     {
  57.         return self::intNullable($this->gpPriceExTax);
  58.     }
  59.     /**
  60.      * 定価(税込)
  61.      *
  62.      * @return int|null
  63.      */
  64.     public function getGpTeikaInTax()
  65.     {
  66.         return self::intNullable($this->gpTeikaInTax);
  67.     }
  68.     /**
  69.      * 売価(税込)
  70.      *
  71.      * @return int
  72.      */
  73.     public function getPriceInTax($datetime null)
  74.     {
  75.         return self::compute($this->priceInTax, function () use ($datetime) {
  76.             //
  77.             if ($priceInTax $this->getCpPriceInTax()) {
  78.                 //
  79.                 return $priceInTax;
  80.             } else if ($priceExTax $this->getGpPriceExTax()) {
  81.                 //
  82.                 return TaxRule::toInTax($priceExTax$datetime);
  83.             } else {
  84.                 //
  85.                 throw new \Exception('価格が取得出来ませんでした');
  86.             }
  87.         });
  88.     }
  89.     /**
  90.      * 売価(税抜)
  91.      *
  92.      * @return int
  93.      */
  94.     public function getPriceExTax($datetime null)
  95.     {
  96.         return self::compute($this->priceExTax, function () use ($datetime) {
  97.             //
  98.             if ($priceInTax $this->getCpPriceInTax()) {
  99.                 //
  100.                 return TaxRule::toExTax($priceInTax);
  101.             } else if ($priceExTax $this->getGpPriceExTax()) {
  102.                 //
  103.                 return $priceExTax;
  104.             } else {
  105.                 //
  106.                 throw new \Exception('価格が取得出来ませんでした');
  107.             }
  108.         });
  109.     }
  110.     /**
  111.      * 希望小売価格(税込)
  112.      *
  113.      * @return int
  114.      */
  115.     public function getTeikaInTax($datetime null)
  116.     {
  117.         return self::compute($this->teikaInTax, function () use ($datetime) {
  118.             //
  119.             $teikaInTax $this->getGpTeikaInTax();
  120.             //
  121.             return $teikaInTax;
  122.         });
  123.     }
  124.     /**
  125.      * 希望小売価格(税抜)
  126.      *
  127.      * @return int
  128.      */
  129.     public function getTeikaExTax($datetime null)
  130.     {
  131.         return self::compute($this->teikaExTax, function () use ($datetime) {
  132.             //
  133.             $teikaInTax $this->getGpTeikaInTax();
  134.             //
  135.             return TaxRule::toExTax($teikaInTax$datetime);
  136.         });
  137.     }
  138.     /**
  139.      * @return bool
  140.      * @throws \Exception
  141.      */
  142.     public function isSokujitsuHassouAvailable()
  143.     {
  144.         return self::compute($this->isSokujitsuHassouAvailable, function () {
  145.             //
  146.             return self::retrieveSokujitauHassouFlgByIdentifiers($this->getGoodsId(), $this->getGclId(), $this->getGpId());
  147.         });
  148.     }
  149.     /**
  150.      * @param $goodsId
  151.      * @param $janId
  152.      * @param $gclId
  153.      * @param $gpId
  154.      * @param $datetime
  155.      * @return SkuWithPrice[]
  156.      * @throws \Exception
  157.      */
  158.     public static function getInstanceList($goodsId$janId null$gclId null$gpId null$datetime null)
  159.     {
  160.         //
  161.         $result = [];
  162.         //
  163.         $skuList SkuExtended::getInstanceList($goodsId$janId$gclId$gpId$datetime);
  164.         //
  165.         foreach ($skuList as $sku) {
  166.             //
  167.             $result[] = SkuWithPrice::factory($sku);
  168.         }
  169.         //
  170.         return $result;
  171.     }
  172.     /**
  173.      * @param $goodsId
  174.      * @param $janId
  175.      * @param $gclId
  176.      * @param $gpId
  177.      * @param $datetime
  178.      * @return SkuWithPrice
  179.      * @throws \Exception
  180.      */
  181.     public static function getInstance($goodsId$janId null$gclId null$gpId null$datetime null)
  182.     {
  183.         //
  184.         $sku SkuWithPrice::factory(SkuExtended::getInstance($goodsId$janId$gclId$gpId$datetime));
  185.         //
  186.         return $sku;
  187.     }
  188.     /**
  189.      * @param int $goodsId
  190.      * @param int $gclId
  191.      * @param int $gpId
  192.      * @return bool
  193.      * @throws \Exception
  194.      */
  195.     protected static function retrieveSokujitauHassouFlgByIdentifiers($goodsId$gclId$gpId)
  196.     {
  197.         //
  198.         $sokujitsuHassouFlgCache CacheService::getCached(function () use ($goodsId) {
  199.             //
  200.             return (new SokujitsuHassou())
  201.                 ->check($goodsIdtrue)
  202.             ;
  203.         });
  204.         //
  205.         if (!empty($sokujitsuHassouFlgCache) && isset($sokujitsuHassouFlgCache[$gclId]) && isset($sokujitsuHassouFlgCache[$gclId][$gpId])) {
  206.             //
  207.             return $sokujitsuHassouFlgCache[$gclId][$gpId] > SokujitsuHassou::FLG_NONE;
  208.         } else {
  209.             //
  210.             return false;
  211.         }
  212.     }
  213. }