modules/CDev/Wholesale/src/Model/WholesalePrice.php line 93

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\Wholesale\Model;
  7. use ApiPlatform\Core\Annotation as ApiPlatform;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use CDev\Wholesale\API\Endpoint\ProductWholesalePrice\DTO\ProductWholesalePriceInput as Input;
  10. use CDev\Wholesale\API\Endpoint\ProductWholesalePrice\DTO\ProductWholesalePriceOutput as Output;
  11. /**
  12.  * Wholesale price model (product)
  13.  *
  14.  * @ORM\Entity
  15.  * @ORM\Table  (name="wholesale_prices",
  16.  *      indexes={
  17.  *          @ORM\Index (name="range", columns={"product_id", "membership_id", "quantityRangeBegin", "quantityRangeEnd"})
  18.  *      }
  19.  * )
  20.  * @ApiPlatform\ApiResource(
  21.  *     shortName="Product Wholesale Price",
  22.  *     input=Input::class,
  23.  *     output=Output::class,
  24.  *     itemOperations={
  25.  *          "get"={
  26.  *              "method"="GET",
  27.  *              "path"="/products/{product_id}/wholesale_prices/{id}.{_format}",
  28.  *              "identifiers"={"product_id", "id"},
  29.  *              "requirements"={"product_id"="\d+", "id"="\d+"},
  30.  *              "openapi_context"={
  31.  *                  "parameters"={
  32.  *                      {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  33.  *                      {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  34.  *                  }
  35.  *              }
  36.  *          },
  37.  *          "put"={
  38.  *              "method"="PUT",
  39.  *              "path"="/products/{product_id}/wholesale_prices/{id}.{_format}",
  40.  *              "identifiers"={"product_id", "id"},
  41.  *              "requirements"={"product_id"="\d+", "id"="\d+"},
  42.  *              "openapi_context"={
  43.  *                  "parameters"={
  44.  *                      {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  45.  *                      {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  46.  *                  }
  47.  *              }
  48.  *          },
  49.  *          "delete"={
  50.  *              "method"="DELETE",
  51.  *              "path"="/products/{product_id}/wholesale_prices/{id}.{_format}",
  52.  *              "identifiers"={"product_id", "id"},
  53.  *              "requirements"={"product_id"="\d+", "id"="\d+"},
  54.  *              "openapi_context"={
  55.  *                  "parameters"={
  56.  *                      {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  57.  *                      {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  58.  *                  }
  59.  *              }
  60.  *          }
  61.  *     },
  62.  *     collectionOperations={
  63.  *          "get"={
  64.  *              "method"="GET",
  65.  *              "path"="/products/{product_id}/wholesale_prices.{_format}",
  66.  *              "identifiers"={"product_id"},
  67.  *              "requirements"={"product_id"="\d+"},
  68.  *              "openapi_context"={
  69.  *                  "parameters"={
  70.  *                      {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  71.  *                  },
  72.  *              }
  73.  *          },
  74.  *          "post"={
  75.  *              "method"="POST",
  76.  *              "path"="/products/{product_id}/wholesale_prices.{_format}",
  77.  *              "controller"="xcart.api.cdev.wholesale.product_wholesale_price.controller",
  78.  *              "identifiers"={"product_id"},
  79.  *              "requirements"={"product_id"="\d+"},
  80.  *              "openapi_context"={
  81.  *                  "parameters"={
  82.  *                      {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  83.  *                  }
  84.  *              }
  85.  *          }
  86.  *     }
  87.  * )
  88.  */
  89. class WholesalePrice extends \CDev\Wholesale\Model\Base\AWholesalePrice
  90. {
  91.     /**
  92.      * Relation to a product entity
  93.      *
  94.      * @var \XLite\Model\Product
  95.      *
  96.      * @ORM\ManyToOne  (targetEntity="XLite\Model\Product", inversedBy="wholesalePrices")
  97.      * @ORM\JoinColumn (name="product_id", referencedColumnName="product_id", onDelete="CASCADE")
  98.      */
  99.     protected $product;
  100.     /**
  101.      * Return owner
  102.      *
  103.      * @return \XLite\Model\Product
  104.      */
  105.     public function getOwner()
  106.     {
  107.         return $this->getProduct();
  108.     }
  109.     /**
  110.      * Set owner
  111.      *
  112.      * @param \XLite\Model\Product $owner Owner
  113.      *
  114.      * @return static
  115.      */
  116.     public function setOwner($owner)
  117.     {
  118.         return $this->setProduct($owner);
  119.     }
  120.     /**
  121.      * @inheritdoc
  122.      */
  123.     public function getOwnerPrice()
  124.     {
  125.         return $this->getOwner()
  126.             ? $this->getOwner()->getPrice()
  127.             : null;
  128.     }
  129.     /**
  130.      * Get id
  131.      *
  132.      * @return integer
  133.      */
  134.     public function getId()
  135.     {
  136.         return $this->id;
  137.     }
  138.     /**
  139.      * @inheritdoc
  140.      */
  141.     public function setPrice($price)
  142.     {
  143.         $this->price $price;
  144.         return $this;
  145.     }
  146.     /**
  147.      * @inheritdoc
  148.      */
  149.     public function getPrice()
  150.     {
  151.         return $this->price;
  152.     }
  153.     /**
  154.      * Set product
  155.      *
  156.      * @param \XLite\Model\Product $product
  157.      * @return static
  158.      */
  159.     public function setProduct(\XLite\Model\Product $product null)
  160.     {
  161.         $this->product $product;
  162.         return $this;
  163.     }
  164.     /**
  165.      * Get product
  166.      *
  167.      * @return \XLite\Model\Product
  168.      */
  169.     public function getProduct()
  170.     {
  171.         return $this->product;
  172.     }
  173. }