src/AtechNet/CoreBundle/Entity/AttributeOption.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\AtechNet\CoreBundle\Entity;
  3. use App\AtechNet\CoreBundle\Helper\GraphSortableEntityInterface;
  4. use App\AtechNet\CoreBundle\Repository\AttributeOptionRepository;
  5. use App\AtechNet\CoreBundle\Translation\TranslationHelper;
  6. use App\AtechNet\CoreBundle\Translation\TranslatorInterface;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\ORM\Mapping\Column;
  9. use Doctrine\ORM\Mapping\Entity;
  10. use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
  11. use Doctrine\ORM\Mapping\JoinColumn;
  12. use Doctrine\ORM\Mapping\ManyToOne;
  13. use Doctrine\ORM\Mapping\OneToMany;
  14. use Doctrine\ORM\Mapping\OrderBy;
  15. use Doctrine\ORM\Mapping\Table as Table;
  16. use Symfony\Component\Validator\Constraints as Assert;
  17. /**
  18.  * AttributeOption
  19.  *
  20.  * @Table(name="attribute_options")
  21.  * @Entity(repositoryClass=AttributeOptionRepository::class)
  22.  * @HasLifecycleCallbacks
  23.  */
  24. class AttributeOption extends AbstractSignedEntity implements GraphSortableEntityInterface
  25. {
  26.     public const Color_None = '';
  27.     public const Color_Blue = 'blue';
  28.     public const Color_Green = 'green';
  29.     public const Color_Grey = 'grey';
  30.     /**
  31.      * ATTRIBUTE_OPTION_ID_HDD_25  => HDD 2,5"
  32.      * ATTRIBUTE_OPTION_ID_HDD_18  => HDD 1.8"
  33.      * ...
  34.      **/
  35.     public const int ATTRIBUTE_OPTION_ID_HDD_25 = 32;
  36.     public const int ATTRIBUTE_OPTION_ID_HDD_35 = 33;
  37.     public const int ATTRIBUTE_OPTION_ID_SSD = 85;
  38.     public const int ATTRIBUTE_OPTION_ID_SSHD_25 = 86;
  39.     public const int ATTRIBUTE_OPTION_ID_SSD_512 = 528;
  40.     public const int ATTRIBUTE_OPTION_ID_SSD_25_1TB = 2047;
  41.     public const int ATTRIBUTE_OPTION_ID_SSD_25_2TB = 5780;
  42.     public const int ATTRIBUTE_OPTION_ID_SSD_480GB = 123;
  43.     public const int ATTRIBUTE_OPTION_ID_SSD_500GB = 124;
  44.     public const int ATTRIBUTE_OPTION_ID_SSD_512GB = 125;
  45.     public const int ATTRIBUTE_OPTION_ID_SSD_M2_480GB = 4685;
  46.     public const int ATTRIBUTE_OPTION_ID_SSD_M2_500GB = 4886;
  47.     public const int ATTRIBUTE_OPTION_ID_SSD_M2_510GB = 5632;
  48.     public const int ATTRIBUTE_OPTION_ID_SSD_M2_512GB = 1448;
  49.     public const int ATTRIBUTE_OPTION_ID_SSD_NVME_512GB = 3384;
  50.     public const int ATTRIBUTE_OPTION_ID_SSHD_35 = 87;
  51.     public const int ATTRIBUTE_OPTION_ID_HDD_18 = 125;
  52.     public const int ATTRIBUTE_OPTION_ID_HDD_EXTERNAL = 34;
  53.     public const int ATTRIBUTE_OPTION_ID_USB_FLASH = 99;
  54.     public const int ATTRIBUTE_OPTION_ID_WINDOWS_10 = 538;
  55.     public const int ATTRIBUTE_OPTION_ID_WINDOWS_11 = 4325;
  56.     public const int ATTRIBUTE_OPTION_ID_MAC_OS = 4873;
  57.     public const int ATTRIBUTE_OPTION_ID_UK_CABEL = 5903;
  58.     public const int ATTRIBUTE_OPTION_1_YEAR_WARRANTY = 2226;
  59.     public const int ATTRIBUTE_OPTION_2_YEAR_WARRANTY = 2227;
  60.     public const int ATTRIBUTE_OPTION_3_YEAR_WARRANTY = 2228;
  61.     public const int ATTRIBUTE_OPTION_I_NEED_OFFICE_1_YEAR = 240;
  62.     public const int ATTRIBUTE_OPTION_I_NEED_PACKAGE_INSTALL = 236;
  63.     public const int ATTRIBUTE_OPTION_TOUCHSCREEN = 1295;
  64.     public const int ATTRIBUTE_OPTION_NO_TOUCHSCREEN = 5964;
  65.     public const int ATTRIBUTE_OPTION_NO_WEBCAM = 1773;
  66.     public const int ATTRIBUTE_OPTION_NO_OOD = 183;
  67.     public const int ATTRIBUTE_OPTION_IPS_PANEL = 926;
  68.     public const int ATTRIBUTE_OPTION_OLED_PANEL = 6007;
  69.     public const int ATTRIBUTE_OPTION_QLED_PANEL = 6083;
  70.     public const int ATTRIBUTE_OPTION_NUMPAD = 555;
  71.     public const int ATTRIBUTE_OPTION_NO_NUMPAD = 554;
  72.     //years for YEAR_OF_PRODUCTION attribute
  73.     public const int ATTRIBUTE_YEAR_2005 = 6122;
  74.     public const int ATTRIBUTE_YEAR_2006 = 6123;
  75.     public const int ATTRIBUTE_YEAR_2007 = 6124;
  76.     public const int ATTRIBUTE_YEAR_2008 = 6125;
  77.     public const int ATTRIBUTE_YEAR_2009 = 6126;
  78.     public const int ATTRIBUTE_YEAR_2010 = 6127;
  79.     public const int ATTRIBUTE_YEAR_2011 = 6128;
  80.     public const int ATTRIBUTE_YEAR_2012 = 6129;
  81.     public const int ATTRIBUTE_YEAR_2013 = 6130;
  82.     public const int ATTRIBUTE_YEAR_2014 = 6131;
  83.     public const int ATTRIBUTE_YEAR_2015 = 6132;
  84.     public const int ATTRIBUTE_YEAR_2016 = 6133;
  85.     public const int ATTRIBUTE_YEAR_2017 = 6134;
  86.     public const int ATTRIBUTE_YEAR_2018 = 6135;
  87.     public const int ATTRIBUTE_YEAR_2019 = 6136;
  88.     public const int ATTRIBUTE_YEAR_2020 = 6137;
  89.     public const int ATTRIBUTE_YEAR_2021 = 6138;
  90.     public const int ATTRIBUTE_YEAR_2022 = 6139;
  91.     public const int ATTRIBUTE_YEAR_2023 = 6140;
  92.     public const int ATTRIBUTE_YEAR_2024 = 6141;
  93.     public const int ATTRIBUTE_YEAR_2025 = 6142;
  94.     public const int ATTRIBUTE_YEAR_2026 = 6540;
  95.     public const int ATTRIBUTE_OPTION_CPU_MARK_A = 6181;
  96.     public const int ATTRIBUTE_OPTION_CPU_MARK_B = 6182;
  97.     public const int ATTRIBUTE_OPTION_CPU_MARK_C = 6183;
  98.     public const int ATTRIBUTE_OPTION_CPU_MARK_D = 6184;
  99.     public const int ATTRIBUTE_OPTION_CPU_MARK_E = 6185;
  100.     public const array WARRIANTIES = [
  101.         self::ATTRIBUTE_OPTION_1_YEAR_WARRANTY,
  102.         self::ATTRIBUTE_OPTION_2_YEAR_WARRANTY,
  103.         self::ATTRIBUTE_OPTION_3_YEAR_WARRANTY,
  104.     ];
  105.     public const int ATTRIBUTE_OPTION_QUALITY_BAZAAR = 2419;
  106.     public const int ATTRIBUTE_OPTION_QUALITY_BRONZ = 745;
  107.     public const int ATTRIBUTE_OPTION_QUALITY_SILVER = 744;
  108.     public const int ATTRIBUTE_OPTION_QUALITY_GOLD = 743;
  109.     public const int ATTRIBUTE_OPTION_QUALITY_NEW = 746;
  110.     public const int ATTRIBUTE_OPTION_QUALITY_PLATINUM = 747;
  111.     public const int ATTRIBUTE_OPTION_ID_NB_RAM_UPGRADED_8GB = 1707;
  112.     public const int ATTRIBUTE_OPTION_ID_NB_RAM_UPGRADED_16GB = 6073;
  113.     public const int ATTRIBUTE_OPTION_ID_NORTON_ANTIVIRUS = 6222;
  114.     public const int ATTRIBUTE_OPTION_ID_NORTON_ANTIVIRUS_FREE = 6256;
  115.     public const int ATTRIBUTE_OPTION_ID_GDATA_ANTIVIRUS = 5194;
  116.     public const int ATTRIBUTE_OPTION_ID_MACBOOK_FREE_MOUSE = 6328;
  117.     public const int ATTRIBUTE_OPTION_ID_NO_WEBCAM_FREE_WEBCAM = 6473;
  118.     public const int ATTRIBUTE_OPTION_ID_DISPLAY_PORT_CABLE = 1887;
  119.     public const int ATTRIBUTE_OPTION_ID_HDMI_CABLE = 1118;
  120.     public const int ATTRIBUTE_OPTION_ID_VGA_CABLE = 1004;
  121.     public const int ATTRIBUTE_OPTION_ID_DVI_CABLE = 1005;
  122.     public const int ATTRIBUTE_OPTION_ID_NEW_BATTERY = 730;
  123.     public const array SSD_TYPE_LIST = [
  124.         'M.2, NVMe',
  125.         'NVMe, M.2',
  126.         'eMMC',
  127.         'M.2',
  128.         'mSATA',
  129.         'uSATA',
  130.         'uSATA MLC',
  131.         'M.2 NVMe',
  132.         'NVMe',
  133.         'Sata',
  134.     ];
  135.     // Base Windows
  136.     public const int ATTRIBUTE_OPTION_ID_WINDOWS_10_PRO = 2128;
  137.     public const int ATTRIBUTE_OPTION_ID_WINDOWS_10_HOME = 2130;
  138.     public const int ATTRIBUTE_OPTION_ID_WINDOWS_11_PRO = 3508;
  139.     public const int ATTRIBUTE_OPTION_ID_WINDOWS_11_HOME = 5224;
  140.     public const int ATTRIBUTE_OPTION_ID_LINUX_MINT = 6368;
  141.     // Localised Windows
  142.     public const int ATTRIBUTE_OPTION_ID_WIN11_PRO_HU = 6102;
  143.     public const int ATTRIBUTE_OPTION_ID_WIN11_HOME_HU = 5707;
  144.     public const int ATTRIBUTE_OPTION_ID_WIN10_PRO_HU = 5588;
  145.     public const int ATTRIBUTE_OPTION_ID_WIN10_HOME_HU = 5688;
  146.     public const int ATTRIBUTE_OPTION_ID_WIN11_PRO_SK = 6100;
  147.     public const int ATTRIBUTE_OPTION_ID_WIN11_HOME_SK = 5706;
  148.     public const int ATTRIBUTE_OPTION_ID_WIN10_PRO_SK = 5587;
  149.     public const int ATTRIBUTE_OPTION_ID_WIN10_HOME_SK = 5687;
  150.     public const int ATTRIBUTE_OPTION_ID_WIN11_PRO_CZ = 6242;
  151.     public const int ATTRIBUTE_OPTION_ID_WIN11_HOME_CZ = 0;
  152.     public const int ATTRIBUTE_OPTION_ID_WIN10_PRO_CZ = 6241;
  153.     public const int ATTRIBUTE_OPTION_ID_WIN10_HOME_CZ = 0;
  154.     public const int ATTRIBUTE_OPTION_ID_WIN10_ES = 5541;
  155.     public const int ATTRIBUTE_OPTION_ID_POWER_CABLE_3_PIN = 5091;
  156.     public const int ATTRIBUTE_OPTION_ID_POWER_CABLE_CH_COMPUTER = 6875;
  157.     public const int ATTRIBUTE_OPTION_ID_POWER_CABLE_CH_NOTEBOOK = 6876;
  158.     public const int ATTRIBUTE_OPTION_ID_OFFICE = 698;
  159.     public const int ATTRIBUTE_OPTION_ID_BACKLIT = 4722;
  160.     public const int ATTRIBUTE_OPTION_ID_FINGERPRINT_READER = 564;
  161.     public const int ATTRIBUTE_OPTION_ID_FULL_HD_RESOLUTION = 632;
  162.     /**
  163.      * @return array
  164.      */
  165.     public static function getColorChoices()
  166.     {
  167.         return [
  168.             self::Color_None => self::Color_None,
  169.             self::Color_Blue => self::Color_Blue,
  170.             self::Color_Green => self::Color_Green,
  171.             self::Color_Grey => self::Color_Grey,
  172.         ];
  173.     }
  174.     /**
  175.      * Get attribute option groups
  176.      *
  177.      * Attribute option groups for merging rows. The order of the arrays determines the primary option.
  178.      *
  179.      * @return array
  180.      */
  181.     public static function getAttributeOptionGroups(): array
  182.     {
  183.         return [
  184.             Attribute::ATTRIBUTE_ID_SSD => [
  185.                 [
  186.                     self::ATTRIBUTE_OPTION_ID_SSD_500GB,
  187.                     self::ATTRIBUTE_OPTION_ID_SSD_512GB,
  188.                     self::ATTRIBUTE_OPTION_ID_SSD_480GB,
  189.                 ], [
  190.                     self::ATTRIBUTE_OPTION_ID_SSD_M2_500GB,
  191.                     self::ATTRIBUTE_OPTION_ID_SSD_M2_512GB,
  192.                     self::ATTRIBUTE_OPTION_ID_SSD_M2_480GB,
  193.                     self::ATTRIBUTE_OPTION_ID_SSD_M2_510GB,
  194.                     self::ATTRIBUTE_OPTION_ID_SSD_NVME_512GB,
  195.                 ],
  196.             ],
  197.         ];
  198.     }
  199.     public static function getYearAttributeOptionIds(): array
  200.     {
  201.         return [
  202.             2005 => self::ATTRIBUTE_YEAR_2005,
  203.             2006 => self::ATTRIBUTE_YEAR_2006,
  204.             2007 => self::ATTRIBUTE_YEAR_2007,
  205.             2008 => self::ATTRIBUTE_YEAR_2008,
  206.             2009 => self::ATTRIBUTE_YEAR_2009,
  207.             2010 => self::ATTRIBUTE_YEAR_2010,
  208.             2011 => self::ATTRIBUTE_YEAR_2011,
  209.             2012 => self::ATTRIBUTE_YEAR_2012,
  210.             2013 => self::ATTRIBUTE_YEAR_2013,
  211.             2014 => self::ATTRIBUTE_YEAR_2014,
  212.             2015 => self::ATTRIBUTE_YEAR_2015,
  213.             2016 => self::ATTRIBUTE_YEAR_2016,
  214.             2017 => self::ATTRIBUTE_YEAR_2017,
  215.             2018 => self::ATTRIBUTE_YEAR_2018,
  216.             2019 => self::ATTRIBUTE_YEAR_2019,
  217.             2020 => self::ATTRIBUTE_YEAR_2020,
  218.             2021 => self::ATTRIBUTE_YEAR_2021,
  219.             2022 => self::ATTRIBUTE_YEAR_2022,
  220.             2023 => self::ATTRIBUTE_YEAR_2023,
  221.             2024 => self::ATTRIBUTE_YEAR_2024,
  222.             2025 => self::ATTRIBUTE_YEAR_2025,
  223.             2026 => self::ATTRIBUTE_YEAR_2026,
  224.         ];
  225.     }
  226.     /**
  227.      * @var Attribute
  228.      *
  229.      * @Assert\NotNull
  230.      *
  231.      * @ManyToOne(targetEntity="Attribute", inversedBy="options")
  232.      * @JoinColumn(name="attribute_id", referencedColumnName="id")
  233.      */
  234.     private $attribute;
  235.     /**
  236.      * @var ArrayCollection
  237.      *
  238.      * @OneToMany(targetEntity="AttributeOption", mappedBy="parent")
  239.      * @OrderBy({"sortIndex" = "ASC"})
  240.      **/
  241.     private $children;
  242.     /**
  243.      * @ManyToOne(targetEntity="AttributeOption", inversedBy="children")
  244.      * @JoinColumn(name="parent_id", referencedColumnName="id")
  245.      **/
  246.     private $parent;
  247.     /**
  248.      * @var string
  249.      *
  250.      * @Assert\NotNull
  251.      *
  252.      * @Column(name="title", type="text")
  253.      */
  254.     private $title;
  255.     /**
  256.      * @var string
  257.      *
  258.      * @Column(name="long_title", type="text", nullable=true)
  259.      */
  260.     private $longTitle;
  261.     /**
  262.      * @var bool
  263.      *
  264.      * @Assert\NotNull
  265.      *
  266.      * @Column(name="private", type="boolean")
  267.      */
  268.     private $private = false;
  269.     /**
  270.      * @var bool
  271.      *
  272.      * @Assert\NotNull
  273.      *
  274.      * @Column(name="in_short_desc", type="boolean")
  275.      */
  276.     private $inShortDesc = true;
  277.     /**
  278.      * @var bool
  279.      *
  280.      * @Assert\NotNull
  281.      *
  282.      * @Column(name="archived", type="boolean")
  283.      */
  284.     private $archived = false;
  285.     /**
  286.      * @var integer
  287.      *
  288.      * @Assert\NotNull
  289.      *
  290.      * @Column(name="sort_index", type="integer")
  291.      */
  292.     private $sortIndex = -1;
  293.     /**
  294.      * @var ArrayCollection
  295.      *
  296.      * @OneToMany(targetEntity="AttributeOptionMeta", mappedBy="attributeOption", cascade={"persist", "remove"})
  297.      **/
  298.     private $metas;
  299.     /**
  300.      * @var ArrayCollection
  301.      *
  302.      * @Assert\Valid
  303.      *
  304.      * @OneToMany(targetEntity="ProductAttribute", mappedBy="option")
  305.      **/
  306.     private $productAttributes;
  307.     /**
  308.      * @ManyToOne(targetEntity="Product")
  309.      * @JoinColumn(name="product_id", referencedColumnName="id")
  310.      **/
  311.     private $product;
  312.     public function __construct()
  313.     {
  314.         parent::__construct();
  315.         $this->children = new ArrayCollection();
  316.         $this->metas = new ArrayCollection();
  317.     }
  318.     /**
  319.      * @param TranslatorInterface $translator
  320.      * @return string
  321.      */
  322.     public function getTitle(TranslatorInterface $translator = null)
  323.     {
  324.         return $translator !== null ? $translator->trans($this->title) : $this->title;
  325.     }
  326.     /**
  327.      * @param TranslatorInterface $translator
  328.      * @return string
  329.      */
  330.     public function getLongTitle(TranslatorInterface $translator = null)
  331.     {
  332.         return $translator !== null ? $translator->trans($this->longTitle) : $this->longTitle;
  333.     }
  334.     /**
  335.      * @param string $longTitle
  336.      */
  337.     public function setLongTitle($longTitle)
  338.     {
  339.         $this->longTitle = $longTitle;
  340.     }
  341.     /**
  342.      * @param TranslatorInterface $translator
  343.      * @return string which contains the attribute and the attribute option too.
  344.      */
  345.     public function getFullTitle(TranslatorInterface $translator = null)
  346.     {
  347.         return $this->attribute->getTitle($translator) . ': ' . $this->getTitle($translator);
  348.     }
  349.     //for debugging the order
  350.     //    public function getFullTitle(TranslatorInterface $translator = null){
  351.     //        return $this->attribute->getSortIndex().','.(is_null($this->parent)?$this->getSortIndex():($this->getParent()->getSortIndex().','.$this->getSortIndex()));
  352.     //    }
  353.     /**
  354.      * @param string $title
  355.      */
  356.     public function setTitle($title)
  357.     {
  358.         $this->title = $title;
  359.     }
  360.     /**
  361.      * @return Attribute
  362.      */
  363.     public function getAttribute()
  364.     {
  365.         return $this->attribute;
  366.     }
  367.     /**
  368.      * @param Attribute $attribute
  369.      */
  370.     public function setAttribute($attribute)
  371.     {
  372.         $this->attribute = $attribute;
  373.         $attribute->addOption($this);
  374.     }
  375.     /**
  376.      * @param Domain $domain
  377.      * @return float
  378.      */
  379.     public function getDomainPrice($domain)
  380.     {
  381.         return round($this->getDomainVatPrice($domain) / (1 + $domain->getVat() / 100.), $domain->getPricePrecision(), PHP_ROUND_HALF_UP);
  382.     }
  383.     /**
  384.      * @param Domain $domain
  385.      * @return float
  386.      */
  387.     public function getDomainVatPrice($domain)
  388.     {
  389.         $attributeOptionMeta = $this->getDomainMeta($domain);
  390.         if ($attributeOptionMeta == null) {
  391.             return 0;
  392.         }
  393.         return $domain->createVatPrice($attributeOptionMeta->getPrice());
  394.     }
  395.     /**
  396.      * @return boolean
  397.      */
  398.     public function hasParent()
  399.     {
  400.         return $this->parent != null;
  401.     }
  402.     /**
  403.      * @return AttributeOption
  404.      */
  405.     public function getParent()
  406.     {
  407.         return $this->parent;
  408.     }
  409.     /**
  410.      * @param AttributeOption $parent
  411.      */
  412.     public function setParent($parent)
  413.     {
  414.         $this->parent = $parent;
  415.         if (!is_null($this->parent)) {
  416.             $parent->addChildren($this);
  417.         }
  418.     }
  419.     /**
  420.      * @return boolean
  421.      */
  422.     public function hasChildren()
  423.     {
  424.         return count($this->children) > 0;
  425.     }
  426.     /**
  427.      * @return mixed
  428.      */
  429.     public function getChildren()
  430.     {
  431.         return $this->children;
  432.     }
  433.     /**
  434.      * Add AttributeOption
  435.      *
  436.      * @param AttributeOption $option
  437.      * @return AttributeOption
  438.      */
  439.     public function addChildren($option)
  440.     {
  441.         if (!$this->children->contains($option)) {
  442.             $this->children->add($option);
  443.             $option->setParent($this);
  444.         }
  445.         return $this;
  446.     }
  447.     /**
  448.      * Remove AttributeOption
  449.      *
  450.      * @param AttributeOption $option
  451.      * @return AttributeOption
  452.      */
  453.     public function removeProductAttribute($option)
  454.     {
  455.         if ($this->children->contains($option)) {
  456.             $this->children->remove($option);
  457.         }
  458.         return $this;
  459.     }
  460.     /**
  461.      * @param TranslatorInterface $translator
  462.      * @param string $ext
  463.      * @return string without php
  464.      * @internal param array $translationArray
  465.      */
  466.     public function getPageFileName(TranslatorInterface $translator = null, $ext = '.php')
  467.     {
  468.         $name = preg_replace('/^\W+|\W+$/', '', TranslationHelper::ascii_convert($this->getTitle($translator)));
  469.         $name = preg_replace('/\W+/', '-', $name);
  470.         return strtolower($name) . $ext;
  471.     }
  472.     /**
  473.      * @return boolean
  474.      */
  475.     public function isPrivate()
  476.     {
  477.         return $this->private;
  478.     }
  479.     /**
  480.      * @param boolean $private
  481.      */
  482.     public function setPrivate($private)
  483.     {
  484.         $this->private = $private;
  485.     }
  486.     /**
  487.      * @return boolean
  488.      */
  489.     public function isInShortDesc()
  490.     {
  491.         return $this->inShortDesc;
  492.     }
  493.     /**
  494.      * @param boolean $inShortDesc
  495.      */
  496.     public function setInShortDesc($inShortDesc)
  497.     {
  498.         $this->inShortDesc = $inShortDesc;
  499.     }
  500.     /**
  501.      * @return int
  502.      */
  503.     public function getSortIndex()
  504.     {
  505.         return $this->sortIndex;
  506.     }
  507.     /**
  508.      * @param int $sortIndex
  509.      */
  510.     public function setSortIndex($sortIndex)
  511.     {
  512.         $this->sortIndex = $sortIndex;
  513.     }
  514.     /**
  515.      * @return ArrayCollection
  516.      */
  517.     public function getMetas()
  518.     {
  519.         return $this->metas;
  520.     }
  521.     /**
  522.      * @param ArrayCollection $metas
  523.      */
  524.     public function setMetas($metas)
  525.     {
  526.         $this->metas = $metas;
  527.     }
  528.     /**
  529.      * Add AttributeOptionMeta
  530.      *
  531.      * @param AttributeOptionMeta $meta
  532.      * @return AttributeOption
  533.      */
  534.     public function addMeta($meta)
  535.     {
  536.         if (!$this->metas->contains($meta)) {
  537.             $this->metas->add($meta);
  538.             $meta->setAttributeOption($this);
  539.         }
  540.         return $this;
  541.     }
  542.     /**
  543.      * @param Domain $domain
  544.      * @return AttributeOptionMeta|null
  545.      */
  546.     public function getDomainMeta(Domain $domain)
  547.     {
  548.         if ($this->getMetas()->count() > 0) {
  549.             foreach ($this->getMetas() as $meta) {
  550.                 if ($meta->getDomain()->getId() == $domain->getId()) {
  551.                     return $meta;
  552.                 }
  553.             }
  554.         }
  555.         return null;
  556.     }
  557.     /**
  558.      * @return ArrayCollection
  559.      */
  560.     public function getProductAttributes()
  561.     {
  562.         return $this->productAttributes;
  563.     }
  564.     /**
  565.      * @param ArrayCollection $productAttributes
  566.      */
  567.     public function setProductAttributes($productAttributes)
  568.     {
  569.         $this->productAttributes = $productAttributes;
  570.     }
  571.     /**
  572.      * @return boolean
  573.      */
  574.     public function isArchived()
  575.     {
  576.         return $this->archived;
  577.     }
  578.     /**
  579.      * @param boolean $archived
  580.      */
  581.     public function setArchived($archived)
  582.     {
  583.         $this->archived = $archived;
  584.     }
  585.     /**
  586.      * @return Product
  587.      */
  588.     public function getProduct()
  589.     {
  590.         return $this->product;
  591.     }
  592.     /**
  593.      * @param Product $product
  594.      */
  595.     public function setProduct($product)
  596.     {
  597.         $this->product = $product;
  598.     }
  599.     /**
  600.      * @return bool
  601.      */
  602.     public function isBacklit(): bool
  603.     {
  604.         return str_ends_with($this->title, 'backlit');
  605.     }
  606.     /**
  607.      * @return string|null
  608.      */
  609.     public function getReprintLanguageCode(): ?string
  610.     {
  611.         if ($this->attribute->getId() !== Attribute::ATTRIBUTE_ID_ACCESSORY_KEYBOARD_REPRINT) {
  612.             return null;
  613.         }
  614.         if ($this->getId() == 2443) { // Don't need
  615.             return null;
  616.         }
  617.         $title = str_ireplace(['Keyboard reprint', 'backlit'], '', $this->longTitle);
  618.         $languageCode = mb_strtoupper(trim($title));
  619.         if (mb_strlen($languageCode) == 3) {
  620.             return $languageCode;
  621.         }
  622.         if ($languageCode === 'SK-CZ') {
  623.             return $languageCode;
  624.         }
  625.         return StockItem::KEYBOARD_LANGUAGE_VALID_VALUE_LIST[$languageCode] ?? null;
  626.     }
  627. }