modules/QSL/MyWishlist/src/Model/WishlistLink.php line 18

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\MyWishlist\Model;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * Wishlist link to snapshot product item model
  10.  *
  11.  * @ORM\Entity
  12.  * @ORM\Table  (name="wishlist_link")
  13.  */
  14. class WishlistLink extends \XLite\Model\AEntity
  15. {
  16.     /**
  17.      * Wishlist link identificator
  18.      *
  19.      * @var mixed
  20.      *
  21.      * @ORM\Id
  22.      * @ORM\GeneratedValue (strategy="AUTO")
  23.      * @ORM\Column         (type="integer")
  24.      */
  25.     protected $id;
  26.     /**
  27.      * Product position in the wishlist
  28.      *
  29.      * @var integer
  30.      *
  31.      * @ORM\Column (type="integer", length=11, nullable=false)
  32.      */
  33.     protected $orderby 0;
  34.     /**
  35.      * Date of link creation
  36.      *
  37.      * @var integer
  38.      *
  39.      * @ORM\Column (type="integer")
  40.      */
  41.     protected $creationDate 0;
  42.     /**
  43.      * Relation to a product snapshot entity
  44.      *
  45.      * @var \QSL\MyWishlist\Model\WishlistProductRecord
  46.      *
  47.      * @ORM\OneToOne (targetEntity="QSL\MyWishlist\Model\WishlistProductRecord", mappedBy="wishlistLink", cascade={"all"}, fetch="EAGER")
  48.      */
  49.     protected $snapshot;
  50.     /**
  51.      * Relation to a parent product entity
  52.      *
  53.      * @var \XLite\Model\Product
  54.      *
  55.      * @ORM\ManyToOne  (targetEntity="XLite\Model\Product", inversedBy="wishlistLinks", cascade={"merge","detach"})
  56.      * @ORM\JoinColumn (name="parent_product_id", referencedColumnName="product_id", onDelete="CASCADE")
  57.      */
  58.     protected $parentProduct;
  59.     /**
  60.      * Relation to a wishlist entity
  61.      *
  62.      * @var \QSL\MyWishlist\Model\Wishlist
  63.      *
  64.      * @ORM\ManyToOne (targetEntity="QSL\MyWishlist\Model\Wishlist", inversedBy="wishlistLinks")
  65.      * @ORM\JoinColumn (name="wishlist_id", referencedColumnName="id", onDelete="CASCADE")
  66.      */
  67.     protected $wishlist;
  68.     public function getOrderby()
  69.     {
  70.         return $this->orderby;
  71.     }
  72.     public function setOrderby($value)
  73.     {
  74.         $this->orderby $value;
  75.         return $this;
  76.     }
  77.     public function getCreationDate()
  78.     {
  79.         return $this->creationDate;
  80.     }
  81.     public function setCreationDate($value)
  82.     {
  83.         $this->creationDate $value;
  84.         return $this;
  85.     }
  86.     public function getSnapshot()
  87.     {
  88.         return $this->snapshot;
  89.     }
  90.     public function setSnapshot($value)
  91.     {
  92.         $this->snapshot $value;
  93.         return $this;
  94.     }
  95.     public function getParentProduct()
  96.     {
  97.         return $this->parentProduct;
  98.     }
  99.     public function setParentProduct($value)
  100.     {
  101.         $this->parentProduct $value;
  102.         return $value;
  103.     }
  104.     public function getWishlist()
  105.     {
  106.         return $this->wishlist;
  107.     }
  108.     public function setWishlist($value)
  109.     {
  110.         $this->wishlist $value;
  111.         return $this;
  112.     }
  113.     /**
  114.      * Check if the provided product is in this link
  115.      *
  116.      * @param \XLite\Model\Product $product
  117.      *
  118.      * @return boolean
  119.      */
  120.     public function hasProduct(\XLite\Model\Product $product)
  121.     {
  122.         return $this->getParentProduct() && $product->getProductId() === $this->getParentProduct()->getProductId();
  123.     }
  124.     /**
  125.      * We copy title/description into the special wishlist product record
  126.      *
  127.      * @param \XLite\Model\Product $product
  128.      *
  129.      * @return void
  130.      */
  131.     public function createSnapshot(\XLite\Model\Product $product)
  132.     {
  133.         $this->setParentProduct($product);
  134.         $this->setCreationDate(\XLite\Core\Converter::time());
  135.         $this->setSnapshot(new \QSL\MyWishlist\Model\WishlistProductRecord(['wishlistLink' => $this]));
  136.         $this->getSnapshot()->generateProductRecord($product);
  137.     }
  138.     /**
  139.      * Return new product object with the name and
  140.      *
  141.      * @return \XLite\Model\Product
  142.      */
  143.     public function getSnapshotProduct()
  144.     {
  145.         return $this->getSnapshot()->getSnapshotProduct();
  146.     }
  147. }