classes/XLite/Model/AttributeValue/AttributeValueHidden.php line 102

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\AttributeValue;
  7. use ApiPlatform\Core\Annotation as ApiPlatform;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use XLite\API\Endpoint\AttributeValue\Hidden\DTO\AttributeValueHiddenInput as Input;
  10. use XLite\API\Endpoint\AttributeValue\Hidden\DTO\AttributeValueHiddenOutput as Output;
  11. use XLite\Controller\API\AttributeValue\Hidden\Post as PostController;
  12. use XLite\Core\Translation\Label;
  13. /**
  14.  * Attribute value (hidden)
  15.  *
  16.  * @ORM\Entity
  17.  * @ORM\Table  (name="attribute_values_hidden",
  18.  *      indexes={
  19.  *          @ORM\Index (name="product_id", columns={"product_id"}),
  20.  *          @ORM\Index (name="attribute_id", columns={"attribute_id"}),
  21.  *          @ORM\Index (name="attribute_option_id", columns={"attribute_option_id"})
  22.  *      }
  23.  * )
  24.  * @ApiPlatform\ApiResource(
  25.  *     attributes={"pagination_enabled": false},
  26.  *     compositeIdentifier=false,
  27.  *     shortName="Hidden Attribute Value",
  28.  *     itemOperations={
  29.  *          "get"={
  30.  *              "method"="GET",
  31.  *              "path"="/products/{product_id}/attributes_hidden/{attribute_id}/values.{_format}",
  32.  *              "identifiers"={"id"},
  33.  *              "input"=Input::class,
  34.  *              "output"=Output::class,
  35.  *              "requirements"={"product_id"="\d+", "attribute_id"="\d+"},
  36.  *              "identifiers"={"product_id", "attribute_id"},
  37.  *              "openapi_context"={
  38.  *                  "summary"="Retrieve a value from a product hidden attribute",
  39.  *                  "parameters"={
  40.  *                     {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  41.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  42.  *                  }
  43.  *              }
  44.  *          },
  45.  *          "put"={
  46.  *              "method"="PUT",
  47.  *              "path"="/products/{product_id}/attributes_hidden/{attribute_id}/values.{_format}",
  48.  *              "identifiers"={"id"},
  49.  *              "input"=Input::class,
  50.  *              "output"=Output::class,
  51.  *              "requirements"={"product_id"="\d+", "attribute_id"="\d+"},
  52.  *              "identifiers"={"product_id", "attribute_id"},
  53.  *              "openapi_context"={
  54.  *                  "summary"="Update a value of a product hidden attribute",
  55.  *                  "parameters"={
  56.  *                     {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  57.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  58.  *                  }
  59.  *              }
  60.  *          },
  61.  *          "delete"={
  62.  *              "method"="DELETE",
  63.  *              "path"="/products/{product_id}/attributes_hidden/{attribute_id}/values.{_format}",
  64.  *              "identifiers"={"id"},
  65.  *              "input"=Input::class,
  66.  *              "output"=Output::class,
  67.  *              "requirements"={"product_id"="\d+", "attribute_id"="\d+"},
  68.  *              "identifiers"={"product_id", "attribute_id"},
  69.  *              "openapi_context"={
  70.  *                  "summary"="Delete a value from a product hidden attribute",
  71.  *                  "parameters"={
  72.  *                     {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  73.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  74.  *                  }
  75.  *              }
  76.  *          }
  77.  *     },
  78.  *     collectionOperations={
  79.  *          "post"={
  80.  *              "method"="POST",
  81.  *              "path"="/products/{product_id}/attributes_hidden/{attribute_id}/values.{_format}",
  82.  *              "identifiers"={"id"},
  83.  *              "input"=Input::class,
  84.  *              "output"=Output::class,
  85.  *              "controller"=PostController::class,
  86.  *              "requirements"={"product_id"="\d+", "attribute_id"="\d+"},
  87.  *              "openapi_context"={
  88.  *                  "summary"="Add a value to a product hidden attribute",
  89.  *                  "parameters"={
  90.  *                     {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  91.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  92.  *                  }
  93.  *              }
  94.  *          }
  95.  *     }
  96.  * )
  97.  */
  98. class AttributeValueHidden extends \XLite\Model\AttributeValue\AAttributeValue
  99. {
  100.     /**
  101.      * @var \XLite\Model\Product
  102.      *
  103.      * @ORM\ManyToOne (targetEntity="XLite\Model\Product", inversedBy="attributeValueH")
  104.      * @ORM\JoinColumn (name="product_id", referencedColumnName="product_id", onDelete="CASCADE")
  105.      */
  106.     protected $product;
  107.     /**
  108.      * Attribute option
  109.      *
  110.      * @var \XLite\Model\AttributeOption
  111.      *
  112.      * @ORM\ManyToOne  (targetEntity="XLite\Model\AttributeOption")
  113.      * @ORM\JoinColumn (name="attribute_option_id", referencedColumnName="id", onDelete="CASCADE")
  114.      */
  115.     protected $attribute_option;
  116.     /**
  117.      * @var \Doctrine\Common\Collections\Collection
  118.      *
  119.      * @ORM\OneToMany (targetEntity="XLite\Model\AttributeValue\AttributeValueHiddenTranslation", mappedBy="owner", cascade={"all"})
  120.      */
  121.     protected $translations;
  122.     /**
  123.      * Return attribute value as string
  124.      *
  125.      * @return string|Label
  126.      */
  127.     public function asString()
  128.     {
  129.         /** @see \XLite\Model\AttributeOptionTranslation */
  130.         return $this->getAttributeOption()->getName();
  131.     }
  132.     /**
  133.      * Clone
  134.      *
  135.      * @return static
  136.      */
  137.     public function cloneEntity()
  138.     {
  139.         /** @var static $newEntity */
  140.         $newEntity parent::cloneEntity();
  141.         if ($this->getAttributeOption()) {
  142.             $attributeOption $this->getAttributeOption();
  143.             $newEntity->setAttributeOption($attributeOption);
  144.         }
  145.         return $newEntity;
  146.     }
  147.     /**
  148.      * @return \XLite\Model\Product
  149.      */
  150.     public function getProduct()
  151.     {
  152.         return $this->product;
  153.     }
  154.     /**
  155.      * @param \XLite\Model\Product $product
  156.      */
  157.     public function setProduct(\XLite\Model\Product $product null)
  158.     {
  159.         $this->product $product;
  160.     }
  161.     /**
  162.      * @param \XLite\Model\AttributeOption $attributeOption
  163.      *
  164.      * @return static
  165.      */
  166.     public function setAttributeOption(\XLite\Model\AttributeOption $attributeOption null)
  167.     {
  168.         $this->attribute_option $attributeOption;
  169.         return $this;
  170.     }
  171.     /**
  172.      * @return \XLite\Model\AttributeOption
  173.      */
  174.     public function getAttributeOption()
  175.     {
  176.         return $this->attribute_option;
  177.     }
  178. }