app/Plugin/EccubePaymentLite42/Entity/RegularOrder.php line 30

Open in your IDE?
  1. <?php
  2. namespace Plugin\EccubePaymentLite42\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Criteria;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Eccube\Entity\AbstractEntity;
  7. use Eccube\Entity\Customer;
  8. use Eccube\Entity\Master\Country;
  9. use Eccube\Entity\Master\CustomerOrderStatus;
  10. use Eccube\Entity\Master\DeviceType;
  11. use Eccube\Entity\Master\Job;
  12. use Eccube\Entity\Master\OrderStatus;
  13. use Eccube\Entity\Master\OrderStatusColor;
  14. use Eccube\Entity\Master\Pref;
  15. use Eccube\Entity\Master\Sex;
  16. use Eccube\Entity\Master\TaxType;
  17. use Eccube\Entity\NameTrait;
  18. use Eccube\Entity\Order;
  19. use Eccube\Entity\Payment;
  20. use Eccube\Entity\PointTrait;
  21. use Eccube\Service\Calculator\OrderItemCollection;
  22. use Eccube\Service\PurchaseFlow\ItemCollection;
  23. /**
  24.  * @ORM\Table(name="plg_eccube_payment_lite42_regular_order")
  25.  * @ORM\Entity(repositoryClass="Plugin\EccubePaymentLite42\Repository\RegularOrderRepository")
  26.  */
  27. class RegularOrder extends AbstractEntity
  28. {
  29.     use NameTrait;
  30.     use PointTrait;
  31.     /**
  32.      * @ORM\Column(name="id", type="integer", options={"unsigned":true})
  33.      * @ORM\Id
  34.      * @ORM\GeneratedValue(strategy="IDENTITY")
  35.      */
  36.     private $id;
  37.     /**
  38.      * @ORM\Column(name="pre_order_id", type="string", length=255, nullable=true)
  39.      */
  40.     private $pre_order_id;
  41.     /**
  42.      * @ORM\Column(name="order_no", type="string", length=255, nullable=true)
  43.      */
  44.     private $order_no;
  45.     /**
  46.      * @ORM\Column(name="message", type="string", length=4000, nullable=true)
  47.      */
  48.     private $message;
  49.     /**
  50.      * @ORM\Column(name="name01", type="string", length=255)
  51.      */
  52.     private $name01;
  53.     /**
  54.      * @ORM\Column(name="name02", type="string", length=255)
  55.      */
  56.     private $name02;
  57.     /**
  58.      * @ORM\Column(name="kana01", type="string", length=255, nullable=true)
  59.      */
  60.     private $kana01;
  61.     /**
  62.      * @ORM\Column(name="kana02", type="string", length=255, nullable=true)
  63.      */
  64.     private $kana02;
  65.     /**
  66.      * @ORM\Column(name="company_name", type="string", length=255, nullable=true)
  67.      */
  68.     private $company_name;
  69.     /**
  70.      * @ORM\Column(name="email", type="string", length=255, nullable=true)
  71.      */
  72.     private $email;
  73.     /**
  74.      * @ORM\Column(name="phone_number", type="string", length=14, nullable=true)
  75.      */
  76.     private $phone_number;
  77.     /**
  78.      * @ORM\Column(name="postal_code", type="string", length=8, nullable=true)
  79.      */
  80.     private $postal_code;
  81.     /**
  82.      * @ORM\Column(name="addr01", type="string", length=255, nullable=true)
  83.      */
  84.     private $addr01;
  85.     /**
  86.      * @ORM\Column(name="addr02", type="string", length=255, nullable=true)
  87.      */
  88.     private $addr02;
  89.     /**
  90.      * @ORM\Column(name="birth", type="datetimetz", nullable=true)
  91.      */
  92.     private $birth;
  93.     /**
  94.      * @ORM\Column(name="subtotal", type="decimal", precision=12, scale=2, options={"unsigned":true,"default":0})
  95.      */
  96.     private $subtotal = 0;
  97.     /**
  98.      * @ORM\Column(name="discount", type="decimal", precision=12, scale=2, options={"unsigned":true,"default":0})
  99.      */
  100.     private $discount = 0;
  101.     /**
  102.      * @ORM\Column(name="delivery_fee_total", type="decimal", precision=12, scale=2, options={"unsigned":true,"default":0})
  103.      */
  104.     private $delivery_fee_total = 0;
  105.     /**
  106.      * @ORM\Column(name="charge", type="decimal", precision=12, scale=2, options={"unsigned":true,"default":0})
  107.      */
  108.     private $charge = 0;
  109.     /**
  110.      * @ORM\Column(name="tax", type="decimal", precision=12, scale=2, options={"unsigned":true,"default":0})
  111.      */
  112.     private $tax = 0;
  113.     /**
  114.      * @ORM\Column(name="total", type="decimal", precision=12, scale=2, options={"unsigned":true,"default":0})
  115.      */
  116.     private $total = 0;
  117.     /**
  118.      * @ORM\Column(name="payment_total", type="decimal", precision=12, scale=2, options={"unsigned":true,"default":0})
  119.      */
  120.     private $payment_total = 0;
  121.     /**
  122.      * @ORM\Column(name="payment_method", type="string", length=255, nullable=true)
  123.      */
  124.     private $payment_method;
  125.     /**
  126.      * @ORM\Column(name="note", type="string", length=4000, nullable=true)
  127.      */
  128.     private $note;
  129.     /**
  130.      * @ORM\Column(name="create_date", type="datetimetz")
  131.      */
  132.     private $create_date;
  133.     /**
  134.      * @ORM\Column(name="update_date", type="datetimetz")
  135.      */
  136.     private $update_date;
  137.     /**
  138.      * @ORM\Column(name="order_date", type="datetimetz", nullable=true)
  139.      */
  140.     private $order_date;
  141.     /**
  142.      * @ORM\Column(name="payment_date", type="datetimetz", nullable=true)
  143.      */
  144.     private $payment_date;
  145.     /**
  146.      * @ORM\Column(name="currency_code", type="string", nullable=true)
  147.      */
  148.     private $currency_code;
  149.     /**
  150.      * 注文完了画面に表示するメッセージ
  151.      *
  152.      * プラグインから注文完了時にメッセージを表示したい場合, このフィールドにセットすることで, 注文完了画面で表示されます。
  153.      * 複数のプラグインから利用されるため, appendCompleteMessage()で追加してください.
  154.      * 表示する際にHTMLは利用可能です。
  155.      *
  156.      * @ORM\Column(name="complete_message", type="text", nullable=true)
  157.      */
  158.     private $complete_message;
  159.     /**
  160.      * 注文完了メールに表示するメッセージ
  161.      *
  162.      * プラグインから注文完了メールにメッセージを表示したい場合, このフィールドにセットすることで, 注文完了メールで表示されます。
  163.      * 複数のプラグインから利用されるため, appendCompleteMailMessage()で追加してください.
  164.      *
  165.      * @ORM\Column(name="complete_mail_message", type="text", nullable=true)
  166.      */
  167.     private $complete_mail_message;
  168.     /**
  169.      * @ORM\OneToMany(targetEntity="Plugin\EccubePaymentLite42\Entity\RegularOrderItem", mappedBy="RegularOrder", cascade={"persist","remove"})
  170.      */
  171.     private $RegularOrderItems;
  172.     /**
  173.      * @ORM\OneToMany(targetEntity="Plugin\EccubePaymentLite42\Entity\RegularShipping", mappedBy="RegularOrder", cascade={"persist","remove"})
  174.      */
  175.     private $RegularShippings;
  176.     /**
  177.      * @ORM\ManyToOne(targetEntity="Eccube\Entity\Customer")
  178.      * @ORM\JoinColumn(name="customer_id", referencedColumnName="id")
  179.      */
  180.     private $Customer;
  181.     /**
  182.      * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\Country")
  183.      * @ORM\JoinColumn(name="country_id", referencedColumnName="id")
  184.      */
  185.     private $Country;
  186.     /**
  187.      * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\Pref")
  188.      * @ORM\JoinColumn(name="pref_id", referencedColumnName="id")
  189.      */
  190.     private $Pref;
  191.     /**
  192.      * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\Sex")
  193.      * @ORM\JoinColumn(name="sex_id", referencedColumnName="id")
  194.      */
  195.     private $Sex;
  196.     /**
  197.      * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\Job")
  198.      * @ORM\JoinColumn(name="job_id", referencedColumnName="id")
  199.      */
  200.     private $Job;
  201.     /**
  202.      * @ORM\ManyToOne(targetEntity="Eccube\Entity\Payment")
  203.      * @ORM\JoinColumn(name="payment_id", referencedColumnName="id")
  204.      */
  205.     private $Payment;
  206.     /**
  207.      * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\DeviceType")
  208.      * @ORM\JoinColumn(name="device_type_id", referencedColumnName="id")
  209.      */
  210.     private $DeviceType;
  211.     /**
  212.      * OrderStatusより先にプロパティを定義しておかないとセットされなくなる
  213.      *
  214.      * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\CustomerOrderStatus")
  215.      * @ORM\JoinColumn(name="order_status_id", referencedColumnName="id")
  216.      */
  217.     private $CustomerOrderStatus;
  218.     /**
  219.      * OrderStatusより先にプロパティを定義しておかないとセットされなくなる
  220.      *
  221.      * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\OrderStatusColor")
  222.      * @ORM\JoinColumn(name="order_status_id", referencedColumnName="id")
  223.      */
  224.     private $OrderStatusColor;
  225.     /**
  226.      * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\OrderStatus")
  227.      * @ORM\JoinColumn(name="order_status_id", referencedColumnName="id")
  228.      */
  229.     private $OrderStatus;
  230.     /**
  231.      * @ORM\Column(name="trans_code", type="text", nullable=true)
  232.      */
  233.     private $trans_code;
  234.     /**
  235.      * @ORM\Column(name="regular_order_count", type="integer", length=6, nullable=true, options={"default":1})
  236.      */
  237.     private $regular_order_count;
  238.     /**
  239.      * @ORM\ManyToOne(targetEntity="Plugin\EccubePaymentLite42\Entity\RegularStatus")
  240.      * @ORM\JoinColumn(name="regular_status_id", referencedColumnName="id")
  241.      */
  242.     private $RegularStatus;
  243.     /**
  244.      * @ORM\ManyToOne(targetEntity="Plugin\EccubePaymentLite42\Entity\RegularCycle")
  245.      * @ORM\JoinColumn(name="regular_cycle_id", referencedColumnName="id")
  246.      */
  247.     private $RegularCycle;
  248.     /**
  249.      * @ORM\OneToMany(targetEntity="Eccube\Entity\Order", mappedBy="RegularOrder")
  250.      */
  251.     private $Orders;
  252.     /**
  253.      * @ORM\Column(name="regular_skip_flag", type="integer", length=6, nullable=true, options={"default":0})
  254.      */
  255.     private $regular_skip_flag;
  256.     /**
  257.      * @ORM\Column(name="regular_stop_date", type="datetimetz", nullable=true)
  258.      */
  259.     private $regular_stop_date;
  260.     public function __construct()
  261.     {
  262.         $this->RegularOrderItems = new ArrayCollection();
  263.         $this->RegularShippings = new ArrayCollection();
  264.         $this->Orders = new ArrayCollection();
  265.     }
  266.     public function getId()
  267.     {
  268.         return $this->id;
  269.     }
  270.     public function setPreOrderId($preOrderId = null)
  271.     {
  272.         $this->pre_order_id = $preOrderId;
  273.         return $this;
  274.     }
  275.     public function getPreOrderId()
  276.     {
  277.         return $this->pre_order_id;
  278.     }
  279.     public function setOrderNo($orderNo = null)
  280.     {
  281.         $this->order_no = $orderNo;
  282.         return $this;
  283.     }
  284.     public function getOrderNo()
  285.     {
  286.         return $this->order_no;
  287.     }
  288.     public function setMessage($message = null)
  289.     {
  290.         $this->message = $message;
  291.         return $this;
  292.     }
  293.     public function getMessage()
  294.     {
  295.         return $this->message;
  296.     }
  297.     public function setName01($name01 = null)
  298.     {
  299.         $this->name01 = $name01;
  300.         return $this;
  301.     }
  302.     public function getName01()
  303.     {
  304.         return $this->name01;
  305.     }
  306.     public function setName02($name02 = null)
  307.     {
  308.         $this->name02 = $name02;
  309.         return $this;
  310.     }
  311.     public function getName02()
  312.     {
  313.         return $this->name02;
  314.     }
  315.     public function setKana01($kana01 = null)
  316.     {
  317.         $this->kana01 = $kana01;
  318.         return $this;
  319.     }
  320.     public function getKana01()
  321.     {
  322.         return $this->kana01;
  323.     }
  324.     public function setKana02($kana02 = null)
  325.     {
  326.         $this->kana02 = $kana02;
  327.         return $this;
  328.     }
  329.     public function getKana02()
  330.     {
  331.         return $this->kana02;
  332.     }
  333.     public function setCompanyName($companyName = null)
  334.     {
  335.         $this->company_name = $companyName;
  336.         return $this;
  337.     }
  338.     public function getCompanyName()
  339.     {
  340.         return $this->company_name;
  341.     }
  342.     public function setEmail($email = null)
  343.     {
  344.         $this->email = $email;
  345.         return $this;
  346.     }
  347.     public function getEmail()
  348.     {
  349.         return $this->email;
  350.     }
  351.     public function setPhoneNumber($phone_number = null)
  352.     {
  353.         $this->phone_number = $phone_number;
  354.         return $this;
  355.     }
  356.     public function getPhoneNumber()
  357.     {
  358.         return $this->phone_number;
  359.     }
  360.     public function setPostalCode($postal_code = null)
  361.     {
  362.         $this->postal_code = $postal_code;
  363.         return $this;
  364.     }
  365.     public function getPostalCode()
  366.     {
  367.         return $this->postal_code;
  368.     }
  369.     public function setAddr01($addr01 = null)
  370.     {
  371.         $this->addr01 = $addr01;
  372.         return $this;
  373.     }
  374.     public function getAddr01()
  375.     {
  376.         return $this->addr01;
  377.     }
  378.     public function setAddr02($addr02 = null)
  379.     {
  380.         $this->addr02 = $addr02;
  381.         return $this;
  382.     }
  383.     public function getAddr02()
  384.     {
  385.         return $this->addr02;
  386.     }
  387.     public function setBirth($birth = null)
  388.     {
  389.         $this->birth = $birth;
  390.         return $this;
  391.     }
  392.     public function getBirth()
  393.     {
  394.         return $this->birth;
  395.     }
  396.     public function setSubtotal($subtotal)
  397.     {
  398.         $this->subtotal = $subtotal;
  399.         return $this;
  400.     }
  401.     public function getSubtotal()
  402.     {
  403.         return $this->subtotal;
  404.     }
  405.     public function setDiscount($discount)
  406.     {
  407.         $this->discount = $discount;
  408.         return $this;
  409.     }
  410.     public function getDiscount()
  411.     {
  412.         return $this->discount;
  413.     }
  414.     public function setDeliveryFeeTotal($deliveryFeeTotal)
  415.     {
  416.         $this->delivery_fee_total = $deliveryFeeTotal;
  417.         return $this;
  418.     }
  419.     public function getDeliveryFeeTotal()
  420.     {
  421.         return $this->delivery_fee_total;
  422.     }
  423.     public function setCharge($charge)
  424.     {
  425.         $this->charge = $charge;
  426.         return $this;
  427.     }
  428.     public function getCharge()
  429.     {
  430.         return $this->charge;
  431.     }
  432.     public function setTax($tax)
  433.     {
  434.         $this->tax = $tax;
  435.         return $this;
  436.     }
  437.     public function getTax()
  438.     {
  439.         return $this->tax;
  440.     }
  441.     public function setTotal($total)
  442.     {
  443.         $this->total = $total;
  444.         return $this;
  445.     }
  446.     public function getTotal()
  447.     {
  448.         return $this->total;
  449.     }
  450.     public function setPaymentTotal($paymentTotal)
  451.     {
  452.         $this->payment_total = $paymentTotal;
  453.         return $this;
  454.     }
  455.     public function getPaymentTotal()
  456.     {
  457.         return $this->payment_total;
  458.     }
  459.     public function setPaymentMethod($paymentMethod = null)
  460.     {
  461.         $this->payment_method = $paymentMethod;
  462.         return $this;
  463.     }
  464.     public function getPaymentMethod()
  465.     {
  466.         return $this->payment_method;
  467.     }
  468.     public function setNote($note = null)
  469.     {
  470.         $this->note = $note;
  471.         return $this;
  472.     }
  473.     public function getNote()
  474.     {
  475.         return $this->note;
  476.     }
  477.     public function setCreateDate($createDate)
  478.     {
  479.         $this->create_date = $createDate;
  480.         return $this;
  481.     }
  482.     public function getCreateDate()
  483.     {
  484.         return $this->create_date;
  485.     }
  486.     public function setUpdateDate($updateDate)
  487.     {
  488.         $this->update_date = $updateDate;
  489.         return $this;
  490.     }
  491.     public function getUpdateDate()
  492.     {
  493.         return $this->update_date;
  494.     }
  495.     public function setOrderDate($orderDate = null)
  496.     {
  497.         $this->order_date = $orderDate;
  498.         return $this;
  499.     }
  500.     public function getOrderDate()
  501.     {
  502.         return $this->order_date;
  503.     }
  504.     public function setPaymentDate($paymentDate = null)
  505.     {
  506.         $this->payment_date = $paymentDate;
  507.         return $this;
  508.     }
  509.     public function getPaymentDate()
  510.     {
  511.         return $this->payment_date;
  512.     }
  513.     public function getCurrencyCode()
  514.     {
  515.         return $this->currency_code;
  516.     }
  517.     public function setCurrencyCode($currencyCode = null)
  518.     {
  519.         $this->currency_code = $currencyCode;
  520.         return $this;
  521.     }
  522.     public function getCompleteMessage()
  523.     {
  524.         return $this->complete_message;
  525.     }
  526.     public function setCompleteMessage($complete_message = null)
  527.     {
  528.         $this->complete_message = $complete_message;
  529.         return $this;
  530.     }
  531.     public function getCompleteMailMessage()
  532.     {
  533.         return $this->complete_mail_message;
  534.     }
  535.     public function setCompleteMailMessage($complete_mail_message = null)
  536.     {
  537.         $this->complete_mail_message = $complete_mail_message;
  538.         return $this;
  539.     }
  540.     public function setCustomer(Customer $customer = null)
  541.     {
  542.         $this->Customer = $customer;
  543.         return $this;
  544.     }
  545.     public function getCustomer()
  546.     {
  547.         return $this->Customer;
  548.     }
  549.     public function setCountry(Country $country = null)
  550.     {
  551.         $this->Country = $country;
  552.         return $this;
  553.     }
  554.     public function getCountry()
  555.     {
  556.         return $this->Country;
  557.     }
  558.     public function setPref(Pref $pref = null)
  559.     {
  560.         $this->Pref = $pref;
  561.         return $this;
  562.     }
  563.     public function getPref()
  564.     {
  565.         return $this->Pref;
  566.     }
  567.     public function setSex(Sex $sex = null)
  568.     {
  569.         $this->Sex = $sex;
  570.         return $this;
  571.     }
  572.     public function getSex()
  573.     {
  574.         return $this->Sex;
  575.     }
  576.     public function setJob(Job $job = null)
  577.     {
  578.         $this->Job = $job;
  579.         return $this;
  580.     }
  581.     public function getJob()
  582.     {
  583.         return $this->Job;
  584.     }
  585.     public function setPayment(Payment $payment = null)
  586.     {
  587.         $this->Payment = $payment;
  588.         return $this;
  589.     }
  590.     public function getPayment()
  591.     {
  592.         return $this->Payment;
  593.     }
  594.     public function setDeviceType(DeviceType $deviceType = null)
  595.     {
  596.         $this->DeviceType = $deviceType;
  597.         return $this;
  598.     }
  599.     public function getDeviceType()
  600.     {
  601.         return $this->DeviceType;
  602.     }
  603.     public function setCustomerOrderStatus(CustomerOrderStatus $customerOrderStatus = null)
  604.     {
  605.         $this->CustomerOrderStatus = $customerOrderStatus;
  606.         return $this;
  607.     }
  608.     public function getCustomerOrderStatus()
  609.     {
  610.         return $this->CustomerOrderStatus;
  611.     }
  612.     public function setOrderStatusColor(OrderStatusColor $orderStatusColor = null)
  613.     {
  614.         $this->OrderStatusColor = $orderStatusColor;
  615.         return $this;
  616.     }
  617.     public function getOrderStatusColor()
  618.     {
  619.         return $this->OrderStatusColor;
  620.     }
  621.     public function setOrderStatus(OrderStatus $orderStatus = null)
  622.     {
  623.         $this->OrderStatus = $orderStatus;
  624.         return $this;
  625.     }
  626.     public function getOrderStatus()
  627.     {
  628.         return $this->OrderStatus;
  629.     }
  630.     public function addRegularOrderItem(RegularOrderItem $RegularOrderItem)
  631.     {
  632.         $this->RegularOrderItems[] = $RegularOrderItem;
  633.         return $this;
  634.     }
  635.     public function removeRegularOrderItem(RegularOrderItem $RegularOrderItem)
  636.     {
  637.         return $this->RegularOrderItems->removeElement($RegularOrderItem);
  638.     }
  639.     public function getRegularOrderItems()
  640.     {
  641.         return $this->RegularOrderItems;
  642.     }
  643.     public function addRegularShipping(RegularShipping $RegularShipping)
  644.     {
  645.         $this->RegularShippings[] = $RegularShipping;
  646.         return $this;
  647.     }
  648.     public function removeRegularShipping(RegularShipping $RegularShipping)
  649.     {
  650.         return $this->RegularShippings->removeElement($RegularShipping);
  651.     }
  652.     public function getRegularShippings()
  653.     {
  654.         $criteria = Criteria::create()
  655.             ->orderBy(['name01' => Criteria::ASC, 'name02' => Criteria::ASC, 'id' => Criteria::ASC]);
  656.         return $this->RegularShippings->matching($criteria);
  657.     }
  658.     public function setTransCode($transCode)
  659.     {
  660.         $this->trans_code = $transCode;
  661.         return $this;
  662.     }
  663.     public function getTransCode()
  664.     {
  665.         return $this->trans_code;
  666.     }
  667.     public function setRegularOrderCount($regularOrderCount)
  668.     {
  669.         $this->regular_order_count = $regularOrderCount;
  670.         return $this;
  671.     }
  672.     public function getRegularOrderCount()
  673.     {
  674.         return $this->regular_order_count;
  675.     }
  676.     public function setRegularSkipFlag($regularSkipFlag)
  677.     {
  678.         $this->regular_skip_flag = $regularSkipFlag;
  679.         return $this;
  680.     }
  681.     public function getRegularSkipFlag()
  682.     {
  683.         return $this->regular_skip_flag;
  684.     }
  685.     public function setRegularStatus(RegularStatus $regularStatus)
  686.     {
  687.         $this->RegularStatus = $regularStatus;
  688.         return $this;
  689.     }
  690.     public function getRegularStatus(): RegularStatus
  691.     {
  692.         return $this->RegularStatus;
  693.     }
  694.     public function getItems()
  695.     {
  696.         return (new ItemCollection($this->getRegularOrderItems()))->sort();
  697.     }
  698.     public function getQuantity()
  699.     {
  700.         $quantity = 0;
  701.         foreach ($this->getItems() as $item) {
  702.             $quantity += $item->getQuantity();
  703.         }
  704.         return $quantity;
  705.     }
  706.     public function setRegularCycle(RegularCycle $regularCycle = null)
  707.     {
  708.         $this->RegularCycle = $regularCycle;
  709.         return $this;
  710.     }
  711.     public function getRegularCycle()
  712.     {
  713.         return $this->RegularCycle;
  714.     }
  715.     /**
  716.      * @return array
  717.      */
  718.     public function getRegularProductOrderItems()
  719.     {
  720.         $sio = new OrderItemCollection($this->RegularOrderItems->toArray());
  721.         return array_values($sio->getProductClasses()->toArray());
  722.     }
  723.     /**
  724.      * 複数配送かどうかの判定を行う.
  725.      *
  726.      * @return boolean
  727.      */
  728.     public function isMultiple()
  729.     {
  730.         $RegularShippings = [];
  731.         foreach ($this->getRegularOrderItems() as $Item) {
  732.             if ($RegularShipping = $Item->getRegularShipping()) {
  733.                 $id = $RegularShipping->getId();
  734.                 if (isset($Shippings[$id])) {
  735.                     continue;
  736.                 }
  737.                 $RegularShippings[$id] = $RegularShipping;
  738.             }
  739.         }
  740.         return count($RegularShippings) > 1;
  741.     }
  742.     /**
  743.      * 課税対象の明細を返す.
  744.      *
  745.      * @return array
  746.      */
  747.     public function getTaxableItems()
  748.     {
  749.         $Items = [];
  750.         foreach ($this->RegularOrderItems as $Item) {
  751.             if ($Item->getTaxType()->getId() == TaxType::TAXATION) {
  752.                 $Items[] = $Item;
  753.             }
  754.         }
  755.         return $Items;
  756.     }
  757.     /**
  758.      * 課税対象の明細の合計金額を返す.
  759.      * 商品合計 + 送料 + 手数料 + 値引き(課税).
  760.      */
  761.     public function getTaxableTotal()
  762.     {
  763.         $total = 0;
  764.         foreach ($this->getTaxableItems() as $Item) {
  765.             $total += $Item->getTotalPrice();
  766.         }
  767.         return $total;
  768.     }
  769.     /**
  770.      * 課税対象の明細の合計金額を、税率ごとに集計する.
  771.      *
  772.      * @return array
  773.      */
  774.     public function getTaxableTotalByTaxRate()
  775.     {
  776.         $total = [];
  777.         foreach ($this->getTaxableItems() as $Item) {
  778.             $totalPrice = $Item->getTotalPrice();
  779.             $taxRate = $Item->getTaxRate();
  780.             $total[$taxRate] = isset($total[$taxRate])
  781.                     ? $total[$taxRate] + $totalPrice
  782.                     : $totalPrice;
  783.         }
  784.         krsort($total);
  785.         return $total;
  786.     }
  787.     /**
  788.      * 課税対象の値引き明細を返す.
  789.      *
  790.      * @return array
  791.      */
  792.     public function getTaxableDiscountItems()
  793.     {
  794.         return array_filter($this->getTaxableItems(), function (RegularOrderItem $Item) {
  795.             return $Item->isDiscount();
  796.         });
  797.     }
  798.     /**
  799.      * 課税対象の値引き金額合計を返す.
  800.      *
  801.      * @return mixed
  802.      */
  803.     public function getTaxableDiscount()
  804.     {
  805.         return array_reduce($this->getTaxableDiscountItems(), function ($sum, RegularOrderItem $Item) {
  806.             return $sum += $Item->getTotalPrice();
  807.         }, 0);
  808.     }
  809.     /**
  810.      * 非課税・不課税の値引き明細を返す.
  811.      *
  812.      * @return array
  813.      */
  814.     public function getTaxFreeDiscountItems()
  815.     {
  816.         return array_filter($this->RegularOrderItems->toArray(), function (RegularOrderItem $Item) {
  817.             return $Item->isPoint() || ($Item->isDiscount() && $Item->getTaxType()->getId() != TaxType::TAXATION);
  818.         });
  819.     }
  820.     public function getMergedRegularProductOrderItems()
  821.     {
  822.         $ProductOrderItems = $this->getRegularProductOrderItems();
  823.         $orderItemArray = [];
  824.         /** @var RegularOrderItem $ProductOrderItem */
  825.         foreach ($ProductOrderItems as $ProductOrderItem) {
  826.             $productClassId = $ProductOrderItem->getProductClass()->getId();
  827.             if (array_key_exists($productClassId, $orderItemArray)) {
  828.                 // 同じ規格の商品がある場合は個数をまとめる
  829.                 $RegularOrderItem = $orderItemArray[$productClassId];
  830.                 $quantity = $RegularOrderItem->getQuantity() + $ProductOrderItem->getQuantity();
  831.                 $RegularOrderItem->setQuantity($quantity);
  832.             } else {
  833.                 // 新規規格の商品は新しく追加する
  834.                 $RegularOrderItem = new RegularOrderItem();
  835.                 $RegularOrderItem->copyProperties($ProductOrderItem, ['id']);
  836.                 $orderItemArray[$productClassId] = $RegularOrderItem;
  837.             }
  838.         }
  839.         return array_values($orderItemArray);
  840.     }
  841.     public function getOrders()
  842.     {
  843.         return $this->Orders;
  844.     }
  845.     public function setOrders(ArrayCollection $Orders): self
  846.     {
  847.         $this->Orders = $Orders;
  848.         return $this;
  849.     }
  850.     public function getFirstOrder()
  851.     {
  852.         $orderBy = (Criteria::create())->orderBy([
  853.             'create_date' => Criteria::ASC,
  854.         ]);
  855.         foreach ($this->Orders->matching($orderBy) as $Order) {
  856.             /** @var Order $Order */
  857.             if ($Order->getOrderStatus()->getId() !== OrderStatus::PROCESSING &&
  858.                 $Order->getOrderStatus()->getId() !== OrderStatus::PENDING) {
  859.                 return $Order->toArray();
  860.             }
  861.         }
  862.         return [];
  863.     }
  864.     public function getLastOrder()
  865.     {
  866.         $orderBy = (Criteria::create())->orderBy([
  867.             'create_date' => Criteria::DESC,
  868.         ]);
  869.         $this->Orders->matching($orderBy);
  870.         foreach ($this->Orders->matching($orderBy) as $Order) {
  871.             /** @var Order $Order */
  872.             if ($Order->getOrderStatus()->getId() !== OrderStatus::PROCESSING &&
  873.                 $Order->getOrderStatus()->getId() !== OrderStatus::PENDING) {
  874.                 return $Order->toArray();
  875.             }
  876.         }
  877.         return [];
  878.     }
  879.     public function getRegularStopDate()
  880.     {
  881.         return $this->regular_stop_date;
  882.     }
  883.     public function setRegularStopDate($regular_stop_date): self
  884.     {
  885.         $this->regular_stop_date = $regular_stop_date;
  886.         return $this;
  887.     }
  888. }