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 InvalidItemException[]
  107.          */
  108.         private $errors = [];
  109.         public function __wakeup()
  110.         {
  111.             $this->errors = [];
  112.         }
  113.         public function __construct()
  114.         {
  115.             $this->CartItems = new ArrayCollection();
  116.         }
  117.         /**
  118.          * @return int
  119.          */
  120.         public function getId()
  121.         {
  122.             return $this->id;
  123.         }
  124.         /**
  125.          * @return string
  126.          */
  127.         public function getCartKey()
  128.         {
  129.             return $this->cart_key;
  130.         }
  131.         /**
  132.          * @param string $cartKey
  133.          */
  134.         public function setCartKey(string $cartKey)
  135.         {
  136.             $this->cart_key $cartKey;
  137.             return $this;
  138.         }
  139.         /**
  140.          * @return bool
  141.          *
  142.          * @deprecated 使用しないので削除予定
  143.          */
  144.         public function getLock()
  145.         {
  146.             return $this->lock;
  147.         }
  148.         /**
  149.          * @param  bool                $lock
  150.          *
  151.          * @return \Eccube\Entity\Cart
  152.          *
  153.          * @deprecated 使用しないので削除予定
  154.          */
  155.         public function setLock($lock)
  156.         {
  157.             $this->lock $lock;
  158.             return $this;
  159.         }
  160.         /**
  161.          * @return string|null
  162.          */
  163.         public function getPreOrderId()
  164.         {
  165.             return $this->pre_order_id;
  166.         }
  167.         /**
  168.          * @param  integer             $pre_order_id
  169.          *
  170.          * @return \Eccube\Entity\Cart
  171.          */
  172.         public function setPreOrderId($pre_order_id)
  173.         {
  174.             $this->pre_order_id $pre_order_id;
  175.             return $this;
  176.         }
  177.         /**
  178.          * @param  CartItem            $CartItem
  179.          *
  180.          * @return \Eccube\Entity\Cart
  181.          */
  182.         public function addCartItem(CartItem $CartItem)
  183.         {
  184.             $this->CartItems[] = $CartItem;
  185.             return $this;
  186.         }
  187.         /**
  188.          * @return \Eccube\Entity\Cart
  189.          */
  190.         public function clearCartItems()
  191.         {
  192.             $this->CartItems->clear();
  193.             return $this;
  194.         }
  195.         /**
  196.          * @return ArrayCollection|CartItem[]
  197.          */
  198.         public function getCartItems()
  199.         {
  200.             return $this->CartItems;
  201.         }
  202.         /**
  203.          * Alias of getCartItems()
  204.          */
  205.         public function getItems()
  206.         {
  207.             return (new ItemCollection($this->getCartItems()))->sort();
  208.         }
  209.         /**
  210.          * @param  CartItem[]          $CartItems
  211.          *
  212.          * @return \Eccube\Entity\Cart
  213.          */
  214.         public function setCartItems($CartItems)
  215.         {
  216.             $this->CartItems $CartItems;
  217.             return $this;
  218.         }
  219.         /**
  220.          * Set total.
  221.          *
  222.          * @param integer $total_price
  223.          *
  224.          * @return Cart
  225.          */
  226.         public function setTotalPrice($total_price)
  227.         {
  228.             $this->total_price $total_price;
  229.             return $this;
  230.         }
  231.         /**
  232.          * @return string
  233.          */
  234.         public function getTotalPrice()
  235.         {
  236.             return $this->total_price;
  237.         }
  238.         /**
  239.          * Alias of setTotalPrice.
  240.          */
  241.         public function setTotal($total)
  242.         {
  243.             return $this->setTotalPrice($total);
  244.         }
  245.         /**
  246.          * Alias of getTotalPrice
  247.          */
  248.         public function getTotal()
  249.         {
  250.             return $this->getTotalPrice();
  251.         }
  252.         /**
  253.          * @return integer
  254.          */
  255.         public function getTotalQuantity()
  256.         {
  257.             $totalQuantity 0;
  258.             foreach ($this->CartItems as $CartItem) {
  259.                 $totalQuantity += $CartItem->getQuantity();
  260.             }
  261.             return $totalQuantity;
  262.         }
  263.         /**
  264.          * @param ItemInterface $item
  265.          */
  266.         public function addItem(ItemInterface $item)
  267.         {
  268.             $this->CartItems->add($item);
  269.         }
  270.         /**
  271.          * @param ItemInterface $item
  272.          */
  273.         public function removeItem(ItemInterface $item)
  274.         {
  275.             $this->CartItems->removeElement($item);
  276.         }
  277.         /**
  278.          * 個数の合計を返します。
  279.          *
  280.          * @return integer
  281.          */
  282.         public function getQuantity()
  283.         {
  284.             return $this->getTotalQuantity();
  285.         }
  286.         /**
  287.          * {@inheritdoc}
  288.          */
  289.         public function setDeliveryFeeTotal($total)
  290.         {
  291.             $this->delivery_fee_total $total;
  292.             return $this;
  293.         }
  294.         /**
  295.          * {@inheritdoc}
  296.          */
  297.         public function getDeliveryFeeTotal()
  298.         {
  299.             return $this->delivery_fee_total;
  300.         }
  301.         /**
  302.          * @return Customer|null
  303.          */
  304.         public function getCustomer(): ?Customer
  305.         {
  306.             return $this->Customer;
  307.         }
  308.         /**
  309.          * @param Customer $Customer
  310.          */
  311.         public function setCustomer(Customer $Customer null)
  312.         {
  313.             $this->Customer $Customer;
  314.             return $this;
  315.         }
  316.         /**
  317.          * Set sortNo.
  318.          *
  319.          * @param int|null $sortNo
  320.          *
  321.          * @return Cart
  322.          */
  323.         public function setSortNo($sortNo null)
  324.         {
  325.             $this->sort_no $sortNo;
  326.             return $this;
  327.         }
  328.         /**
  329.          * Get sortNo.
  330.          *
  331.          * @return int|null
  332.          */
  333.         public function getSortNo()
  334.         {
  335.             return $this->sort_no;
  336.         }
  337.         /**
  338.          * Set createDate.
  339.          *
  340.          * @param \DateTime $createDate
  341.          *
  342.          * @return Cart
  343.          */
  344.         public function setCreateDate($createDate)
  345.         {
  346.             $this->create_date $createDate;
  347.             return $this;
  348.         }
  349.         /**
  350.          * Get createDate.
  351.          *
  352.          * @return \DateTime
  353.          */
  354.         public function getCreateDate()
  355.         {
  356.             return $this->create_date;
  357.         }
  358.         /**
  359.          * Set updateDate.
  360.          *
  361.          * @param \DateTime $updateDate
  362.          *
  363.          * @return Cart
  364.          */
  365.         public function setUpdateDate($updateDate)
  366.         {
  367.             $this->update_date $updateDate;
  368.             return $this;
  369.         }
  370.         /**
  371.          * Get updateDate.
  372.          *
  373.          * @return \DateTime
  374.          */
  375.         public function getUpdateDate()
  376.         {
  377.             return $this->update_date;
  378.         }
  379.         /**
  380.          * {@inheritdoc}
  381.          */
  382.         public function setDiscount($total)
  383.         {
  384.             // TODO quiet
  385.         }
  386.         /**
  387.          * {@inheritdoc}
  388.          */
  389.         public function setCharge($total)
  390.         {
  391.             // TODO quiet
  392.         }
  393.         /**
  394.          * {@inheritdoc}
  395.          *
  396.          * @deprecated
  397.          */
  398.         public function setTax($total)
  399.         {
  400.             // TODO quiet
  401.         }
  402.     }
  403. }