modules/CDev/Wholesale/src/Module/XC/ProductVariants/Model/ProductVariantWholesalePrice.php line 105

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\Module\XC\ProductVariants\Model;
  7. use ApiPlatform\Core\Annotation as ApiPlatform;
  8. use CDev\Wholesale\Module\XC\ProductVariants\API\Endpoint\ProductVariantWholesalePrice\DTO\ProductVariantWholesalePriceInput as Input;
  9. use CDev\Wholesale\Module\XC\ProductVariants\API\Endpoint\ProductVariantWholesalePrice\DTO\ProductVariantWholesalePriceOutput as Output;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use XCart\Extender\Mapping\Extender;
  12. /**
  13.  * @ORM\Entity
  14.  * @ORM\Table  (name="product_variant_wholesale_prices",
  15.  *      indexes={
  16.  *          @ORM\Index (name="range", columns={"product_variant_id", "membership_id", "quantityRangeBegin", "quantityRangeEnd"})
  17.  *      }
  18.  * )
  19.  *
  20.  * @ApiPlatform\ApiResource(
  21.  *     shortName="Product Variant Wholesale Price",
  22.  *     input=Input::class,
  23.  *     output=Output::class,
  24.  *     itemOperations={
  25.  *          "get"={
  26.  *              "method"="GET",
  27.  *              "path"="/products/{product_id}/variants/{variant_id}/wholesale_prices/{id}.{_format}",
  28.  *              "identifiers"={"product_id", "variant_id", "id"},
  29.  *              "requirements"={"product_id"="\d+", "variant_id"="\d+", "id"="\d+"},
  30.  *              "openapi_context"={
  31.  *                  "summary"="Retrieve a wholesale price from a product variant",
  32.  *                  "parameters"={
  33.  *                      {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  34.  *                      {"name"="variant_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  35.  *                      {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  36.  *                  }
  37.  *              }
  38.  *          },
  39.  *          "put"={
  40.  *              "method"="PUT",
  41.  *              "path"="/products/{product_id}/variants/{variant_id}/wholesale_prices/{id}.{_format}",
  42.  *              "identifiers"={"product_id", "variant_id", "id"},
  43.  *              "requirements"={"product_id"="\d+", "variant_id"="\d+", "id"="\d+"},
  44.  *              "openapi_context"={
  45.  *                  "summary"="Update a wholesale price of a product variant",
  46.  *                  "parameters"={
  47.  *                      {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  48.  *                      {"name"="variant_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  49.  *                      {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  50.  *                  }
  51.  *              }
  52.  *          },
  53.  *          "delete"={
  54.  *              "method"="DELETE",
  55.  *              "path"="/products/{product_id}/variants/{variant_id}/wholesale_prices/{id}.{_format}",
  56.  *              "identifiers"={"product_id", "variant_id", "id"},
  57.  *              "requirements"={"product_id"="\d+", "variant_id"="\d+", "id"="\d+"},
  58.  *              "openapi_context"={
  59.  *                  "summary"="Delete a wholesale price from a product variant",
  60.  *                  "parameters"={
  61.  *                      {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  62.  *                      {"name"="variant_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  63.  *                      {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  64.  *                  }
  65.  *              }
  66.  *          }
  67.  *     },
  68.  *     collectionOperations={
  69.  *          "get"={
  70.  *              "method"="GET",
  71.  *              "path"="/products/{product_id}/variants/{variant_id}/wholesale_prices.{_format}",
  72.  *              "identifiers"={"product_id", "variant_id"},
  73.  *              "requirements"={"product_id"="\d+", "variant_id"="\d+"},
  74.  *              "openapi_context"={
  75.  *                  "summary"="Retrieve a list of wholesale prices from a product variant",
  76.  *                  "parameters"={
  77.  *                      {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  78.  *                      {"name"="variant_id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  79.  *                  },
  80.  *              }
  81.  *          },
  82.  *          "post"={
  83.  *              "method"="POST",
  84.  *              "path"="/products/{product_id}/variants/{variant_id}/wholesale_prices.{_format}",
  85.  *              "controller"="xcart.api.cdev.wholesale.product_variant_wholesale_price.controller",
  86.  *              "identifiers"={"product_id", "variant_id"},
  87.  *              "requirements"={"product_id"="\d+", "variant_id"="\d+"},
  88.  *              "openapi_context"={
  89.  *                  "summary"="Add a wholesale price to a product variant",
  90.  *                  "parameters"={
  91.  *                      {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  92.  *                      {"name"="variant_id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  93.  *                  }
  94.  *              }
  95.  *          }
  96.  *     }
  97.  * )
  98.  *
  99.  * @Extender\Depend("XC\ProductVariants")
  100.  */
  101. class ProductVariantWholesalePrice extends \CDev\Wholesale\Model\Base\AWholesalePrice
  102. {
  103.     /**
  104.      * Relation to a product variant entity
  105.      *
  106.      * @var \XC\ProductVariants\Model\ProductVariant
  107.      *
  108.      * @ORM\ManyToOne  (targetEntity="XC\ProductVariants\Model\ProductVariant",cascade={"persist"})
  109.      * @ORM\JoinColumn (name="product_variant_id", referencedColumnName="id", onDelete="CASCADE")
  110.      */
  111.     protected $productVariant;
  112.     /**
  113.      * Return owner
  114.      *
  115.      * @return \XC\ProductVariants\Model\ProductVariant
  116.      */
  117.     public function getOwner()
  118.     {
  119.         return $this->getProductVariant();
  120.     }
  121.     /**
  122.      * Set owner
  123.      *
  124.      * @param \XC\ProductVariants\Model\ProductVariant $owner Owner
  125.      *
  126.      * @return static
  127.      */
  128.     public function setOwner($owner)
  129.     {
  130.         return $this->setProductVariant($owner);
  131.     }
  132.     /**
  133.      * @inheritdoc
  134.      */
  135.     public function getOwnerPrice()
  136.     {
  137.         if ($this->getOwner()) {
  138.             return $this->getOwner()->getDefaultPrice()
  139.                 ? $this->getOwner()->getProduct()->getPrice()
  140.                 : $this->getOwner()->getPrice();
  141.         } else {
  142.             return null;
  143.         }
  144.     }
  145.     /**
  146.      * Get product
  147.      *
  148.      * @return \XLite\Model\Product
  149.      */
  150.     public function getProduct()
  151.     {
  152.         return $this->getOwner() ? $this->getOwner()->getProduct() : null;
  153.     }
  154.     /**
  155.      * Set product: fake method for compatibility with \CDev\Wholesale\Model\WholesalePrice class
  156.      *
  157.      * @param \XLite\Model\Product $product
  158.      *
  159.      * @return static
  160.      */
  161.     public function setProduct($product)
  162.     {
  163.         return $this;
  164.     }
  165.     /**
  166.      * Get id
  167.      *
  168.      * @return integer
  169.      */
  170.     public function getId()
  171.     {
  172.         return $this->id;
  173.     }
  174.     /**
  175.      * @inheritdoc
  176.      */
  177.     public function setPrice($price)
  178.     {
  179.         $this->price $price;
  180.         return $this;
  181.     }
  182.     /**
  183.      * @inheritdoc
  184.      */
  185.     public function getPrice()
  186.     {
  187.         return $this->price;
  188.     }
  189.     /**
  190.      * Set productVariant
  191.      *
  192.      * @param \XC\ProductVariants\Model\ProductVariant|null $productVariant
  193.      * @return ProductVariantWholesalePrice
  194.      */
  195.     public function setProductVariant(\XC\ProductVariants\Model\ProductVariant $productVariant null)
  196.     {
  197.         $this->productVariant $productVariant;
  198.         return $this;
  199.     }
  200.     /**
  201.      * Get productVariant
  202.      *
  203.      * @return \XC\ProductVariants\Model\ProductVariant
  204.      */
  205.     public function getProductVariant()
  206.     {
  207.         return $this->productVariant;
  208.     }
  209. }