src/Eccube/Entity/Cart.php line 21

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\Common\Collections\ArrayCollection;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use Eccube\Service\PurchaseFlow\InvalidItemException;
  16. use Eccube\Service\PurchaseFlow\ItemCollection;
  17. if (!class_exists('\Eccube\Entity\Cart')) {
  18.     /**
  19.      * Cart
  20.      *
  21.      * @ORM\Table(name="dtb_cart", indexes={
  22.      *     @ORM\Index(name="dtb_cart_update_date_idx", columns={"update_date"})
  23.      *  },
  24.      *  uniqueConstraints={
  25.      *     @ORM\UniqueConstraint(name="dtb_cart_pre_order_id_idx", columns={"pre_order_id"})
  26.      *  }))
  27.      * @ORM\InheritanceType("SINGLE_TABLE")
  28.      * @ORM\DiscriminatorColumn(name="discriminator_type", type="string", length=255)
  29.      * @ORM\HasLifecycleCallbacks()
  30.      * @ORM\Entity(repositoryClass="Eccube\Repository\CartRepository")
  31.      */
  32.     class Cart extends AbstractEntity implements PurchaseInterfaceItemHolderInterface
  33.     {
  34.         use PointTrait;
  35.         /**
  36.          * @var integer
  37.          *
  38.          * @ORM\Column(name="id", type="integer", options={"unsigned":true})
  39.          * @ORM\Id
  40.          * @ORM\GeneratedValue(strategy="IDENTITY")
  41.          */
  42.         private $id;
  43.         /**
  44.          * @var string
  45.          *
  46.          * @ORM\Column(name="cart_key", type="string", nullable=true)
  47.          */
  48.         private $cart_key;
  49.         /**
  50.          * @var \Eccube\Entity\Customer
  51.          *
  52.          * @ORM\ManyToOne(targetEntity="Eccube\Entity\Customer")
  53.          * @ORM\JoinColumns({
  54.          *   @ORM\JoinColumn(name="customer_id", referencedColumnName="id")
  55.          * })
  56.          */
  57.         private $Customer;
  58.         /**
  59.          * @var bool
  60.          */
  61.         private $lock false;
  62.         /**
  63.          * @var \Doctrine\Common\Collections\Collection|CartItem[]
  64.          *
  65.          * @ORM\OneToMany(targetEntity="Eccube\Entity\CartItem", mappedBy="Cart", cascade={"persist"})
  66.          * @ORM\OrderBy({"id" = "ASC"})
  67.          */
  68.         private $CartItems;
  69.         /**
  70.          * @var string|null
  71.          *
  72.          * @ORM\Column(name="pre_order_id", type="string", length=255, nullable=true)
  73.          */
  74.         private $pre_order_id null;
  75.         /**
  76.          * @var string
  77.          *
  78.          * @ORM\Column(name="total_price", type="decimal", precision=12, scale=2, options={"unsigned":true,"default":0})
  79.          */
  80.         private $total_price;
  81.         /**
  82.          * @var string
  83.          *
  84.          * @ORM\Column(name="delivery_fee_total", type="decimal", precision=12, scale=2, options={"unsigned":true,"default":0})
  85.          */
  86.         private $delivery_fee_total;
  87.         /**
  88.          * @var int|null
  89.          *
  90.          * @ORM\Column(name="sort_no", type="smallint", nullable=true, options={"unsigned":true})
  91.          */
  92.         private $sort_no;
  93.         /**
  94.          * @var \DateTime
  95.          *
  96.          * @ORM\Column(name="create_date", type="datetimetz")
  97.          */
  98.         private $create_date;
  99.         /**
  100.          * @var \DateTime
  101.          *
  102.          * @ORM\Column(name="update_date", type="datetimetz")
  103.          */
  104.         private $update_date;
  105.         /**
  106.          * @var integer
  107.          *
  108.          * @ORM\Column(name="buyflg", type="integer")
  109.          */
  110.         private $buyflg;
  111.         /**
  112.          * @var InvalidItemException[]
  113.          */
  114.         private $errors = [];
  115.         public function __wakeup()
  116.         {
  117.             $this->errors = [];
  118.         }
  119.         public function __construct()
  120.         {
  121.             $this->CartItems = new ArrayCollection();
  122.         }
  123.         /**
  124.          * @return int
  125.          */
  126.         public function getId()
  127.         {
  128.             return $this->id;
  129.         }
  130.         /**
  131.          * @return string
  132.          */
  133.         public function getCartKey()
  134.         {
  135.             return $this->cart_key;
  136.         }
  137.         /**
  138.          * @param string $cartKey
  139.          */
  140.         public function setCartKey(string $cartKey)
  141.         {
  142.             $this->cart_key $cartKey;
  143.             return $this;
  144.         }
  145.         /**
  146.          * @return integer
  147.          * 
  148.          */
  149.         public function getBuyflg()
  150.         {
  151.             return $this->buyflg;
  152.         }
  153.         /**
  154.          * @param integer $buyflg
  155.          * 
  156.          */
  157.         public function setBuyflg($buyflg)
  158.         {
  159.             $this->buyflg $buyflg;
  160.             return $this;
  161.         }
  162.         /**
  163.          * @return bool
  164.          *
  165.          * @deprecated 使用しないので削除予定
  166.          */
  167.         public function getLock()
  168.         {
  169.             return $this->lock;
  170.         }
  171.         /**
  172.          * @param  bool                $lock
  173.          *
  174.          * @return \Eccube\Entity\Cart
  175.          *
  176.          * @deprecated 使用しないので削除予定
  177.          */
  178.         public function setLock($lock)
  179.         {
  180.             $this->lock $lock;
  181.             return $this;
  182.         }
  183.         /**
  184.          * @return string|null
  185.          */
  186.         public function getPreOrderId()
  187.         {
  188.             return $this->pre_order_id;
  189.         }
  190.         /**
  191.          * @param  integer             $pre_order_id
  192.          *
  193.          * @return \Eccube\Entity\Cart
  194.          */
  195.         public function setPreOrderId($pre_order_id)
  196.         {
  197.             $this->pre_order_id $pre_order_id;
  198.             return $this;
  199.         }
  200.         /**
  201.          * @param  CartItem            $CartItem
  202.          *
  203.          * @return \Eccube\Entity\Cart
  204.          */
  205.         public function addCartItem(CartItem $CartItem)
  206.         {
  207.             $this->CartItems[] = $CartItem;
  208.             return $this;
  209.         }
  210.         /**
  211.          * @return \Eccube\Entity\Cart
  212.          */
  213.         public function clearCartItems()
  214.         {
  215.             $this->CartItems->clear();
  216.             return $this;
  217.         }
  218.         /**
  219.          * @return ArrayCollection|CartItem[]
  220.          */
  221.         public function getCartItems()
  222.         {
  223.             return $this->CartItems;
  224.         }
  225.         /**
  226.          * Alias of getCartItems()
  227.          */
  228.         public function getItems()
  229.         {
  230.             return (new ItemCollection($this->getCartItems()))->sort();
  231.         }
  232.         /**
  233.          * @param  CartItem[]          $CartItems
  234.          *
  235.          * @return \Eccube\Entity\Cart
  236.          */
  237.         public function setCartItems($CartItems)
  238.         {
  239.             $this->CartItems $CartItems;
  240.             return $this;
  241.         }
  242.         /**
  243.          * Set total.
  244.          *
  245.          * @param integer $total_price
  246.          *
  247.          * @return Cart
  248.          */
  249.         public function setTotalPrice($total_price)
  250.         {
  251.             $this->total_price $total_price;
  252.             return $this;
  253.         }
  254.         /**
  255.          * @return string
  256.          */
  257.         public function getTotalPrice()
  258.         {
  259.             return $this->total_price;
  260.         }
  261.         /**
  262.          * Alias of setTotalPrice.
  263.          */
  264.         public function setTotal($total)
  265.         {
  266.             return $this->setTotalPrice($total);
  267.         }
  268.         /**
  269.          * Alias of getTotalPrice
  270.          */
  271.         public function getTotal()
  272.         {
  273.             return $this->getTotalPrice();
  274.         }
  275.         /**
  276.          * @return integer
  277.          */
  278.         public function getTotalQuantity()
  279.         {
  280.             $totalQuantity 0;
  281.             foreach ($this->CartItems as $CartItem) {
  282.                 $totalQuantity += $CartItem->getQuantity();
  283.             }
  284.             return $totalQuantity;
  285.         }
  286.         /**
  287.          * @param ItemInterface $item
  288.          */
  289.         public function addItem(ItemInterface $item)
  290.         {
  291.             $this->CartItems->add($item);
  292.         }
  293.         /**
  294.          * @param ItemInterface $item
  295.          */
  296.         public function removeItem(ItemInterface $item)
  297.         {
  298.             $this->CartItems->removeElement($item);
  299.         }
  300.         /**
  301.          * 個数の合計を返します。
  302.          *
  303.          * @return integer
  304.          */
  305.         public function getQuantity()
  306.         {
  307.             return $this->getTotalQuantity();
  308.         }
  309.         /**
  310.          * {@inheritdoc}
  311.          */
  312.         public function setDeliveryFeeTotal($total)
  313.         {
  314.             $this->delivery_fee_total $total;
  315.             return $this;
  316.         }
  317.         /**
  318.          * {@inheritdoc}
  319.          */
  320.         public function getDeliveryFeeTotal()
  321.         {
  322.             return $this->delivery_fee_total;
  323.         }
  324.         /**
  325.          * @return Customer|null
  326.          */
  327.         public function getCustomer(): ?Customer
  328.         {
  329.             return $this->Customer;
  330.         }
  331.         /**
  332.          * @param Customer $Customer
  333.          */
  334.         public function setCustomer(Customer $Customer null)
  335.         {
  336.             $this->Customer $Customer;
  337.             return $this;
  338.         }
  339.         /**
  340.          * Set sortNo.
  341.          *
  342.          * @param int|null $sortNo
  343.          *
  344.          * @return Cart
  345.          */
  346.         public function setSortNo($sortNo null)
  347.         {
  348.             $this->sort_no $sortNo;
  349.             return $this;
  350.         }
  351.         /**
  352.          * Get sortNo.
  353.          *
  354.          * @return int|null
  355.          */
  356.         public function getSortNo()
  357.         {
  358.             return $this->sort_no;
  359.         }
  360.         /**
  361.          * Set createDate.
  362.          *
  363.          * @param \DateTime $createDate
  364.          *
  365.          * @return Cart
  366.          */
  367.         public function setCreateDate($createDate)
  368.         {
  369.             $this->create_date $createDate;
  370.             return $this;
  371.         }
  372.         /**
  373.          * Get createDate.
  374.          *
  375.          * @return \DateTime
  376.          */
  377.         public function getCreateDate()
  378.         {
  379.             return $this->create_date;
  380.         }
  381.         /**
  382.          * Set updateDate.
  383.          *
  384.          * @param \DateTime $updateDate
  385.          *
  386.          * @return Cart
  387.          */
  388.         public function setUpdateDate($updateDate)
  389.         {
  390.             $this->update_date $updateDate;
  391.             return $this;
  392.         }
  393.         /**
  394.          * Get updateDate.
  395.          *
  396.          * @return \DateTime
  397.          */
  398.         public function getUpdateDate()
  399.         {
  400.             return $this->update_date;
  401.         }
  402.         /**
  403.          * {@inheritdoc}
  404.          */
  405.         public function setDiscount($total)
  406.         {
  407.             // TODO quiet
  408.         }
  409.         /**
  410.          * {@inheritdoc}
  411.          */
  412.         public function setCharge($total)
  413.         {
  414.             // TODO quiet
  415.         }
  416.         /**
  417.          * {@inheritdoc}
  418.          *
  419.          * @deprecated
  420.          */
  421.         public function setTax($total)
  422.         {
  423.             // TODO quiet
  424.         }
  425.     }
  426. }