src/Eccube/Entity/CartItem.php line 28

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\Entity;
  13. use Doctrine\ORM\Mapping as ORM;
  14. if (!class_exists('\Eccube\Entity\CartItem')) {
  15.     /**
  16.      * CartItem
  17.      *
  18.      * @ORM\Table(name="dtb_cart_item")
  19.      * @ORM\InheritanceType("SINGLE_TABLE")
  20.      * @ORM\DiscriminatorColumn(name="discriminator_type", type="string", length=255)
  21.      * @ORM\HasLifecycleCallbacks()
  22.      * @ORM\Entity(repositoryClass="Eccube\Repository\CartItemRepository")
  23.      */
  24.     class CartItem extends \Eccube\Entity\AbstractEntity implements ItemInterface
  25.     {
  26.         use PointRateTrait;
  27.         /**
  28.          * @var integer
  29.          *
  30.          * @ORM\Column(name="id", type="integer", options={"unsigned":true})
  31.          * @ORM\Id
  32.          * @ORM\GeneratedValue(strategy="IDENTITY")
  33.          */
  34.         private $id;
  35.         /**
  36.          * @var string
  37.          *
  38.          * @ORM\Column(name="price", type="decimal", precision=12, scale=2, options={"default":0})
  39.          */
  40.         private $price 0;
  41.         /**
  42.          * @var string
  43.          *
  44.          * @ORM\Column(name="quantity", type="decimal", precision=10, scale=0, options={"default":0})
  45.          */
  46.         private $quantity 0;
  47.         /**
  48.          * @var \Eccube\Entity\ProductClass
  49.          *
  50.          * @ORM\ManyToOne(targetEntity="Eccube\Entity\ProductClass")
  51.          * @ORM\JoinColumns({
  52.          *   @ORM\JoinColumn(name="product_class_id", referencedColumnName="id")
  53.          * })
  54.          */
  55.         private $ProductClass;
  56.         /**
  57.          * @var \Eccube\Entity\Cart
  58.          *
  59.          * @ORM\ManyToOne(targetEntity="Eccube\Entity\Cart", inversedBy="CartItems", cascade={"persist"})
  60.          * @ORM\JoinColumns({
  61.          *   @ORM\JoinColumn(name="cart_id", referencedColumnName="id", onDelete="CASCADE")
  62.          * })
  63.          */
  64.         private $Cart;
  65.         /**
  66.          * sessionのシリアライズのために使われる
  67.          *
  68.          * @var int
  69.          */
  70.         private $product_class_id;
  71.         public function __sleep()
  72.         {
  73.             return ['product_class_id''price''quantity'];
  74.         }
  75.         /**
  76.          * @return int
  77.          */
  78.         public function getId()
  79.         {
  80.             return $this->id;
  81.         }
  82.         /**
  83.          * @param  integer  $price
  84.          *
  85.          * @return CartItem
  86.          */
  87.         public function setPrice($price)
  88.         {
  89.             $this->price $price;
  90.             return $this;
  91.         }
  92.         /**
  93.          * @return string
  94.          */
  95.         public function getPrice()
  96.         {
  97.             return $this->price;
  98.         }
  99.         /**
  100.          * @param  integer  $quantity
  101.          *
  102.          * @return CartItem
  103.          */
  104.         public function setQuantity($quantity)
  105.         {
  106.             $this->quantity $quantity;
  107.             return $this;
  108.         }
  109.         /**
  110.          * @return string
  111.          */
  112.         public function getQuantity()
  113.         {
  114.             return $this->quantity;
  115.         }
  116.         /**
  117.          * @return integer
  118.          */
  119.         public function getTotalPrice()
  120.         {
  121.             return $this->getPrice() * $this->getQuantity();
  122.         }
  123.         /**
  124.          * 商品明細かどうか.
  125.          *
  126.          * @return boolean 商品明細の場合 true
  127.          */
  128.         public function isProduct()
  129.         {
  130.             return true;
  131.         }
  132.         /**
  133.          * 送料明細かどうか.
  134.          *
  135.          * @return boolean 送料明細の場合 true
  136.          */
  137.         public function isDeliveryFee()
  138.         {
  139.             return false;
  140.         }
  141.         /**
  142.          * 手数料明細かどうか.
  143.          *
  144.          * @return boolean 手数料明細の場合 true
  145.          */
  146.         public function isCharge()
  147.         {
  148.             return false;
  149.         }
  150.         /**
  151.          * 値引き明細かどうか.
  152.          *
  153.          * @return boolean 値引き明細の場合 true
  154.          */
  155.         public function isDiscount()
  156.         {
  157.             return false;
  158.         }
  159.         /**
  160.          * 税額明細かどうか.
  161.          *
  162.          * @return boolean 税額明細の場合 true
  163.          */
  164.         public function isTax()
  165.         {
  166.             return false;
  167.         }
  168.         /**
  169.          * ポイント明細かどうか.
  170.          *
  171.          * @return boolean ポイント明細の場合 true
  172.          */
  173.         public function isPoint()
  174.         {
  175.             return false;
  176.         }
  177.         public function getOrderItemType()
  178.         {
  179.             // TODO OrderItemType::PRODUCT
  180.             $ItemType = new \Eccube\Entity\Master\OrderItemType();
  181.             return $ItemType;
  182.         }
  183.         /**
  184.          * @param ProductClass $ProductClass
  185.          *
  186.          * @return $this
  187.          */
  188.         public function setProductClass(ProductClass $ProductClass)
  189.         {
  190.             $this->ProductClass $ProductClass;
  191.             $this->product_class_id is_object($ProductClass) ?
  192.             $ProductClass->getId() : null;
  193.             return $this;
  194.         }
  195.         /**
  196.          * @return ProductClass
  197.          */
  198.         public function getProductClass()
  199.         {
  200.             return $this->ProductClass;
  201.         }
  202.         /**
  203.          * @return int|null
  204.          */
  205.         public function getProductClassId()
  206.         {
  207.             return $this->product_class_id;
  208.         }
  209.         public function getPriceIncTax()
  210.         {
  211.             // TODO ItemInterfaceに追加, Cart::priceは税込み金額が入っているので,フィールドを分ける必要がある
  212.             return $this->price;
  213.         }
  214.         /**
  215.          * @return Cart
  216.          */
  217.         public function getCart()
  218.         {
  219.             return $this->Cart;
  220.         }
  221.         /**
  222.          * @param Cart $Cart
  223.          */
  224.         public function setCart(Cart $Cart)
  225.         {
  226.             $this->Cart $Cart;
  227.             return $this;
  228.         }
  229.     }
  230. }