classes/XLite/Model/AttributeOption.php line 327

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\AttributeOption\Hidden\DTO\AttributeOptionHiddenInput as InputHiddenOption;
  10. use XLite\API\Endpoint\AttributeOption\Hidden\DTO\AttributeOptionHiddenOutput as OutputHiddenOption;
  11. use XLite\API\Endpoint\AttributeOption\Select\DTO\AttributeOptionSelectInput as InputSelectOption;
  12. use XLite\API\Endpoint\AttributeOption\Select\DTO\AttributeOptionSelectOutput as OutputSelectOption;
  13. /**
  14.  * @ORM\Entity
  15.  * @ORM\Table (name="attribute_options")
  16.  * @ApiPlatform\ApiResource(
  17.  *     shortName="Attribute Option",
  18.  *     itemOperations={
  19.  *          "get_option_select"={
  20.  *              "method"="GET",
  21.  *              "path"="/attributes_select/{attribute_id}/options/{id}.{_format}",
  22.  *              "identifiers"={"id"},
  23.  *              "input"=InputSelectOption::class,
  24.  *              "output"=OutputSelectOption::class,
  25.  *              "requirements"={"attribute_id"="\d+", "id"="\d+"},
  26.  *              "openapi_context"={
  27.  *                  "summary"="Retrieve an option from a global plain field attribute",
  28.  *                  "parameters"={
  29.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  30.  *                     {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  31.  *                  }
  32.  *              }
  33.  *          },
  34.  *          "put_option_select"={
  35.  *              "method"="PUT",
  36.  *              "path"="/attributes_select/{attribute_id}/options/{id}.{_format}",
  37.  *              "identifiers"={"id"},
  38.  *              "input"=InputSelectOption::class,
  39.  *              "output"=OutputSelectOption::class,
  40.  *              "requirements"={"attribute_id"="\d+", "id"="\d+"},
  41.  *              "openapi_context"={
  42.  *                  "summary"="Update an option of a global plain field attribute",
  43.  *                  "parameters"={
  44.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  45.  *                     {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  46.  *                  }
  47.  *              }
  48.  *          },
  49.  *          "delete_option_select"={
  50.  *              "method"="DELETE",
  51.  *              "path"="/attributes_select/{attribute_id}/options/{id}.{_format}",
  52.  *              "identifiers"={"id"},
  53.  *              "input"=InputSelectOption::class,
  54.  *              "output"=OutputSelectOption::class,
  55.  *              "requirements"={"attribute_id"="\d+", "id"="\d+"},
  56.  *              "openapi_context"={
  57.  *                  "summary"="Delete an option from a global plain field attribute",
  58.  *                  "parameters"={
  59.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  60.  *                     {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  61.  *                  }
  62.  *              }
  63.  *          },
  64.  *          "get_option_hidden"={
  65.  *              "method"="GET",
  66.  *              "path"="/attributes_hidden/{attribute_id}/options/{id}.{_format}",
  67.  *              "identifiers"={"id"},
  68.  *              "input"=InputHiddenOption::class,
  69.  *              "output"=OutputHiddenOption::class,
  70.  *              "requirements"={"attribute_id"="\d+", "id"="\d+"},
  71.  *              "openapi_context"={
  72.  *                  "summary"="Retrieve an option from a global hidden attribute",
  73.  *                  "parameters"={
  74.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  75.  *                     {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  76.  *                  }
  77.  *              }
  78.  *          },
  79.  *          "put_option_hidden"={
  80.  *              "method"="PUT",
  81.  *              "path"="/attributes_hidden/{attribute_id}/options/{id}.{_format}",
  82.  *              "identifiers"={"id"},
  83.  *              "input"=InputHiddenOption::class,
  84.  *              "output"=OutputHiddenOption::class,
  85.  *              "requirements"={"attribute_id"="\d+", "id"="\d+"},
  86.  *              "openapi_context"={
  87.  *                  "summary"="Update an option of a global hidden attribute",
  88.  *                  "parameters"={
  89.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  90.  *                     {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  91.  *                  }
  92.  *              }
  93.  *          },
  94.  *          "delete_option_hidden"={
  95.  *              "method"="DELETE",
  96.  *              "path"="/attributes_hidden/{attribute_id}/options/{id}.{_format}",
  97.  *              "identifiers"={"id"},
  98.  *              "input"=InputHiddenOption::class,
  99.  *              "output"=OutputHiddenOption::class,
  100.  *              "requirements"={"attribute_id"="\d+", "id"="\d+"},
  101.  *              "openapi_context"={
  102.  *                  "summary"="Delete an option from a global hidden attribute",
  103.  *                  "parameters"={
  104.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  105.  *                     {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  106.  *                  }
  107.  *              }
  108.  *          },
  109.  *          "product_class_based_get_option_select"={
  110.  *              "method"="GET",
  111.  *              "path"="/product_classes/{class_id}/attributes_select/{attribute_id}/options/{id}.{_format}",
  112.  *              "identifiers"={"id"},
  113.  *              "input"=InputSelectOption::class,
  114.  *              "output"=OutputSelectOption::class,
  115.  *              "requirements"={"class_id"="\d+", "attribute_id"="\d+", "id"="\d+"},
  116.  *              "openapi_context"={
  117.  *                  "summary"="Retrieve an option from a product class plain field attribute",
  118.  *                  "parameters"={
  119.  *                     {"name"="class_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  120.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  121.  *                     {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  122.  *                  }
  123.  *              }
  124.  *          },
  125.  *          "product_class_based_put_option_select"={
  126.  *              "method"="PUT",
  127.  *              "path"="/product_classes/{class_id}/attributes_select/{attribute_id}/options/{id}.{_format}",
  128.  *              "identifiers"={"id"},
  129.  *              "input"=InputSelectOption::class,
  130.  *              "output"=OutputSelectOption::class,
  131.  *              "requirements"={"class_id"="\d+", "attribute_id"="\d+", "id"="\d+"},
  132.  *              "openapi_context"={
  133.  *                  "summary"="Update an option of a product class plain field attribute",
  134.  *                  "parameters"={
  135.  *                     {"name"="class_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  136.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  137.  *                     {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  138.  *                  }
  139.  *              }
  140.  *          },
  141.  *          "product_class_based_delete_option_select"={
  142.  *              "method"="DELETE",
  143.  *              "path"="/product_classes/{class_id}/attributes_select/{attribute_id}/options/{id}.{_format}",
  144.  *              "identifiers"={"id"},
  145.  *              "input"=InputSelectOption::class,
  146.  *              "output"=OutputSelectOption::class,
  147.  *              "requirements"={"class_id"="\d+", "attribute_id"="\d+", "id"="\d+"},
  148.  *              "openapi_context"={
  149.  *                  "summary"="Delete an option from a product class plain field attribute",
  150.  *                  "parameters"={
  151.  *                     {"name"="class_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  152.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  153.  *                     {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  154.  *                  }
  155.  *              }
  156.  *          },
  157.  *          "product_based_get_option_select"={
  158.  *              "method"="GET",
  159.  *              "path"="/products/{product_id}/attributes_select/{attribute_id}/options/{id}.{_format}",
  160.  *              "identifiers"={"id"},
  161.  *              "input"=InputSelectOption::class,
  162.  *              "output"=OutputSelectOption::class,
  163.  *              "requirements"={"product_id"="\d+", "attribute_id"="\d+", "id"="\d+"},
  164.  *              "openapi_context"={
  165.  *                  "summary"="Retrieve an option from a product-specific plain field attribute",
  166.  *                  "parameters"={
  167.  *                     {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  168.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  169.  *                     {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  170.  *                  }
  171.  *              }
  172.  *          },
  173.  *          "product_based_put_option_select"={
  174.  *              "method"="PUT",
  175.  *              "path"="/products/{product_id}/attributes_select/{attribute_id}/options/{id}.{_format}",
  176.  *              "identifiers"={"id"},
  177.  *              "input"=InputSelectOption::class,
  178.  *              "output"=OutputSelectOption::class,
  179.  *              "requirements"={"product_id"="\d+", "attribute_id"="\d+", "id"="\d+"},
  180.  *              "openapi_context"={
  181.  *                  "summary"="Update an option of a product-specific plain field attribute",
  182.  *                  "parameters"={
  183.  *                     {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  184.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  185.  *                     {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  186.  *                  }
  187.  *              }
  188.  *          },
  189.  *          "product_based_delete_option_select"={
  190.  *              "method"="DELETE",
  191.  *              "path"="/products/{product_id}/attributes_select/{attribute_id}/options/{id}.{_format}",
  192.  *              "identifiers"={"id"},
  193.  *              "input"=InputSelectOption::class,
  194.  *              "output"=OutputSelectOption::class,
  195.  *              "requirements"={"product_id"="\d+", "attribute_id"="\d+", "id"="\d+"},
  196.  *              "openapi_context"={
  197.  *                  "summary"="Delete an option from a product-specific plain field attribute",
  198.  *                  "parameters"={
  199.  *                     {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  200.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  201.  *                     {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  202.  *                  }
  203.  *              }
  204.  *          }
  205.  *     },
  206.  *     collectionOperations={
  207.  *          "get_option_selects"={
  208.  *              "method"="GET",
  209.  *              "path"="/attributes_select/{attribute_id}/options.{_format}",
  210.  *              "identifiers"={"id"},
  211.  *              "input"=InputSelectOption::class,
  212.  *              "output"=OutputSelectOption::class,
  213.  *              "requirements"={"attribute_id"="\d+"},
  214.  *              "openapi_context"={
  215.  *                  "summary"="Retrieve a list of options from a global plain field attribute",
  216.  *                  "parameters"={
  217.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  218.  *                  }
  219.  *              }
  220.  *          },
  221.  *          "post_option_select"={
  222.  *              "method"="POST",
  223.  *              "controller"="xcart.api.attribute_option.select.controller",
  224.  *              "path"="/attributes_select/{attribute_id}/options.{_format}",
  225.  *              "identifiers"={"id"},
  226.  *              "input"=InputSelectOption::class,
  227.  *              "output"=OutputSelectOption::class,
  228.  *              "requirements"={"attribute_id"="\d+"},
  229.  *              "openapi_context"={
  230.  *                  "summary"="Add an option to a global plain field attribute",
  231.  *                  "parameters"={
  232.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  233.  *                  }
  234.  *              }
  235.  *          },
  236.  *          "get_option_hiddens"={
  237.  *              "method"="GET",
  238.  *              "path"="/attributes_hidden/{attribute_id}/options.{_format}",
  239.  *              "identifiers"={"id"},
  240.  *              "input"=InputHiddenOption::class,
  241.  *              "output"=OutputHiddenOption::class,
  242.  *              "requirements"={"attribute_id"="\d+"},
  243.  *              "openapi_context"={
  244.  *                  "summary"="Retrieve a list of options from a global hidden attribute",
  245.  *                  "parameters"={
  246.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  247.  *                  }
  248.  *              }
  249.  *          },
  250.  *          "post_option_hidden"={
  251.  *              "method"="POST",
  252.  *              "controller"="xcart.api.attribute_option.hidden.controller",
  253.  *              "path"="/attributes_hidden/{attribute_id}/options.{_format}",
  254.  *              "identifiers"={"id"},
  255.  *              "input"=InputHiddenOption::class,
  256.  *              "output"=OutputHiddenOption::class,
  257.  *              "requirements"={"attribute_id"="\d+"},
  258.  *              "openapi_context"={
  259.  *                  "summary"="Add an option to a global hidden attribute",
  260.  *                  "parameters"={
  261.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  262.  *                  }
  263.  *              }
  264.  *          },
  265.  *          "product_class_based_get_option_selects"={
  266.  *              "method"="GET",
  267.  *              "path"="/product_classes/{class_id}/attributes_select/{attribute_id}/options.{_format}",
  268.  *              "identifiers"={"id"},
  269.  *              "input"=InputSelectOption::class,
  270.  *              "output"=OutputSelectOption::class,
  271.  *              "requirements"={"class_id"="\d+", "attribute_id"="\d+"},
  272.  *              "openapi_context"={
  273.  *                  "summary"="Retrieve a list of options from a product class plain field attribute",
  274.  *                  "parameters"={
  275.  *                     {"name"="class_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  276.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  277.  *                  }
  278.  *              }
  279.  *          },
  280.  *          "product_class_based_post_option_select"={
  281.  *              "method"="POST",
  282.  *              "controller"="xcart.api.attribute_option.select.product_class_controller",
  283.  *              "path"="/product_classes/{class_id}/attributes_select/{attribute_id}/options.{_format}",
  284.  *              "identifiers"={"id"},
  285.  *              "input"=InputSelectOption::class,
  286.  *              "output"=OutputSelectOption::class,
  287.  *              "requirements"={"class_id"="\d+", "attribute_id"="\d+"},
  288.  *              "openapi_context"={
  289.  *                  "summary"="Add an option to a product class plain field attribute",
  290.  *                  "parameters"={
  291.  *                     {"name"="class_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  292.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  293.  *                  }
  294.  *              }
  295.  *          },
  296.  *          "product_based_get_option_selects"={
  297.  *              "method"="GET",
  298.  *              "path"="/products/{product_id}/attributes_select/{attribute_id}/options.{_format}",
  299.  *              "identifiers"={"id"},
  300.  *              "input"=InputSelectOption::class,
  301.  *              "output"=OutputSelectOption::class,
  302.  *              "requirements"={"product_id"="\d+", "attribute_id"="\d+"},
  303.  *              "openapi_context"={
  304.  *                  "summary"="Retrieve a list of options from a product-specific plain field attribute",
  305.  *                  "parameters"={
  306.  *                     {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  307.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  308.  *                  }
  309.  *              }
  310.  *          },
  311.  *          "product_based_post_option_select"={
  312.  *              "method"="POST",
  313.  *              "controller"="xcart.api.attribute_option.select.product_controller",
  314.  *              "path"="/products/{product_id}/attributes_select/{attribute_id}/options.{_format}",
  315.  *              "identifiers"={"id"},
  316.  *              "input"=InputSelectOption::class,
  317.  *              "output"=OutputSelectOption::class,
  318.  *              "requirements"={"product_id"="\d+", "attribute_id"="\d+"},
  319.  *              "openapi_context"={
  320.  *                  "summary"="Add an option to a product-specific plain field attribute",
  321.  *                  "parameters"={
  322.  *                     {"name"="product_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  323.  *                     {"name"="attribute_id", "in"="path", "required"=true, "schema"={"type"="integer"}},
  324.  *                  }
  325.  *              }
  326.  *          }
  327.  *     }
  328.  * )
  329.  */
  330. class AttributeOption extends \XLite\Model\Base\I18n
  331. {
  332.     /**
  333.      * @var int
  334.      *
  335.      * @ORM\Id
  336.      * @ORM\GeneratedValue (strategy="AUTO")
  337.      * @ORM\Column (type="integer", options={"unsigned": true})
  338.      */
  339.     protected $id;
  340.     /**
  341.      * @var \XLite\Model\Attribute
  342.      *
  343.      * @ORM\ManyToOne (targetEntity="XLite\Model\Attribute", inversedBy="attribute_options")
  344.      * @ORM\JoinColumn (name="attribute_id", referencedColumnName="id", onDelete="CASCADE")
  345.      */
  346.     protected $attribute;
  347.     /**
  348.      * Add to new products or class’s assigns automatically
  349.      *
  350.      * @var bool
  351.      *
  352.      * @ORM\Column (type="boolean")
  353.      */
  354.     protected $addToNew false;
  355.     /**
  356.      * @var int
  357.      *
  358.      * @ORM\Column (type="integer")
  359.      */
  360.     protected $position 0;
  361.     /**
  362.      * @var \Doctrine\Common\Collections\Collection
  363.      *
  364.      * @ORM\OneToMany (targetEntity="XLite\Model\AttributeOptionTranslation", mappedBy="owner", cascade={"all"})
  365.      */
  366.     protected $translations;
  367.     /**
  368.      * Get id
  369.      *
  370.      * @return integer
  371.      */
  372.     public function getId()
  373.     {
  374.         return $this->id;
  375.     }
  376.     /**
  377.      * Set addToNew
  378.      *
  379.      * @param boolean $addToNew
  380.      */
  381.     public function setAddToNew($addToNew)
  382.     {
  383.         $this->addToNew $addToNew;
  384.     }
  385.     /**
  386.      * Get addToNew
  387.      *
  388.      * @return boolean
  389.      */
  390.     public function getAddToNew()
  391.     {
  392.         return $this->addToNew;
  393.     }
  394.     /**
  395.      * Set attribute
  396.      *
  397.      * @param \XLite\Model\Attribute $attribute
  398.      */
  399.     public function setAttribute(\XLite\Model\Attribute $attribute null)
  400.     {
  401.         $this->attribute $attribute;
  402.     }
  403.     /**
  404.      * Get attribute
  405.      *
  406.      * @return \XLite\Model\Attribute
  407.      */
  408.     public function getAttribute()
  409.     {
  410.         return $this->attribute;
  411.     }
  412.     /**
  413.      * @return int
  414.      */
  415.     public function getPosition()
  416.     {
  417.         return $this->position;
  418.     }
  419.     /**
  420.      * @param int $position
  421.      */
  422.     public function setPosition($position)
  423.     {
  424.         $this->position $position;
  425.     }
  426. }