classes/XLite/Model/AttributeValue/AttributeValueSelect.php line 109

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\Select\DTO\AttributeValueSelectInput as Input;
  10. use XLite\API\Endpoint\AttributeValue\Select\DTO\AttributeValueSelectOutput as Output;
  11. use XLite\Controller\API\AttributeValue\Select\Post as PostController;
  12. use XLite\Core\Translation\Label;
  13. /**
  14.  * Attribute value (select)
  15.  *
  16.  * @ORM\Entity
  17.  * @ORM\Table  (name="attribute_values_select",
  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.  *     shortName="Plain Field Attribute Value",
  27.  *     itemOperations={
  28.  *          "get"={
  29.  *              "method"="GET",
  30.  *              "path"="/products/{product_id}/attributes_select/{attribute_id}/values/{id}.{_format}",
  31.  *              "identifiers"={"id"},
  32.  *              "input"=Input::class,
  33.  *              "output"=Output::class,
  34.  *              "requirements"={"product_id"="\d+", "attribute_id"="\d+", "id"="\d+"},
  35.  *              "openapi_context"={
  36.  *                  "summary"="Retrieve a value from a product plain field attribute",
  37.  *                  "parameters"={
  38.  *                     {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  39.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  40.  *                     {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  41.  *                  }
  42.  *              }
  43.  *          },
  44.  *          "put"={
  45.  *              "method"="PUT",
  46.  *              "path"="/products/{product_id}/attributes_select/{attribute_id}/values/{id}.{_format}",
  47.  *              "identifiers"={"id"},
  48.  *              "input"=Input::class,
  49.  *              "output"=Output::class,
  50.  *              "requirements"={"product_id"="\d+", "attribute_id"="\d+", "id"="\d+"},
  51.  *              "openapi_context"={
  52.  *                  "summary"="Update a value of a product plain field attribute",
  53.  *                  "parameters"={
  54.  *                     {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  55.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  56.  *                     {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  57.  *                  }
  58.  *              }
  59.  *          },
  60.  *          "delete"={
  61.  *              "method"="DELETE",
  62.  *              "path"="/products/{product_id}/attributes_select/{attribute_id}/values/{id}.{_format}",
  63.  *              "identifiers"={"id"},
  64.  *              "input"=Input::class,
  65.  *              "output"=Output::class,
  66.  *              "requirements"={"product_id"="\d+", "attribute_id"="\d+", "id"="\d+"},
  67.  *              "openapi_context"={
  68.  *                  "summary"="Delete a value from a product plain field attribute",
  69.  *                  "parameters"={
  70.  *                     {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  71.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  72.  *                     {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  73.  *                  }
  74.  *              }
  75.  *          }
  76.  *     },
  77.  *     collectionOperations={
  78.  *          "get"={
  79.  *              "method"="GET",
  80.  *              "path"="/products/{product_id}/attributes_select/{attribute_id}/values.{_format}",
  81.  *              "identifiers"={"id"},
  82.  *              "input"=Input::class,
  83.  *              "output"=Output::class,
  84.  *              "requirements"={"product_id"="\d+", "attribute_id"="\d+"},
  85.  *              "openapi_context"={
  86.  *                  "summary"="Retrieve a list of values from a product plain field attribute",
  87.  *                  "parameters"={
  88.  *                     {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  89.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  90.  *                  }
  91.  *              }
  92.  *          },
  93.  *          "post"={
  94.  *              "method"="POST",
  95.  *              "path"="/products/{product_id}/attributes_select/{attribute_id}/values.{_format}",
  96.  *              "identifiers"={"id"},
  97.  *              "input"=Input::class,
  98.  *              "output"=Output::class,
  99.  *              "controller"=PostController::class,
  100.  *              "requirements"={"product_id"="\d+", "attribute_id"="\d+"},
  101.  *              "openapi_context"={
  102.  *                  "summary"="Add a value to a product plain field attribute",
  103.  *                  "parameters"={
  104.  *                     {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  105.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  106.  *                  }
  107.  *              }
  108.  *          }
  109.  *     }
  110.  * )
  111.  */
  112. class AttributeValueSelect extends \XLite\Model\AttributeValue\Multiple
  113. {
  114.     /**
  115.      * @var \XLite\Model\Product
  116.      *
  117.      * @ORM\ManyToOne (targetEntity="XLite\Model\Product", inversedBy="attributeValueS")
  118.      * @ORM\JoinColumn (name="product_id", referencedColumnName="product_id", onDelete="CASCADE")
  119.      */
  120.     protected $product;
  121.     /**
  122.      * Attribute option
  123.      *
  124.      * @var \XLite\Model\AttributeOption
  125.      *
  126.      * @ORM\ManyToOne  (targetEntity="XLite\Model\AttributeOption")
  127.      * @ORM\JoinColumn (name="attribute_option_id", referencedColumnName="id", onDelete="CASCADE")
  128.      */
  129.     protected $attribute_option;
  130.     /**
  131.      * Position
  132.      *
  133.      * @var integer
  134.      *
  135.      * @ORM\Column (type="integer")
  136.      */
  137.     protected $position 0;
  138.     /**
  139.      * @var \Doctrine\Common\Collections\Collection
  140.      *
  141.      * @ORM\OneToMany (targetEntity="XLite\Model\AttributeValue\AttributeValueSelectTranslation", mappedBy="owner", cascade={"all"})
  142.      */
  143.     protected $translations;
  144.     /**
  145.      * Return attribute value as string
  146.      *
  147.      * @return string|Label
  148.      */
  149.     public function asString()
  150.     {
  151.         /** @see \XLite\Model\AttributeOptionTranslation */
  152.         return $this->getAttributeOption()->getName();
  153.     }
  154.     /**
  155.      * Clone
  156.      *
  157.      * @return static
  158.      */
  159.     public function cloneEntity()
  160.     {
  161.         /** @var static $newEntity */
  162.         $newEntity parent::cloneEntity();
  163.         if ($this->getAttributeOption()) {
  164.             if ($this->getAttribute()->getProduct()) {
  165.                 $attributeOption $this->getAttributeOption()->cloneEntity();
  166.                 \XLite\Core\Database::getEM()->persist($attributeOption);
  167.             } else {
  168.                 $attributeOption $this->getAttributeOption();
  169.             }
  170.             $newEntity->setAttributeOption($attributeOption);
  171.         }
  172.         return $newEntity;
  173.     }
  174.     /**
  175.      * @return \XLite\Model\Product
  176.      */
  177.     public function getProduct()
  178.     {
  179.         return $this->product;
  180.     }
  181.     /**
  182.      * @param \XLite\Model\Product $product
  183.      */
  184.     public function setProduct(\XLite\Model\Product $product null)
  185.     {
  186.         $this->product $product;
  187.     }
  188.     /**
  189.      * @return \XLite\Model\AttributeOption
  190.      */
  191.     public function getAttributeOption()
  192.     {
  193.         return $this->attribute_option;
  194.     }
  195.     /**
  196.      * @param \XLite\Model\AttributeOption $attributeOption
  197.      *
  198.      * @return static
  199.      */
  200.     public function setAttributeOption(\XLite\Model\AttributeOption $attributeOption null)
  201.     {
  202.         $this->attribute_option $attributeOption;
  203.         return $this;
  204.     }
  205.     /**
  206.      * @return integer
  207.      */
  208.     public function getPosition()
  209.     {
  210.         return $this->position;
  211.     }
  212.     /**
  213.      * @param integer $position
  214.      *
  215.      * @return static
  216.      */
  217.     public function setPosition($position)
  218.     {
  219.         $this->position $position;
  220.         return $this;
  221.     }
  222. }