modules/QSL/AbandonedCartReminder/src/Model/Email.php line 27

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright (c) 2001-present X-Cart Holdings LLC. All rights reserved.
  4.  * See https://www.x-cart.com/license-agreement.html for license details.
  5.  */
  6. namespace QSL\AbandonedCartReminder\Model;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * E-mail notification for an abandoned cart.
  10.  *
  11.  * @ORM\Entity (repositoryClass="\QSL\AbandonedCartReminder\Model\Repo\Email")
  12.  * @ORM\Table  (name="cart_reminder_emails",
  13.  *      indexes={
  14.  *          @ORM\Index (name="dateSent", columns={"dateSent"}),
  15.  *          @ORM\Index (name="dateClicked", columns={"dateClicked"}),
  16.  *          @ORM\Index (name="datePlaced", columns={"datePlaced"}),
  17.  *          @ORM\Index (name="datePaid", columns={"datePaid"}),
  18.  *          @ORM\Index (name="orderHash", columns={"orderHash"}),
  19.  *          @ORM\Index (name="profileHash", columns={"profileHash"})
  20.  *      }
  21.  * )
  22.  */
  23. class Email extends \XLite\Model\AEntity
  24. {
  25.     /**
  26.      * Primary key
  27.      *
  28.      * @var integer
  29.      *
  30.      * @ORM\Id
  31.      * @ORM\GeneratedValue (strategy="AUTO")
  32.      * @ORM\Column         (type="integer")
  33.      */
  34.     protected $email_id;
  35.     /**
  36.      * Abandoned cart / recovered order
  37.      *
  38.      * Due to the default "cart ttl" set to 7 days, we have to make the relation
  39.      * optional and provide a function to clear past statistics (otherwise XC5
  40.      * will auto-delete e-mails sent more than 7 days ago).
  41.      *
  42.      * @var \XLite\Model\Order
  43.      *
  44.      * @ORM\ManyToOne  (targetEntity="XLite\Model\Order", inversedBy="cartReminderEmails")
  45.      * @ORM\JoinColumn (name="order_id", referencedColumnName="order_id", nullable=true, onDelete="SET NULL")
  46.      */
  47.     protected $order;
  48.     /**
  49.      * Unique identifier of the associated order.
  50.      *
  51.      * Orders can be deleted (and will be deleted during the garbage clean-up
  52.      * routine!). So, in order to keep the statistics consistent, we have to
  53.      * store some kind of a cached identifier that doesn't depend on
  54.      * the associated order model.
  55.      *
  56.      * @var string
  57.      * @ORM\Column (type="string", length=255, nullable=false, options={ "default": "" })
  58.      */
  59.     protected $orderHash '';
  60.     /**
  61.      * Unique identifier of the associated profile.
  62.      *
  63.      * Profiles can be deleted. So, in order to keep the statistics consistent,
  64.      * we have to store some kind of a cached identifier that doesn't depend on
  65.      * the associated profile model.
  66.      *
  67.      * @var string
  68.      * @ORM\Column (type="string", length=255, nullable=false, options={ "default": "" })
  69.      */
  70.     protected $profileHash '';
  71.     /**
  72.      * Date when the e-mail was sent (timestamp).
  73.      *
  74.      * @var integer
  75.      *
  76.      * @ORM\Column (type="integer", nullable=false, options={ "default": 0 })
  77.      */
  78.     protected $dateSent 0;
  79.     /**
  80.      * Date when the e-mail was clicked by the customer the last time (timestamp).
  81.      *
  82.      * @var integer
  83.      *
  84.      * @ORM\Column (type="integer", nullable=false, options={ "default": 0 })
  85.      */
  86.     protected $dateClicked 0;
  87.     /**
  88.      * Date when the customer placed the order (timestamp).
  89.      *
  90.      * @var integer
  91.      *
  92.      * @ORM\Column (type="integer", nullable=false, options={ "default": 0 })
  93.      */
  94.     protected $datePlaced 0;
  95.     /**
  96.      * Date when the customer paid the order (timestamp).
  97.      *
  98.      * @var integer
  99.      *
  100.      * @ORM\Column (type="integer", nullable=false, options={ "default": 0 })
  101.      */
  102.     protected $datePaid 0;
  103.     /**
  104.      * @var integer
  105.      *
  106.      * @ORM\Column (type="integer", nullable=false)
  107.      */
  108.     protected $reminderId;
  109.     /**
  110.      * Returns a unique string that identifies an order.
  111.      *
  112.      * @param \XLite\Model\Order $order Order or cart model
  113.      *
  114.      * @return string
  115.      */
  116.     public static function getHashForOrder(\XLite\Model\Order $order)
  117.     {
  118.         $email $order->getLastCartReminderEmail();
  119.         return $email $email->getOrderHash() : ($order->getDate() . '-' $order->getOrderId());
  120.     }
  121.     /**
  122.      * Returns a unique string that identifies a user.
  123.      *
  124.      * @param \XLite\Model\Profile $profile User profile
  125.      *
  126.      * @return string
  127.      */
  128.     public static function getHashForProfile(\XLite\Model\Profile $profile)
  129.     {
  130.         return $profile->getAdded() . '-' $profile->getProfileId();
  131.     }
  132.     /**
  133.      * Updates the date when the e-mail was sent to the user.
  134.      *
  135.      * @param int $timestamp Date (UNIX timestamp)
  136.      *
  137.      * @return void
  138.      */
  139.     public function setDateSent($timestamp)
  140.     {
  141.         $this->dateSent $timestamp;
  142.     }
  143.     /**
  144.      * Returns the date when the e-mail was sent to the user.
  145.      *
  146.      * @return int
  147.      */
  148.     public function getDateSent()
  149.     {
  150.         return $this->dateSent;
  151.     }
  152.     /**
  153.      * Updates the date when user followed the cart recovery link in the e-mail
  154.      * the last time.
  155.      *
  156.      * @param int $timestamp Date (UNIX timestamp)
  157.      *
  158.      * @return void
  159.      */
  160.     public function setDateClicked($timestamp)
  161.     {
  162.         $this->dateClicked $timestamp;
  163.     }
  164.     /**
  165.      * Returns the date when user followed the cart recovery link in the e-mail
  166.      * the last time.
  167.      *
  168.      * @return int
  169.      */
  170.     public function getDateClicked()
  171.     {
  172.         return $this->dateClicked;
  173.     }
  174.     /**
  175.      * Updates the date when user placed an order after following the cart
  176.      * recovery link from the e-mail.
  177.      *
  178.      * @param int $timestamp Date (UNIX timestamp)
  179.      *
  180.      * @return void
  181.      */
  182.     public function setDatePlaced($timestamp)
  183.     {
  184.         $this->datePlaced $timestamp;
  185.     }
  186.     /**
  187.      * Returns the date when user placed an order after following the cart
  188.      * recovery link from the e-mail.
  189.      *
  190.      * @return int
  191.      */
  192.     public function getDatePlaced()
  193.     {
  194.         return $this->datePlaced;
  195.     }
  196.     /**
  197.      * Updates the date when user paid an an order, placed after following
  198.      * the cart recovery link from the e-mail.
  199.      *
  200.      * @param int $timestamp Date (UNIX timestamp)
  201.      *
  202.      * @return void
  203.      */
  204.     public function setDatePaid($timestamp)
  205.     {
  206.         $this->datePaid $timestamp;
  207.     }
  208.     /**
  209.      * Returns the date when user paid an an order, placed after following
  210.      * the cart recovery link from the e-mail.
  211.      *
  212.      * @return int
  213.      */
  214.     public function getDatePaid()
  215.     {
  216.         return $this->datePaid;
  217.     }
  218.     /**
  219.      * Associated the e-mail model with the abandoned cart that the e-mail was
  220.      * sent for.
  221.      *
  222.      * @param \XLite\Model\Order $order
  223.      */
  224.     public function setOrder(\XLite\Model\Order $order)
  225.     {
  226.         $this->order $order;
  227.         $this->setOrderHash(self::getHashForOrder($order));
  228.         $this->setProfileHash(self::getHashForProfile(
  229.             $order->getOrigProfile() ?: $order->getProfile()
  230.         ));
  231.     }
  232.     /**
  233.      * Returns the abandoned cart / order that the e-mail was sent for.
  234.      *
  235.      * @return \XLite\Model\Order
  236.      */
  237.     public function getOrder()
  238.     {
  239.         return $this->order;
  240.     }
  241.     /**
  242.      * Updates the unique string identifying the order that the e-mail was sent
  243.      * for.
  244.      *
  245.      * @param string $hash Unique identifier
  246.      *
  247.      * @return void
  248.      */
  249.     public function setOrderHash($hash)
  250.     {
  251.         $this->orderHash $hash;
  252.     }
  253.     /**
  254.      * Returns the unique string identifying the order that the e-mail was sent
  255.      * for.
  256.      *
  257.      * @return string
  258.      */
  259.     public function getOrderHash()
  260.     {
  261.         return $this->orderHash;
  262.     }
  263.     /**
  264.      * Updates the unique string identifying the user that the e-mail was sent
  265.      * for.
  266.      *
  267.      * @param string $hash Unique identifier
  268.      *
  269.      * @return void
  270.      */
  271.     public function setProfileHash($hash)
  272.     {
  273.         $this->profileHash $hash;
  274.     }
  275.     /**
  276.      * Returns the unique string identifying the user that the e-mail was sent
  277.      * for.
  278.      *
  279.      * @return string
  280.      */
  281.     public function getProfileHash()
  282.     {
  283.         return $this->profileHash;
  284.     }
  285.     /**
  286.      * @param integer $id
  287.      *
  288.      * @return $this
  289.      */
  290.     public function setReminderId($id)
  291.     {
  292.         $this->reminderId $id;
  293.         return $this;
  294.     }
  295.     /**
  296.      * @return int
  297.      */
  298.     public function getReminderId()
  299.     {
  300.         return $this->reminderId;
  301.     }
  302. }