modules/CDev/FeaturedProducts/src/Model/FeaturedProduct.php line 120

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 CDev\FeaturedProducts\Model;
  7. use ApiPlatform\Core\Annotation as ApiPlatform;
  8. use CDev\FeaturedProducts\API\Endpoint\FeaturedProduct\DTO\CategoryFeaturedInput;
  9. use CDev\FeaturedProducts\API\Endpoint\FeaturedProduct\DTO\CategoryFeaturedOutput;
  10. use CDev\FeaturedProducts\Controller\API\FeaturedProduct\DeleteCategoryFeatured;
  11. use CDev\FeaturedProducts\Controller\API\FeaturedProduct\DeleteFrontPageFeatured;
  12. use Doctrine\ORM\Mapping as ORM;
  13. /**
  14.  * Featured Product
  15.  *
  16.  * @ORM\Entity
  17.  * @ORM\Table (name="featured_products",
  18.  *      uniqueConstraints={
  19.  *             @ORM\UniqueConstraint (name="pair", columns={"category_id","product_id"})
  20.  *      }
  21.  * )
  22.  * @ApiPlatform\ApiResource(
  23.  *     attributes={"pagination_enabled"=false},
  24.  *     shortName="Featured Product",
  25.  *     input=CategoryFeaturedInput::class,
  26.  *     output=CategoryFeaturedOutput::class,
  27.  *     itemOperations={
  28.  *         "get"={
  29.  *             "method"="GET",
  30.  *             "path"="/categories/{category_id}/featured/{product_id}.{_format}",
  31.  *             "identifiers"={"category_id", "product_id"},
  32.  *             "requirements"={"category_id"="\d+", "product_id"="\d+"},
  33.  *             "openapi_context"={
  34.  *                  "summary"="Retrieve a featured product from a category",
  35.  *                  "parameters"={
  36.  *                      {"name"="category_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  37.  *                      {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  38.  *                  }
  39.  *             },
  40.  *          },
  41.  *         "delete_category_featured"={
  42.  *             "method"="DELETE",
  43.  *             "path"="/categories/{category_id}/featured/{product_id}.{_format}",
  44.  *             "identifiers"={"category_id", "product_id"},
  45.  *             "requirements"={"category_id"="\d+", "product_id"="\d+"},
  46.  *             "controller"=DeleteCategoryFeatured::class,
  47.  *             "read"=false,
  48.  *             "openapi_context"={
  49.  *                  "summary"="Delete a featured product from a category",
  50.  *                  "parameters"={
  51.  *                      {"name"="category_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  52.  *                      {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  53.  *                  }
  54.  *             },
  55.  *         },
  56.  *         "delete_front_page_featured"={
  57.  *             "method"="DELETE",
  58.  *             "path"="/front_page/featured/{product_id}.{_format}",
  59.  *             "identifiers"={"category_id", "product_id"},
  60.  *             "requirements"={"product_id"="\d+"},
  61.  *             "controller"=DeleteFrontPageFeatured::class,
  62.  *             "read"=false,
  63.  *             "openapi_context"={
  64.  *                  "summary"="Delete a featured product from the front page",
  65.  *                  "parameters"={
  66.  *                      {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  67.  *                  }
  68.  *             },
  69.  *         },
  70.  *     },
  71.  *     collectionOperations={
  72.  *         "add_category_featured"={
  73.  *             "method"="POST",
  74.  *             "path"="/categories/{category_id}/featured.{_format}",
  75.  *             "identifiers"={"category_id", "product_id"},
  76.  *             "requirements"={"category_id"="\d+"},
  77.  *             "openapi_context"={
  78.  *                 "summary"="Add a featured product to a category",
  79.  *                 "parameters"={
  80.  *                     {"name"="category_id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  81.  *                 }
  82.  *             },
  83.  *         },
  84.  *         "get_category_featured"={
  85.  *             "method"="GET",
  86.  *             "path"="/categories/{category_id}/featured.{_format}",
  87.  *             "identifiers"={"category_id", "product_id"},
  88.  *             "requirements"={"category_id"="\d+"},
  89.  *             "openapi_context"={
  90.  *                  "summary"="Retrieve a list of featured products from a category",
  91.  *                  "parameters"={
  92.  *                     {"name"="category_id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  93.  *                 }
  94.  *             },
  95.  *         },
  96.  *         "add_front_page_featured"={
  97.  *             "method"="POST",
  98.  *             "path"="/front_page/featured.{_format}",
  99.  *             "identifiers"={"category_id", "product_id"},
  100.  *             "openapi_context"={
  101.  *                 "summary"="Add a featured product to the front page",
  102.  *             },
  103.  *         },
  104.  *         "get_front_page_featured"={
  105.  *             "method"="GET",
  106.  *             "path"="/front_page/featured.{_format}",
  107.  *             "identifiers"={"category_id", "product_id"},
  108.  *             "openapi_context"={
  109.  *                  "summary"="Retrieve a list of featured products from the front page",
  110.  *             },
  111.  *         },
  112.  *     }
  113.  * )
  114.  */
  115. class FeaturedProduct extends \XLite\Model\AEntity
  116. {
  117.     /**
  118.      * Session cell name
  119.      */
  120.     public const SESSION_CELL_NAME 'featuredProductsSearch';
  121.     /**
  122.      * Product + category link unique id
  123.      *
  124.      * @var integer
  125.      *
  126.      * @ORM\Id
  127.      * @ORM\GeneratedValue (strategy="AUTO")
  128.      * @ORM\Column         (type="integer")
  129.      */
  130.     protected $id;
  131.     /**
  132.      * Sort position
  133.      *
  134.      * @var integer
  135.      *
  136.      * @ORM\Column (type="integer")
  137.      */
  138.     protected $orderBy 0;
  139.     /**
  140.      * Product (relation)
  141.      *
  142.      * @var \XLite\Model\Product
  143.      *
  144.      * @ORM\ManyToOne  (targetEntity="XLite\Model\Product", inversedBy="featuredProducts")
  145.      * @ORM\JoinColumn (name="product_id", referencedColumnName="product_id", onDelete="CASCADE")
  146.      */
  147.     protected $product;
  148.     /**
  149.      * Category (relation)
  150.      *
  151.      * @var \XLite\Model\Category
  152.      *
  153.      * @ORM\ManyToOne  (targetEntity="XLite\Model\Category", inversedBy="featuredProducts")
  154.      * @ORM\JoinColumn (name="category_id", referencedColumnName="category_id", onDelete="CASCADE")
  155.      */
  156.     protected $category;
  157.     /**
  158.      * SKU getter
  159.      *
  160.      * @return string
  161.      */
  162.     public function getSku()
  163.     {
  164.         return $this->getProduct()->getSku();
  165.     }
  166.     /**
  167.      * Price getter
  168.      *
  169.      * @return double
  170.      */
  171.     public function getPrice()
  172.     {
  173.         return $this->getProduct()->getPrice();
  174.     }
  175.     /**
  176.      * Amount getter
  177.      *
  178.      * @return integer
  179.      */
  180.     public function getAmount()
  181.     {
  182.         return $this->getProduct()->getPublicAmount();
  183.     }
  184.     /**
  185.      * Get position
  186.      *
  187.      * @return integer
  188.      */
  189.     public function getPosition()
  190.     {
  191.         return $this->getOrderBy();
  192.     }
  193.     /**
  194.      * Set position
  195.      *
  196.      * @param integer $position Category position
  197.      *
  198.      * @return void
  199.      */
  200.     public function setPosition($position)
  201.     {
  202.         return $this->setOrderBy($position);
  203.     }
  204.     /**
  205.      * Get id
  206.      *
  207.      * @return integer
  208.      */
  209.     public function getId()
  210.     {
  211.         return $this->id;
  212.     }
  213.     /**
  214.      * Set orderBy
  215.      *
  216.      * @param integer $orderBy
  217.      * @return FeaturedProduct
  218.      */
  219.     public function setOrderBy($orderBy)
  220.     {
  221.         $this->orderBy $orderBy;
  222.         return $this;
  223.     }
  224.     /**
  225.      * Get orderBy
  226.      *
  227.      * @return integer
  228.      */
  229.     public function getOrderBy()
  230.     {
  231.         return $this->orderBy;
  232.     }
  233.     /**
  234.      * Set product
  235.      *
  236.      * @param \XLite\Model\Product $product
  237.      * @return FeaturedProduct
  238.      */
  239.     public function setProduct(\XLite\Model\Product $product null)
  240.     {
  241.         $this->product $product;
  242.         return $this;
  243.     }
  244.     /**
  245.      * Get product
  246.      *
  247.      * @return \XLite\Model\Product
  248.      */
  249.     public function getProduct()
  250.     {
  251.         return $this->product;
  252.     }
  253.     /**
  254.      * Set category
  255.      *
  256.      * @param \XLite\Model\Category $category
  257.      * @return FeaturedProduct
  258.      */
  259.     public function setCategory(\XLite\Model\Category $category null)
  260.     {
  261.         $this->category $category;
  262.         return $this;
  263.     }
  264.     /**
  265.      * Get category
  266.      *
  267.      * @return \XLite\Model\Category
  268.      */
  269.     public function getCategory()
  270.     {
  271.         return $this->category;
  272.     }
  273. }