modules/QSL/SpecialOffersBase/src/Model/SpecialOffer.php line 22

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright (c) 2011-present Qualiteam software Ltd. All rights reserved.
  4.  * See https://www.x-cart.com/license-agreement.html for license details.
  5.  */
  6. namespace QSL\SpecialOffersBase\Model;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * Special Offer model.
  10.  *
  11.  * It stores information on what special offer logic should be used and offer settings.
  12.  *
  13.  * @ORM\Entity (repositoryClass="\QSL\SpecialOffersBase\Model\Repo\SpecialOffer")
  14.  * @ORM\Table  (name="special_offers",
  15.  *      indexes={
  16.  *          @ORM\Index (name="offer_id", columns={"offer_id"}),
  17.  *          @ORM\Index (name="name", columns={"name"}),
  18.  *          @ORM\Index (name="position", columns={"position"}),
  19.  *          @ORM\Index (name="promoHome", columns={"promoHome"}),
  20.  *          @ORM\Index (name="promoOffers", columns={"promoOffers"}),
  21.  *          @ORM\Index (name="enabled", columns={"enabled"})
  22.  *      }
  23.  * )
  24.  */
  25. class SpecialOffer extends \XLite\Model\Base\I18n
  26. {
  27.     /**
  28.      * Unique identifier of the offer.
  29.      *
  30.      * @var integer
  31.      *
  32.      * @ORM\Id
  33.      * @ORM\GeneratedValue (strategy="AUTO")
  34.      * @ORM\Column         (type="integer")
  35.      */
  36.     protected $offer_id;
  37.     /**
  38.      * Offer Type.
  39.      *
  40.      * @var \QSL\SpecialOffersBase\Model\OfferType
  41.      *
  42.      * @ORM\ManyToOne  (targetEntity="QSL\SpecialOffersBase\Model\OfferType", inversedBy="specialOffers")
  43.      * @ORM\JoinColumn (name="type_id", referencedColumnName="type_id", onDelete="CASCADE")
  44.      */
  45.     protected $offerType// when the offer type is deleted, the operation cascades to all realted offers (via SQL)
  46.     /**
  47.      * Administrative name of the special offer.
  48.      *
  49.      * @var string
  50.      * @ORM\Column (type="string", length=255)
  51.      */
  52.     protected $name;
  53.     /**
  54.      * Position of the exit offer among other ones in the list.
  55.      *
  56.      * @var integer
  57.      *
  58.      * @ORM\Column (type="integer")
  59.      */
  60.     protected $position 0;
  61.     /**
  62.      * Whether the offer is enabled, or not.
  63.      *
  64.      * @var boolean
  65.      *
  66.      * @ORM\Column (type="boolean")
  67.      */
  68.     protected $enabled true;
  69.     /**
  70.      * Date range (begin)
  71.      *
  72.      * @var   integer
  73.      *
  74.      * @ORM\Column (type="integer", options={ "unsigned": true })
  75.      */
  76.     protected $activeFrom 0;
  77.     /**
  78.      * Date range (end)
  79.      *
  80.      * @var   integer
  81.      *
  82.      * @ORM\Column (type="integer", options={ "unsigned": true })
  83.      */
  84.     protected $activeTill 0;
  85.     /**
  86.      * Identifiers of other special offers that this offer may not apply together on the same item.
  87.      *
  88.      * @var array
  89.      *
  90.      * @ORM\Column (type="array", nullable=true)
  91.      */
  92.     protected $exclusions = [];
  93.     /**
  94.      * One-to-one relation with special_offer_images table
  95.      *
  96.      * @var \QSL\SpecialOffersBase\Model\Image\SpecialOffer\Image
  97.      *
  98.      * @ORM\OneToOne  (targetEntity="QSL\SpecialOffersBase\Model\Image\SpecialOffer\Image", mappedBy="specialOffer", cascade={"all"})
  99.      */
  100.     protected $image;
  101.     /**
  102.      * Whether the short promo text and image is displayed on the home page, or not.
  103.      *
  104.      * @var boolean
  105.      *
  106.      * @ORM\Column (type="boolean")
  107.      */
  108.     protected $promoHome true;
  109.     /**
  110.      * Whether the short promo text and image is displayed on Special Offers page.
  111.      *
  112.      * @var boolean
  113.      *
  114.      * @ORM\Column (type="boolean")
  115.      */
  116.     protected $promoOffers true;
  117.     /**
  118.      * @var \Doctrine\Common\Collections\Collection
  119.      *
  120.      * @ORM\OneToMany (targetEntity="QSL\SpecialOffersBase\Model\SpecialOfferTranslation", mappedBy="owner", cascade={"all"})
  121.      */
  122.     protected $translations;
  123.     /**
  124.      * Get the model ID.
  125.      *
  126.      * @return integer
  127.      */
  128.     public function getId()
  129.     {
  130.         return $this->getBrandId();
  131.     }
  132.     /**
  133.      * Check if this offer can apply on an item together with the specified offer.
  134.      *
  135.      * @param integer $otherOfferId Identifier of the other offer to check.
  136.      *
  137.      * @return boolean
  138.      */
  139.     public function canApplyTogether($otherOfferId)
  140.     {
  141.         return !(in_array($otherOfferId$this->exclusions));
  142.     }
  143.     /**
  144.      * Since Doctrine lifecycle callbacks do not allow to modify associations, we've added this method
  145.      *
  146.      * @param string $type Type of current operation
  147.      *
  148.      * @return void
  149.      */
  150.     public function prepareEntityBeforeCommit($type)
  151.     {
  152.         if ($type == static::ACTION_UPDATE && !$this->getOfferType()->hasAllRequiredClasses()) {
  153.             $this->setEnabled(false);
  154.         }
  155.         parent::prepareEntityBeforeCommit($type);
  156.     }
  157.     /**
  158.      * Returns the offer identifier.
  159.      *
  160.      * @return integer
  161.      */
  162.     public function getOfferId()
  163.     {
  164.         return $this->offer_id;
  165.     }
  166.     /**
  167.      * Sets the administrative name for the offer type.
  168.      *
  169.      * @param string $name Administrative name
  170.      *
  171.      * @return SpecialOffer
  172.      */
  173.     public function setName($name)
  174.     {
  175.         $this->name $name;
  176.         return $this;
  177.     }
  178.     /**
  179.      * Returns the administrative name for the offer type.
  180.      *
  181.      * @return string
  182.      */
  183.     public function getName()
  184.     {
  185.         return $this->name;
  186.     }
  187.     /**
  188.      * Sets the position of the offer among others.
  189.      *
  190.      * @param integer $position Position
  191.      *
  192.      * @return SpecialOffer
  193.      */
  194.     public function setPosition($position)
  195.     {
  196.         $this->position $position;
  197.         return $this;
  198.     }
  199.     /**
  200.      * Returns the position of the offer among others.
  201.      *
  202.      * @return integer
  203.      */
  204.     public function getPosition()
  205.     {
  206.         return $this->position;
  207.     }
  208.     /**
  209.      * Confgiures whether the special offer is enabled, or disabled.
  210.      *
  211.      * @param boolean $enabled New state
  212.      *
  213.      * @return SpecialOffer
  214.      */
  215.     public function setEnabled($enabled)
  216.     {
  217.         $this->enabled $enabled;
  218.         return $this;
  219.     }
  220.     /**
  221.      * Checks if the special offer is enabled, or not.
  222.      *
  223.      * @return boolean
  224.      */
  225.     public function getEnabled()
  226.     {
  227.         return $this->enabled;
  228.     }
  229.     /**
  230.      * Sets the date that the offer is active from (timestamp).
  231.      *
  232.      * @param integer $activeFrom Date (timestamp)
  233.      *
  234.      * @return SpecialOffer
  235.      */
  236.     public function setActiveFrom($activeFrom)
  237.     {
  238.         $this->activeFrom intval($activeFrom);
  239.         return $this;
  240.     }
  241.     /**
  242.      * Returns the date that the offer is active from (timestamp).
  243.      *
  244.      * @return integer
  245.      */
  246.     public function getActiveFrom()
  247.     {
  248.         return $this->activeFrom;
  249.     }
  250.     /**
  251.      * Configures the date that the offer is active till (timestamp).
  252.      *
  253.      * @param integer $activeTill Date (timestamp)
  254.      *
  255.      * @return SpecialOffer
  256.      */
  257.     public function setActiveTill($activeTill)
  258.     {
  259.         $this->activeTill intval($activeTill);
  260.         return $this;
  261.     }
  262.     /**
  263.      * Returns the date that the offer is active till (timestamp).
  264.      *
  265.      * @return integer
  266.      */
  267.     public function getActiveTill()
  268.     {
  269.         return $this->activeTill;
  270.     }
  271.     /**
  272.      * Configures the list of special offers that this one cannot be combined with.
  273.      *
  274.      * @param array $exclusions Special offers
  275.      *
  276.      * @return SpecialOffer
  277.      */
  278.     public function setExclusions($exclusions)
  279.     {
  280.         $this->exclusions $exclusions;
  281.         return $this;
  282.     }
  283.     /**
  284.      * Returns the list of special offers that this one cannot be combined with.
  285.      *
  286.      * @return array
  287.      */
  288.     public function getExclusions()
  289.     {
  290.         return $this->exclusions;
  291.     }
  292.     /**
  293.      * Configures whether the promo should be displayed on the home page.
  294.      *
  295.      * @param boolean $promoHome State
  296.      *
  297.      * @return SpecialOffer
  298.      */
  299.     public function setPromoHome($promoHome)
  300.     {
  301.         $this->promoHome $promoHome;
  302.         return $this;
  303.     }
  304.     /**
  305.      * Checks if the promo should be displayed on the home page.
  306.      *
  307.      * @return boolean
  308.      */
  309.     public function getPromoHome()
  310.     {
  311.         return $this->promoHome;
  312.     }
  313.     /**
  314.      * Configures whether the promo should be displayed on the Special Offers page.
  315.      *
  316.      * @param boolean $promoOffers State
  317.      *
  318.      * @return SpecialOffer
  319.      */
  320.     public function setPromoOffers($promoOffers)
  321.     {
  322.         $this->promoOffers $promoOffers;
  323.         return $this;
  324.     }
  325.     /**
  326.      * Checks if the promo should be displayed on the Special Offers page.
  327.      *
  328.      * @return boolean
  329.      */
  330.     public function getPromoOffers()
  331.     {
  332.         return $this->promoOffers;
  333.     }
  334.     /**
  335.      * Sets the type for the special offer.
  336.      *
  337.      * @param \QSL\SpecialOffersBase\Model\OfferType $offerType Offer type
  338.      *
  339.      * @return SpecialOffer
  340.      */
  341.     public function setOfferType(\QSL\SpecialOffersBase\Model\OfferType $offerType null)
  342.     {
  343.         $this->offerType $offerType;
  344.         return $this;
  345.     }
  346.     /**
  347.      * Returns the type of the special offer.
  348.      *
  349.      * @return \QSL\SpecialOffersBase\Model\OfferType
  350.      */
  351.     public function getOfferType()
  352.     {
  353.         return $this->offerType;
  354.     }
  355.     /**
  356.      * Associates the special offer with an image.
  357.      *
  358.      * @param \QSL\SpecialOffersBase\Model\Image\SpecialOffer\Image $image
  359.      *
  360.      * @return SpecialOffer
  361.      */
  362.     public function setImage(\QSL\SpecialOffersBase\Model\Image\SpecialOffer\Image $image null)
  363.     {
  364.         $this->image $image;
  365.         return $this;
  366.     }
  367.     /**
  368.      * Returns the special offer image.
  369.      *
  370.      * @return \QSL\SpecialOffersBase\Model\Image\SpecialOffer\Image
  371.      */
  372.     public function getImage()
  373.     {
  374.         return $this->image;
  375.     }
  376.     // {{{ Translation Getters / setters
  377.     /**
  378.      * @return string
  379.      */
  380.     public function getTitle()
  381.     {
  382.         return $this->getTranslationField(__FUNCTION__);
  383.     }
  384.     /**
  385.      * @param string $title
  386.      *
  387.      * @return \XLite\Model\Base\Translation
  388.      */
  389.     public function setTitle($title)
  390.     {
  391.         return $this->setTranslationField(__FUNCTION__$title);
  392.     }
  393.     /**
  394.      * @return string
  395.      */
  396.     public function getShortPromoText()
  397.     {
  398.         return $this->getTranslationField(__FUNCTION__);
  399.     }
  400.     /**
  401.      * @param string $shortPromoText
  402.      *
  403.      * @return \XLite\Model\Base\Translation
  404.      */
  405.     public function setShortPromoText($shortPromoText)
  406.     {
  407.         return $this->setTranslationField(__FUNCTION__$shortPromoText);
  408.     }
  409.     /**
  410.      * @return string
  411.      */
  412.     public function getDescription()
  413.     {
  414.         return $this->getTranslationField(__FUNCTION__);
  415.     }
  416.     /**
  417.      * @param string $description
  418.      *
  419.      * @return \XLite\Model\Base\Translation
  420.      */
  421.     public function setDescription($description)
  422.     {
  423.         return $this->setTranslationField(__FUNCTION__$description);
  424.     }
  425.     /**
  426.      * @return string
  427.      */
  428.     public function getCartPromoText()
  429.     {
  430.         return $this->getTranslationField(__FUNCTION__);
  431.     }
  432.     /**
  433.      * @param string $cartPromoText
  434.      *
  435.      * @return \XLite\Model\Base\Translation
  436.      */
  437.     public function setCartPromoText($cartPromoText)
  438.     {
  439.         return $this->setTranslationField(__FUNCTION__$cartPromoText);
  440.     }
  441.     /**
  442.      * @return string
  443.      */
  444.     public function getCartAppliedText()
  445.     {
  446.         return $this->getTranslationField(__FUNCTION__);
  447.     }
  448.     /**
  449.      * @param string $cartAppliedText
  450.      *
  451.      * @return \XLite\Model\Base\Translation
  452.      */
  453.     public function setCartAppliedText($cartAppliedText)
  454.     {
  455.         return $this->setTranslationField(__FUNCTION__$cartAppliedText);
  456.     }
  457.     // }}}
  458. }