classes/XLite/Model/TaxClass.php line 57

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 XLite\Model;
  7. use ApiPlatform\Core\Annotation as ApiPlatform;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use XLite\API\Endpoint\TaxClass\DTO\TaxClassInput;
  10. use XLite\API\Endpoint\TaxClass\DTO\TaxClassOutput;
  11. use XLite\API\Filter\AlphabeticalOrderFilter;
  12. /**
  13.  * Tax class
  14.  *
  15.  * @ORM\Entity
  16.  * @ORM\Table  (name="tax_classes")
  17.  * @ApiPlatform\ApiResource(
  18.  *     shortName="Tax Class",
  19.  *     input=TaxClassInput::class,
  20.  *     output=TaxClassOutput::class,
  21.  *     itemOperations={
  22.  *         "get"={
  23.  *             "method"="GET",
  24.  *             "path"="/tax_classes/{id}",
  25.  *             "identifiers"={"id"},
  26.  *         },
  27.  *         "put"={
  28.  *             "method"="PUT",
  29.  *             "path"="/tax_classes/{id}",
  30.  *             "identifiers"={"id"},
  31.  *         },
  32.  *         "delete"={
  33.  *             "method"="DELETE",
  34.  *             "path"="/tax_classes/{id}",
  35.  *             "identifiers"={"id"},
  36.  *         }
  37.  *     },
  38.  *     collectionOperations={
  39.  *         "get"={
  40.  *             "method"="GET",
  41.  *             "path"="/tax_classes",
  42.  *             "identifiers"={"id"},
  43.  *         },
  44.  *         "post"={
  45.  *             "method"="POST",
  46.  *             "path"="/tax_classes",
  47.  *             "identifiers"={"id"},
  48.  *         }
  49.  *     }
  50.  * )
  51.  * @ApiPlatform\ApiFilter(AlphabeticalOrderFilter::class, properties={"name"="ASC"})
  52.  */
  53. class TaxClass extends \XLite\Model\Base\I18n
  54. {
  55.     /**
  56.      * ID
  57.      *
  58.      * @var integer
  59.      *
  60.      * @ORM\Id
  61.      * @ORM\GeneratedValue (strategy="AUTO")
  62.      * @ORM\Column         (type="integer", options={ "unsigned": true })
  63.      */
  64.     protected $id;
  65.     /**
  66.      * Position
  67.      *
  68.      * @var   integer
  69.      * @see   ____var_see____
  70.      * @since 1.0.0
  71.      *
  72.      * @ORM\Column (type="integer")
  73.      */
  74.     protected $position 0;
  75.     /**
  76.      * @var \Doctrine\Common\Collections\Collection
  77.      *
  78.      * @ORM\OneToMany (targetEntity="XLite\Model\TaxClassTranslation", mappedBy="owner", cascade={"all"})
  79.      */
  80.     protected $translations;
  81.     /**
  82.      * Return number of products associated with the category
  83.      *
  84.      * @return integer
  85.      */
  86.     public function getProductsCount()
  87.     {
  88.         return $this->getProducts(nulltrue);
  89.     }
  90.     /**
  91.      * Return products list
  92.      *
  93.      * @param \XLite\Core\CommonCell $cnd       Search condition OPTIONAL
  94.      * @param boolean                $countOnly Return items list or only its size OPTIONAL
  95.      *
  96.      * @return array|integer
  97.      */
  98.     public function getProducts(\XLite\Core\CommonCell $cnd null$countOnly false)
  99.     {
  100.         if (!isset($cnd)) {
  101.             $cnd = new \XLite\Core\CommonCell();
  102.         }
  103.         // Main condition for this search
  104.         $cnd->{\XLite\Model\Repo\Product::P_TAX_CLASS} = $this;
  105.         return \XLite\Core\Database::getRepo('XLite\Model\Product')->search($cnd$countOnly);
  106.     }
  107.     /**
  108.      * Get id
  109.      *
  110.      * @return integer
  111.      */
  112.     public function getId()
  113.     {
  114.         return $this->id;
  115.     }
  116.     /**
  117.      * Set position
  118.      *
  119.      * @param integer $position
  120.      * @return TaxClass
  121.      */
  122.     public function setPosition($position)
  123.     {
  124.         $this->position $position;
  125.         return $this;
  126.     }
  127.     /**
  128.      * Get position
  129.      *
  130.      * @return integer
  131.      */
  132.     public function getPosition()
  133.     {
  134.         return $this->position;
  135.     }
  136. }