src/Model/DefaultProduct.php line 819

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Enterprise License (PEL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  * @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  * @license    http://www.pimcore.org/license     GPLv3 and PEL
  13.  */
  14. namespace App\Model;
  15. use App\Model\Product\TraitClasses\Checkoutable;
  16. use App\Tool\AdminStyle;
  17. use App\Tool\SizeSort;
  18. use Pimcore\Cache;
  19. use Pimcore\Model\DataObject\AbstractObject;
  20. use Pimcore\Model\DataObject\Folder;
  21. use Pimcore\Model\DataObject\Product;
  22. use App\Model\DefaultMarca;
  23. class DefaultProduct extends Product
  24. {
  25.     use Checkoutable;
  26.     protected const GENERAL_ATTRIBUTES = [
  27.         'unitCount',
  28.     ];
  29.     public static function generalAttributeKeys(): array
  30.     {
  31.         return self::GENERAL_ATTRIBUTES;
  32.     }
  33.     private $internationalSizeOrden = array('XXS''XS''S''M''L''XL''XXL''3XL''4XL');
  34.     public function getElementAdminStyle()
  35.     {
  36.         if (!$this->o_elementAdminStyle) {
  37.             $this->o_elementAdminStyle = new AdminStyle($this);
  38.         }
  39.         return $this->o_elementAdminStyle;
  40.     }
  41.     public function save()
  42.     {
  43.         parent::save();
  44.         Cache::clearTag('object_' $this->internalGetBaseProduct()->getId());
  45.     }
  46.     public function isActive($inProductList false): bool
  47.     {
  48.         return $this->isPublished();
  49.     }
  50.     public function getOSDoIndexProduct(): bool
  51.     {
  52.         if ($this->getType() == 'object' && $this->getParent() instanceof Product) {
  53.             return false;
  54.         } else {
  55.             return true;
  56.         }
  57.     }
  58.     public function getOSParentId()
  59.     {
  60.         if ($this->getType() == 'variant' && $this->getParent()->getParent() instanceof Product) {
  61.             return $this->getParent()->getParent()->getId();
  62.         } elseif ($this->getParent() instanceof Product) {
  63.             return parent::getOSParentId();
  64.         } else {
  65.             return $this->getId();
  66.         }
  67.     }
  68.     /*
  69.      *
  70.      * Own functions for bsnbarcelona products
  71.      */
  72.     public function getMarcaObject()
  73.     {
  74.         if (method_exists($this"getMarca")) {
  75.             $marcaId $this->getMarca();
  76.             if ($marcaId 0) {
  77.                 return DefaultMarca::getById($marcaId);
  78.             }
  79.         }
  80.         return null;
  81.     }
  82.     public function getAttributeRelationProductTypeArray()
  83.     {
  84.         $types = array();
  85.         $attributes $this->getAllAttributes($this);
  86.         if (key_exists("relationproducts"$attributes)) {
  87.             $relationsproducts $this->getAttributeValue($attributes["relationproducts"]);
  88.             if ($relationsproducts) {
  89.                 foreach ($relationsproducts as $item) {
  90.                     if (!(array_key_exists($item->getTipo(), $types))) {
  91.                         $types[$item->getTipo()] = array();
  92.                     }
  93.                 }
  94.             }
  95.         }
  96.         return $types;
  97.     }
  98.     public function getCatalizador()
  99.     {
  100.         $catalizadores = array();
  101.         $attributes $this->getAllAttributes($this);
  102.         if (key_exists("relationproducts"$attributes)) {
  103.             $relationsproducts $this->getAttributeValue($attributes["relationproducts"]);
  104.             if ($relationsproducts) {
  105.                 foreach ($relationsproducts as $item) {
  106.                     if ($item->getTipo() == "Catalizador") {
  107.                         $catalizadores[] = $item;
  108.                     }
  109.                 }
  110.             }
  111.         }
  112.         return $catalizadores;
  113.     }
  114.     public function getKit()
  115.     {
  116.         $kit = array();
  117.         $attributes $this->getAllAttributes($this);
  118.         if (key_exists("relationproducts"$attributes)) {
  119.             $relationsproducts $this->getAttributeValue($attributes["relationproducts"]);
  120.             if ($relationsproducts) {
  121.                 foreach ($relationsproducts as $item) {
  122.                     if ($item->getTipo() == "Kit") {
  123.                         $kit[] = $item;
  124.                     }
  125.                 }
  126.             }
  127.         }
  128.         return $kit;
  129.     }
  130.     public function getDisolvente()
  131.     {
  132.         $disolventes = array();
  133.         $attributes $this->getAllAttributes($this);
  134.         if (key_exists("relationproducts"$attributes)) {
  135.             $relationsproducts $this->getAttributeValue($attributes["relationproducts"]);
  136.             if ($relationsproducts) {
  137.                 foreach ($relationsproducts as $item) {
  138.                     if ($item->getTipo() == "Disolvente") {
  139.                         $disolventes[] = $item;
  140.                     }
  141.                 }
  142.             }
  143.         }
  144.         return $disolventes;
  145.     }
  146.     public function getCleaner()
  147.     {
  148.         $cleaners = array();
  149.         $attributes $this->getAllAttributes($this);
  150.         if (key_exists("relationproducts"$attributes)) {
  151.             $relationsproducts $this->getAttributeValue($attributes["relationproducts"]);
  152.             if ($relationsproducts) {
  153.                 foreach ($relationsproducts as $item) {
  154.                     if ($item->getTipo() == "Cleaner") {
  155.                         $cleaners[] = $item;
  156.                     }
  157.                 }
  158.             }
  159.         }
  160.         return $cleaners;
  161.     }
  162.     public function getReducer()
  163.     {
  164.         $reducers = array();
  165.         $attributes $this->getAllAttributes($this);
  166.         if (key_exists("relationproducts"$attributes)) {
  167.             $relationsproducts $this->getAttributeValue($attributes["relationproducts"]);
  168.             if ($relationsproducts) {
  169.                 foreach ($relationsproducts as $item) {
  170.                     if ($item->getTipo() == "Reducer") {
  171.                         $reducers[] = $item;
  172.                     }
  173.                 }
  174.             }
  175.         }
  176.         return $reducers;
  177.     }
  178.     public function getActivador()
  179.     {
  180.         $activadores = array();
  181.         $attributes $this->getAllAttributes($this);
  182.         if (key_exists("relationproducts"$attributes)) {
  183.             $relationsproducts $this->getAttributeValue($attributes["relationproducts"]);
  184.             if ($relationsproducts) {
  185.                 foreach ($relationsproducts as $item) {
  186.                     if ($item->getTipo() == "Activador") {
  187.                         $activadores[] = $item;
  188.                     }
  189.                 }
  190.             }
  191.         }
  192.         return $activadores;
  193.     }
  194.     public function getComplement()
  195.     {
  196.         $activadores = array();
  197.         $attributes $this->getAllAttributes($this);
  198.         if (key_exists("relationproducts"$attributes)) {
  199.             $relationsproducts $this->getAttributeValue($attributes["relationproducts"]);
  200.             if ($relationsproducts) {
  201.                 foreach ($relationsproducts as $item) {
  202.                     if ($item->getTipo() == "Complemento") {
  203.                         $activadores[] = $item;
  204.                     }
  205.                 }
  206.             }
  207.         }
  208.         return $activadores;
  209.     }
  210.     public function getConverter()
  211.     {
  212.         $converters = array();
  213.         $attributes $this->getAllAttributes($this);
  214.         if (key_exists("relationproducts"$attributes)) {
  215.             $relationsproducts $this->getAttributeValue($attributes["relationproducts"]);
  216.             if ($relationsproducts) {
  217.                 foreach ($relationsproducts as $item) {
  218.                     if ($item->getTipo() == "Converter") {
  219.                         $converters[] = $item;
  220.                     }
  221.                 }
  222.             }
  223.         }
  224.         return $converters;
  225.     }
  226.     public function getBase()
  227.     {
  228.         $base = array();
  229.         $attributes $this->getAllAttributes($this);
  230.         if (key_exists("relationproducts"$attributes)) {
  231.             $relationsproducts $this->getAttributeValue($attributes["relationproducts"]);
  232.             if ($relationsproducts) {
  233.                 foreach ($relationsproducts as $item) {
  234.                     if ($item->getTipo() == "Base") {
  235.                         $base[] = $item;
  236.                     }
  237.                 }
  238.             }
  239.         }
  240.         return $base;
  241.     }
  242.     public function getProporcionMezcla()
  243.     {
  244.         $proporcion = array();
  245.         $attributes $this->getAllAttributes($this);
  246.         if (key_exists("relationproducts"$attributes)) {
  247.             $relationsproducts $this->getAttributeValue($attributes["relationproducts"]);
  248.             if ($relationsproducts) {
  249.                 foreach ($relationsproducts as $item) {
  250.                     if (!empty(trim("" $item->getMezcla()))) {
  251.                         $proporcion[] = trim("" $item->getMezcla());
  252.                     }
  253.                 }
  254.             }
  255.         }
  256.         return $proporcion;
  257.     }
  258.     public function getDimensiones($fields = array('ancho''largo''alto'))
  259.     {
  260.         $dimension "";
  261.         $attributes $this->getAllAttributes($this);
  262.         $counter = -1;
  263.         $quantityArray = array();
  264.         $unitArray = array();
  265.         foreach ($fields as $field) {
  266.             if (key_exists($field$attributes)) {
  267.                 $value $this->getAttributeValue($attributes[$field]);
  268.                 switch ($attributes[$field]["fieldtype"]) {
  269.                     case "inputQuantityValue":
  270.                     case "quantityValue":
  271.                         if ($value) {
  272.                             $valorNumerico trim("" $value->getValue());
  273.                             $unidad = !is_null($value->getUnit()) ? trim("" $value->getUnit()->getAbbreviation()) : "";
  274.                             if (!empty($valorNumerico)) {
  275.                                 $counter++;
  276.                                 $quantityArray[$counter] = $valorNumerico;
  277.                                 if (!empty($unidad)) {
  278.                                     $unitArray[$counter] = $unidad;
  279.                                 }
  280.                             }
  281.                         }
  282.                         break;
  283.                     default:
  284.                         if (!empty($value)) {
  285.                             $dimension $value;
  286.                         }
  287.                 }
  288.             }
  289.         }
  290.         if (count($quantityArray) > 0) {
  291.             if (count(array_unique($unitArray)) > 1) {
  292.                 foreach ($quantityArray as $key => $value) {
  293.                     $unit = isset($unitArray[$key]) ? trim("" $unitArray[$key]) : "";
  294.                     if (!($unit == "\"" || $unit == "'" || $unit == "º" || $unit == "")) {
  295.                         $unit "&nbsp;" $unit;
  296.                     }
  297.                     if (!empty(trim("" $value))) {
  298.                         $quantityArray[$key] = trim("" $value $unit);
  299.                     }
  300.                 }
  301.                 $dimension implode(" x "$quantityArray);
  302.             } else {
  303.                 $unit count($unitArray) > trim("" array_pop($unitArray)) : "";
  304.                 if (!($unit == "\"" || $unit == "'" || $unit == "º" || $unit == "")) {
  305.                     $unit "&nbsp;" $unit;
  306.                 }
  307.                 $dimension trim("" implode(" x "$quantityArray) . $unit);
  308.             }
  309.         } else {
  310.             return "";
  311.         }
  312.         return $dimension;
  313.     }
  314.     public function getOldDimensionesList($fields = array('ancho''largo''alto'))
  315.     {
  316.         $variants $this->getAllActiveVariants();
  317.         $attributes $this->getAllAttributes($this);
  318.         $dimensionesList = array();
  319.         if (count($variants) > 0) {
  320.             foreach ($variants as $variant) {
  321.                 $dimension $variant->getDimensiones($fields);
  322.                 if (!empty($dimension)) {
  323.                     $dimensionArray explode_and_trim(" x "$dimension);
  324.                     $valueUnitArray explode_and_trim(" "$dimensionArray[count($dimensionArray) - 1]);
  325.                     $defaultUnit "";
  326.                     if (count($valueUnitArray) == 2) {
  327.                         $defaultUnit $valueUnitArray[1];
  328.                     }
  329.                     $key "";
  330.                     foreach ($dimensionArray as $valueUnit) {
  331.                         $valueUnitArray explode_and_trim(" "$valueUnit);
  332.                         $unit $defaultUnit;
  333.                         $value $valueUnitArray[0];
  334.                         if (count($valueUnitArray) == 2) {
  335.                             $unit $valueUnitArray[1];
  336.                         }
  337.                         $key is_string($this->convertToMM($value$unit) ? '' $key "_" str_pad(floor($this->convertToMM($value$unit)), 6"0"STR_PAD_LEFT));
  338.                     }
  339.                     $key trim($key"_");
  340.                     if (in_array('tallainternational'$fields) && in_array($dimension$this->internationalSizeOrden)) {
  341.                         $key array_search($dimension$this->internationalSizeOrden);
  342.                         $key str_pad($key6"0"STR_PAD_LEFT);
  343.                     }
  344.                     $dimensionesList[$key] = $dimension;
  345.                 }
  346.             }
  347.         } else {
  348.             $dimension $this->getDimensiones($fields);
  349.             if (!empty($dimension)) {
  350.                 $dimensionesList["000000"] = $dimension;
  351.             }
  352.         }
  353.         ksort($dimensionesList);
  354.         return $dimensionesList;
  355.     }
  356.     public function getDimensionesList($fields = array('ancho''largo''alto'))
  357.     {
  358.         $dimensionesList = array();
  359.         $dimension $this->getDimensiones($fields);
  360.         if (!empty($dimension)) {
  361.             $dimensionesList["000000"] = $dimension;
  362.         }
  363.         ksort($dimensionesList);
  364.         return $dimensionesList;
  365.     }
  366.     public function getCapacity()
  367.     {
  368.         try {
  369.             $capacity $this->getAttributeValue($this->getAllAttributes($this)["capacidad"]);
  370.             return [
  371.                 'value' => $capacity->getValue(),
  372.                 'unit' => strtoupper($capacity->getUnit()->getAbbreviation())
  373.             ];
  374.         } catch (\Throwable $th) {
  375.             return [
  376.                 'value' => '',
  377.                 'unit' => ''
  378.             ];
  379.         }
  380.     }
  381.     public function getColor()
  382.     {
  383.         try {
  384.             $colorId $this->getAttributeValue($this->getAllAttributes($this)["color"]);
  385.             $color \Pimcore\Model\DataObject\Colores::getById($colorId);
  386.             return [
  387.                 'name' => $color->getName(),
  388.                 'hex' => implode(","$color->getHex()->getCssRgba()),
  389.             ];
  390.         } catch (\Throwable $th) {
  391.             if (is_null($color)){
  392.                 return [
  393.                     'name' => '',
  394.                     'hex' => '',
  395.                 ];
  396.             }else{
  397.                 return [
  398.                     'name' => $color->getName(),
  399.                     'hex' => '',
  400.                 ];
  401.             }
  402.         }
  403.     }
  404.     public function getPresentacionsList($fields = array('presentacion''capacidad'))
  405.     {
  406.         $variants $this->getAllActiveVariants();
  407.         $attributes $this->getAllAttributes($this);
  408.         $presentacionsList = array();
  409.         if (count($fields) == 2) {
  410.             if (count($variants) > 0) {
  411.                 if (key_exists($fields[0], $attributes)) {
  412.                     foreach ($variants as $variant) {
  413.                         $key $variant->getAttributeValue($attributes[$fields[0]]);
  414.                         $value "";
  415.                         if (!key_exists($key$presentacionsList)) {
  416.                             $presentacionsList[$key] = array();
  417.                         }
  418.                         if (key_exists($fields[1], $attributes)) {
  419.                             $value $variant->getAttributeValue($attributes[$fields[1]]);
  420.                             if (key_exists($fields[1], $attributes)) {
  421.                                 switch ($attributes[$fields[1]]["fieldtype"]) {
  422.                                     case "inputQuantityValue" :
  423.                                     case "quantityValue" :
  424.                                         $quantity = ($value && method_exists($value"getValue")) ? trim("" $value->getValue()) : "";
  425.                                         $unit = ($value && method_exists($value"getValue")) ? trim("" $value->getUnit()->getAbbreviation()) : "";
  426.                                         $value "";
  427.                                         if (!empty($quantity)) {
  428.                                             $value $quantity "&nbsp;" $unit;
  429.                                             switch (true) {
  430.                                                 case(in_array($unit, array("ml""l""pt""gal"))) :
  431.                                                     $orderKey floor($this->convertToML($quantity$unit));
  432.                                                     break;
  433.                                                 case(in_array($unit, array("kg""g"))) :
  434.                                                     $orderKey floor($this->convertToMG($quantity$unit));
  435.                                                     break;
  436.                                                 case(in_array($unit, array("mm""cm""m"))) :
  437.                                                     $orderKey floor($this->convertToMM($quantity$unit));
  438.                                                     break;
  439.                                                 default :
  440.                                                     $orderKey $quantity;
  441.                                             }
  442.                                         }
  443.                                         break;
  444.                                     default:
  445.                                         $orderKey $variant->getAttributeValue($attributes[$fields[1]]);
  446.                                 }
  447.                             }
  448.                             if (!empty($value)) {
  449.                                 $orderKey str_pad($orderKey6"0"STR_PAD_LEFT);
  450.                                 $presentacionsList[$key][$orderKey] = trim("" $value);
  451.                             }
  452.                         }
  453.                     }
  454.                 }
  455.             } else {
  456.                 if (key_exists($fields[0], $attributes)) {
  457.                     $key $this->getAttributeValue($attributes[$fields[0]]);
  458. //                    if ($key == null) {
  459. //                        $parent = $this->getParent();
  460. //                        if ($parent->o_type == "object") {
  461. //                      //      $key = $parent->getAttributeValue($attributes[$fields[0]]);
  462. //                        }
  463. //                    }
  464.                     $presentacionsList[$key] = array();
  465.                     if (key_exists($fields[1], $attributes)) {
  466.                         $orderKey str_pad(""6"0"STR_PAD_LEFT);
  467.                         $value $this->getAttributeValue($attributes[$fields[1]]);
  468.                         if (key_exists($fields[1], $attributes)) {
  469.                             switch ($attributes[$fields[1]]["fieldtype"]) {
  470.                                 case "inputQuantityValue" :
  471.                                 case "quantityValue" :
  472.                                     $quantity = ($value && method_exists($value"getValue")) ? trim("" $value->getValue()) : "";
  473.                                     $unit = ($value && method_exists($value"getUnit") && $value->getUnit()) ? trim("" $value->getUnit()->getAbbreviation()) : "";
  474.                                     $value "";
  475.                                     if (!empty($quantity)) {
  476.                                         $value $quantity "&nbsp;" $unit;
  477.                                         switch (true) {
  478.                                             case(in_array($unit, array("ml""l""pt""gal"))) :
  479.                                                 $orderKey floatval($this->convertToML($quantity$unit));
  480.                                                 break;
  481.                                             case(in_array($unit, array("kg""g"))) :
  482.                                                 $sortvalue floatval($this->convertToMG($quantity$unit));
  483.                                                 break;
  484.                                             case(in_array($unit, array("mm""cm""m"))) :
  485.                                                 $sortvalue floatval($this->convertToMM($quantity$unit));
  486.                                                 break;
  487.                                             default :
  488.                                                 $orderKey $quantity;
  489.                                         }
  490.                                     }
  491.                                     break;
  492.                                 default:
  493.                                     $orderKey $this->getAttributeValue($attributes[$fields[1]]);
  494.                             }
  495.                             if (!empty($value)) {
  496.                                 $orderKey str_pad($orderKey6"0"STR_PAD_LEFT);
  497.                                 $presentacionsList[$key][$orderKey] = trim("" $value);
  498.                             }
  499.                         }
  500.                     }
  501.                 }
  502.             }
  503.         }
  504.         foreach ($presentacionsList as $key => $value) {
  505.             ksort($presentacionsList[$key]);
  506.         }
  507.         $hasValues true;
  508.         if (count($presentacionsList) == 1) {
  509.             foreach ($presentacionsList as $key => $value) {
  510.                 if ((empty($key)) && (count($value) == 0)) {
  511.                     $presentacionsList = array();
  512.                 }
  513.             }
  514.         }
  515.         return $presentacionsList;
  516.     }
  517.     public function getPresentation(){
  518.         $attributes $this->getAllAttributes($this);
  519.         $presentacion "";
  520.         if (key_exists("presentacion"$attributes)) {
  521.             $key $this->getAttributeValue($attributes["presentacion"]);
  522.             $presentacion $key;
  523.         }
  524.         return $presentacion;
  525.     }
  526.     public function getCapacidad($field 'capacidad'){
  527.         $attributes $this->getAllAttributes($this);
  528.         $presentacionsList = array();
  529.         if (key_exists($field$attributes)) {
  530.             $orderKey str_pad(""6"0"STR_PAD_LEFT);
  531.             $value $this->getAttributeValue($attributes[$field]);
  532.             if (key_exists($field$attributes)) {
  533.                 switch ($attributes[$field]["fieldtype"]) {
  534.                     case "inputQuantityValue" :
  535.                     case "quantityValue" :
  536.                         $quantity = ($value && method_exists($value"getValue")) ? trim("" $value->getValue()) : "";
  537.                         $unit = ($value && method_exists($value"getUnit") && $value->getUnit()) ? trim("" $value->getUnit()->getAbbreviation()) : "";
  538.                         $value "";
  539.                         if (!empty($quantity)) {
  540.                             $value $quantity "&nbsp;" $unit;
  541.                             switch (true) {
  542.                                 case(in_array($unit, array("ml""l""pt""gal"))) :
  543.                                     $orderKey floatval($this->convertToML($quantity$unit));
  544.                                     break;
  545.                                 case(in_array($unit, array("kg""g"))) :
  546.                                     $sortvalue floatval($this->convertToMG($quantity$unit));
  547.                                     break;
  548.                                 case(in_array($unit, array("mm""cm""m"))) :
  549.                                     $sortvalue floatval($this->convertToMM($quantity$unit));
  550.                                     break;
  551.                                 default :
  552.                                     $orderKey $quantity;
  553.                             }
  554.                         }
  555.                         break;
  556.                     default:
  557.                         $orderKey $this->getAttributeValue($attributes[$fields[1]]);
  558.                 }
  559.                 if (!empty($value)) {
  560.                     $orderKey str_pad($orderKey6"0"STR_PAD_LEFT);
  561.                     $presentacionsList[$orderKey] = trim("" $value);
  562.                 }
  563.             }
  564.         }
  565.         return $presentacionsList;
  566.     }
  567.     public function getOldPresentation($fields = array('presentacion''capacidad'))
  568.     {
  569.         $attributes $this->getAllAttributes($this);
  570.         $presentacionsList = array();
  571.         if (count($fields) == 2) {
  572.             if (key_exists($fields[0], $attributes)) {
  573.                 $key $this->getAttributeValue($attributes[$fields[0]]);
  574. //                    if ($key == null) {
  575. //                        $parent = $this->getParent();
  576. //                        if ($parent->o_type == "object") {
  577. //                      //      $key = $parent->getAttributeValue($attributes[$fields[0]]);
  578. //                        }
  579. //                    }
  580.                 $presentacionsList[$key] = array();
  581.                 if (key_exists($fields[1], $attributes)) {
  582.                     $orderKey str_pad(""6"0"STR_PAD_LEFT);
  583.                     $value $this->getAttributeValue($attributes[$fields[1]]);
  584.                     if (key_exists($fields[1], $attributes)) {
  585.                         switch ($attributes[$fields[1]]["fieldtype"]) {
  586.                             case "inputQuantityValue" :
  587.                             case "quantityValue" :
  588.                                 $quantity = ($value && method_exists($value"getValue")) ? trim("" $value->getValue()) : "";
  589.                                 $unit = ($value && method_exists($value"getUnit") && $value->getUnit()) ? trim("" $value->getUnit()->getAbbreviation()) : "";
  590.                                 $value "";
  591.                                 if (!empty($quantity)) {
  592.                                     $value $quantity "&nbsp;" $unit;
  593.                                     switch (true) {
  594.                                         case(in_array($unit, array("ml""l""pt""gal"))) :
  595.                                             $orderKey floatval($this->convertToML($quantity$unit));
  596.                                             break;
  597.                                         case(in_array($unit, array("kg""g"))) :
  598.                                             $sortvalue floatval($this->convertToMG($quantity$unit));
  599.                                             break;
  600.                                         case(in_array($unit, array("mm""cm""m"))) :
  601.                                             $sortvalue floatval($this->convertToMM($quantity$unit));
  602.                                             break;
  603.                                         default :
  604.                                             $orderKey $quantity;
  605.                                     }
  606.                                 }
  607.                                 break;
  608.                             default:
  609.                                 $orderKey $this->getAttributeValue($attributes[$fields[1]]);
  610.                         }
  611.                         if (!empty($value)) {
  612.                             $orderKey str_pad($orderKey6"0"STR_PAD_LEFT);
  613.                             $presentacionsList[$key][$orderKey] = trim("" $value);
  614.                         }
  615.                     }
  616.                 }
  617.             }
  618.         }
  619.         foreach ($presentacionsList as $key => $value) {
  620.             ksort($presentacionsList[$key]);
  621.         }
  622.         $hasValues true;
  623.         if (count($presentacionsList) == 1) {
  624.             foreach ($presentacionsList as $key => $value) {
  625.                 if ((empty($key)) && (count($value) == 0)) {
  626.                     $presentacionsList = array();
  627.                 }
  628.             }
  629.         }
  630.         return $presentacionsList;
  631.     }
  632.     public function getColorList()
  633.     {
  634.         $variants $this->getAllActiveVariants();
  635.         $attributes $this->getAllAttributes($this);
  636.         $colorList = array();
  637.         if (count($variants) > 0) {
  638.             if (key_exists('color'$attributes)) {
  639.                 foreach ($variants as $variant) {
  640.                     $colorId $variant->getAttributeValue($attributes['color']);
  641.                     if ($colorId 0) {
  642.                         $colorObj \Pimcore\Model\DataObject\Colores::getById($colorId);
  643.                         if (!empty($colorObj)) {
  644.                             $colorList[$colorObj->getId()] = $colorObj;
  645.                         }
  646.                     }
  647.                 }
  648.             }
  649.         } else {
  650.             if (key_exists('color'$attributes)) {
  651.                 $colorId $this->getAttributeValue($attributes['color']);
  652.                 if ($colorId 0) {
  653.                     $colorObj \Pimcore\Model\DataObject\Colores::getById($colorId);
  654.                     if (!empty($colorObj)) {
  655.                         $colorList[$colorObj->getId()] = $colorObj;
  656.                     }
  657.                 }
  658.             }
  659.         }
  660.         ksort($colorList1);
  661.         return $colorList;
  662.     }
  663.     public function getVariantPriceList()
  664.     {
  665.         $variants $this->getAllActiveVariants();
  666.         $precios = array();
  667.         // $parentPrice = floatval(str_replace(",", ".", str_replace(".", "", $this->getPrice())));
  668.         $parentPrice $this->getPrice();
  669.         if (!empty(trim("" $parentPrice))) {
  670.             $precios[] = $parentPrice;
  671.         }
  672.         foreach ($variants as $variant) {
  673.             //$variantPrice = floatval(str_replace(",", ".", str_replace(".", "", $variant->getPrice())));
  674.             $variantPrice $variant->getPrice();
  675.             if (!empty(trim("" $variantPrice))) {
  676.                 $precios[] = $variantPrice;
  677.             }
  678.         }
  679.         $precios array_unique($precios);
  680.         sort($preciosSORT_NUMERIC);
  681.         return $precios;
  682.     }
  683.     public function getVariantPriceListV2($useLimitedVariants false)
  684.     {
  685.         if ($useLimitedVariants){
  686.             $variants $this->getLimitedChildren(35, [AbstractObject::OBJECT_TYPE_VARIANT]);
  687.         }else{
  688.             $variants $this->getAllActiveVariants();
  689.         }
  690.         $precios = array();
  691.         // $parentPrice = floatval(str_replace(",", ".", str_replace(".", "", $this->getPrice())));
  692.         $parentPrice $this->getPrice();
  693.         if (!empty(trim("" $parentPrice))) {
  694.             $precios[] = $parentPrice;
  695.         }
  696.         foreach ($variants as $variant) {
  697.             //$variantPrice = floatval(str_replace(",", ".", str_replace(".", "", $variant->getPrice())));
  698.             $variantPrice $variant->getPrice();
  699.             if (!empty(trim("" $variantPrice))) {
  700.                 $precios[] = $variantPrice;
  701.             }
  702.         }
  703.         $precios array_unique($precios);
  704.         sort($preciosSORT_NUMERIC);
  705.         return $precios;
  706.     }
  707.     public function getVariantPriceAndIdList($useLimitedVariants false)
  708.     {
  709.         if ($useLimitedVariants) {
  710.             $variants $this->getLimitedChildren(35, [AbstractObject::OBJECT_TYPE_VARIANT]);
  711.         } else {
  712.             $variants $this->getAllActiveVariants();
  713.         }
  714.         $precios = [];
  715.         // $parentPrice = floatval(str_replace(",", ".", str_replace(".", "", $this->getPrice())));
  716.         $parentPrice $this->getPrice();
  717.         if (!empty(trim("" $parentPrice))) {
  718.             $precios[$this->getId()] = $parentPrice;
  719.         }
  720.         foreach ($variants as $variant) {
  721.             //$variantPrice = floatval(str_replace(",", ".", str_replace(".", "", $variant->getPrice())));
  722.             $variantPrice $variant->getPrice();
  723.             if (!empty(trim("" $variantPrice))) {
  724.                 $precios[$variant->getId()] = $variantPrice;
  725.             }
  726.         }
  727.         $precios array_unique($precios);
  728.         return $precios;
  729.     }
  730.     public function getPriceNumeric()
  731.     {
  732.         return $this->floatvalue($this->getPrice());
  733.     }
  734.     /*
  735.       public function getPrice()
  736.       {
  737.       if (parent::getPrice() && "0" !== parent::getPrice()) {
  738.       return number_format($this->floatvalue(parent::getPrice()), 2, ",", "") ;
  739.       } else {
  740.       return parent::getPrice();
  741.       }
  742.       }
  743.      */
  744.     public function getAllActiveVariants($orderKeys = array())
  745.     {
  746.         $productList $this->getChildren([AbstractObject::OBJECT_TYPE_VARIANT]);
  747.         $variantsList = array(); // $this->getAllActiveVariantsOrderByPublication($productList);
  748.         if (count($variantsList) == 0) {
  749.             $variantsList $this->getAllActiveVariantsOrderByKeys($productList$orderKeys);
  750.         }
  751.         ksort($variantsList);
  752.         return $variantsList;
  753.     }
  754.     private function getAllActiveVariantsOrderByPublication($productList)
  755.     {
  756.         $variantsList = array();
  757.         if (class_exists('\IndabaPublicationBundle\Controller\TreeController')) {
  758.             $variantInfo $this->getVariantsInfosFromPublication();
  759.             if (count($variantInfo)) {
  760.                 foreach ($productList as $product) {
  761.                     if (!in_array($product->getProductstatus(), array('new''decatelogized''for_delete'))) {
  762.                         $key str_pad("0"6"0"STR_PAD_LEFT);
  763.                         $variantsList[$key] = $product;
  764.                     }
  765.                 }
  766.             }
  767.         }
  768.         return $variantsList;
  769.     }
  770.     private function getVariantsInfosFromPublication()
  771.     {
  772.         $variantInfo = array();
  773.         $db \Pimcore\Db::get();
  774.         $query "SELECT `id`,`structure_path`,`name`  FROM `schrader_catalogue_structure` WHERE `object_id` = " $this->getId();
  775.         $result $db->query($query);
  776.         $structurePath "";
  777.         if ($row $result->fetch()) {
  778.             $structurePath $row["structure_path"] . $row["name"] . "/";
  779.         }
  780.         if (!empty($structurePath)) {
  781.             $query "SELECT `id`,`object_id`,`orden`  FROM `schrader_catalogue_structure` WHERE `structure_path` = '" $structurePath "%' Order By `orden`;";
  782.             $result $db->query($query);
  783.             while ($row $result->fetch()) {
  784.                 $variantInfo[$row["orden"]] = $row["object_id"];
  785.             }
  786.         }
  787.         return $variantInfo;
  788.     }
  789.     private function getAllActiveVariantsOrderByKeys($productList$orderKeys = array())
  790.     {
  791.         $variantsList = array();
  792.         $attributes $this->getAllAttributes($this);
  793.         foreach ($productList as $product) {
  794.             if (!in_array($product->getProductstatus(), array('new''decatelogized''for_delete'))) {
  795.                 $keyArray = array();
  796.                 foreach ($orderKeys as $orderKey) {
  797.                     \Pimcore\Log\Simple::log("DefaultProduct"$orderKey);
  798.                     if (key_exists($orderKey$attributes)) {
  799.                         switch ($attributes[$orderKey]["fieldtype"]) {
  800.                             case "inputQuantityValue" :
  801.                             case "quantityValue" :
  802.                                 $value $product->getAttributeValue($attributes[$orderKey]);
  803.                                 $quantity = ($value && method_exists($value"getValue")) ? $value->getValue() : "";
  804.                                 $unit = ($value && method_exists($value"getUnit") && $value->getUnit()) ? $value->getUnit()->getAbbreviation() : "";
  805.                                 if (!empty($quantity)) {
  806.                                     switch (true) {
  807.                                         case(in_array($unit, array("ml""l""pt""gal"))) :
  808.                                             $sortvalue floor($this->convertToML($quantity$unit));
  809.                                             break;
  810.                                         case(in_array($unit, array("kg""g"))) :
  811.                                             $sortvalue floor($this->convertToMG($quantity$unit));
  812.                                             break;
  813.                                         case(in_array($unit, array("mm""cm""m"))) :
  814.                                             $sortvalue floor($this->convertToMM($quantity$unit));
  815.                                             break;
  816.                                         default :
  817.                                             $sortvalue $quantity;
  818.                                     }
  819.                                     $keyArray[] = str_pad($sortvalue6"0"STR_PAD_LEFT);
  820.                                 }
  821.                                 break;
  822.                             default:
  823.                                 $sortvalue $product->getAttributeValue($attributes[$orderKey]);
  824.                                 if ($orderKey == 'tallainternational') {
  825.                                     $key array_search($sortvalue$this->internationalSizeOrden);
  826.                                     $sortvalue str_pad($key6"0"STR_PAD_LEFT);
  827.                                 }
  828.                                 $keyArray[] = $sortvalue;
  829.                         }
  830.                     }
  831.                 }
  832.                 $keyArray[] = (!empty($product->getBsncode())) ? $product->getBsncode() : $product->getManufacturercode();
  833.                 $key implode("_"$keyArray);
  834.                 $variantsList[$key] = $product;
  835.             }
  836.         }
  837.         return $variantsList;
  838.     }
  839.     public function getAttributeValue($fieldinfo)
  840.     {
  841.         // $value = "";
  842.         $fieldObj $this;
  843.         for ($i 0$i count($fieldinfo["getters"]) - 1$i++) {
  844.             $getter $fieldinfo["getters"][$i];
  845.             $fieldObj $fieldObj->$getter();
  846.         }
  847.         $getter $fieldinfo["getters"][count($fieldinfo["getters"]) - 1];
  848.         $value $fieldObj->$getter();
  849.         return $value;
  850.     }
  851.     public function getAllAttributes($obj)
  852.     {
  853.         $fieldArray = array();
  854.         $this->getDataDefinition($obj$fieldArray);
  855.         $allFields = array();
  856.         foreach ($fieldArray as $key => $field) {
  857.             if ($key == "attributes") {
  858.                 $getterPrdAttribute "get" ucfirst($field["name"]);
  859.                 foreach ($field["objectbricks"] as $objbr) {
  860.                     $getterObjectBrick $objbr["objectbrick"];
  861.                     foreach ($objbr["fields"] as $fieldOB) {
  862.                         $getterField "get" ucfirst($fieldOB->name);
  863.                         $valueObject $obj->$getterPrdAttribute()->$getterObjectBrick()->$getterField();
  864.                         $allFields[$fieldOB->name] = array("fieldtype" => $fieldOB->fieldtype"name" => $fieldOB->name"title" => $fieldOB->title"getters" => array($getterPrdAttribute$getterObjectBrick$getterField));
  865.                     }
  866.                 }
  867.             }
  868.         }
  869.         $generalFields self::GENERAL_ATTRIBUTES;
  870.         foreach ($generalFields as $name) {
  871.             if (!isset($fieldArray[$name])) {
  872.                 continue;
  873.             }
  874.             $getter 'get' ucfirst($name);
  875.             if (!method_exists($obj$getter)) {
  876.                 continue;
  877.             }
  878.             $value $obj->$getter();
  879.             $hasValue = !(
  880.                 $value === null ||
  881.                 $value === '' ||
  882.                 (is_array($value) && count($value) === 0)
  883.             );
  884.             if (!$hasValue) {
  885.                 continue;
  886.             }
  887.             $def $fieldArray[$name];
  888.             $fieldtype method_exists($def'getFieldtype') ? $def->getFieldtype() : ($def->fieldtype ?? null);
  889.             $title     method_exists($def'getTitle') ? $def->getTitle() : ucfirst($name);
  890.             $allFields[$name] = [
  891.                 "fieldtype" => $fieldtype,
  892.                 "name"      => $name,
  893.                 "title"     => $title,
  894.                 "getters"   => [$getter],
  895.             ];
  896.         }
  897.         return $allFields;
  898.     }
  899.     public function getVariantsAttributes()
  900.     {
  901.         $excludeArray $this->getExcludeVariantsFields();
  902.         $attributes $this->getAllAttributes($this);
  903.         $variants $this->getAllActiveVariants();
  904.         $variantsFieldArray = array();
  905.         foreach ($attributes as $key => $value) {
  906.             if (!in_array($key$excludeArray)) {
  907.                 $parentValue $this->getAttributeValue($value);
  908.                 foreach ($variants as $variant) {
  909.                     $variantValue $variant->getAttributeValue($value); {
  910.                         if ($parentValue instanceof \Pimcore\Model\DataObject\Data\InputQuantityValue && $variantValue instanceof \Pimcore\Model\DataObject\Data\InputQuantityValue) {
  911.                             if ($parentValue->getValue() !== $variantValue->getValue() || $parentValue->getUnitId() !== $variantValue->getUnitId()) {
  912.                                 $variantsFieldArray[$key] = $value;
  913.                             }
  914.                         }else{
  915.                             if ($parentValue !== $variantValue ) {
  916.                                 $variantsFieldArray[$key] = $value;
  917.                             }
  918.                         }
  919.                     }
  920.                 }
  921.             }
  922.         }
  923.         return $variantsFieldArray;
  924.     }
  925.     public function getDataDefinition($obj, &$fieldArray$excludeArray = array())
  926.     {
  927.         if (method_exists($obj"getClass")) {
  928.             $classFielddefinition $obj->getClass()->getFieldDefinitions();
  929.         } else {
  930.             $classFielddefinition $obj->getDefinition()->getFieldDefinitions();
  931.         }
  932.         foreach ($classFielddefinition as $key => $fieldDefinition) {
  933.             if (in_array($key$excludeArray)) {
  934.                 continue;
  935.             }
  936.             switch ($fieldDefinition->fieldtype) {
  937.                 case "panel" :
  938.                     $this->getChildDataDefinition($fieldDefinition$fieldArray);
  939.                     break;
  940.                 case "localizedfields" :
  941.                     $this->getFieldDefinitionCache($fieldDefinition$fieldArray);
  942.                     break;
  943.                 case "objectbricks" :
  944.                     if ($obj && $obj->getAttributes()) {
  945.                         $objectBricks $obj->getAttributes()->getBrickGetters();
  946.                         // $objectBricks = $obj->getAttributes()->items ;
  947.                         foreach ($objectBricks as $objBr) {
  948.                             if ($obj->getAttributes()->$objBr()) {
  949.                                 $fieldArrayObjBrick = array();
  950.                                 $this->getDataDefinition($obj->getAttributes()->$objBr(), $fieldArrayObjBrick);
  951.                                 $fieldArray[$key]["name"] = $fieldDefinition->name;
  952.                                 $fieldArray[$key]["type"] = $fieldDefinition->fieldtype;
  953.                                 $fieldArray[$key]["objectbricks"][] = array("objectbrick" => $objBr"fields" => $fieldArrayObjBrick);
  954.                             }
  955.                         }
  956.                     }
  957.                     break;
  958.                 default:
  959.                     if ($fieldDefinition->datatype == "data") {
  960.                         $fieldArray [$key] = $fieldDefinition;
  961.                     }
  962.             }
  963.         }
  964.     }
  965.     private function getChildDataDefinition($fieldDefinition, &$fieldArray)
  966.     {
  967.         $childArray $fieldDefinition->childs;
  968.         foreach ($childArray as $ch) {
  969.             if ($ch->datatype == "layout") {
  970.                 $this->getChildDataDefinition($ch$fieldArray);
  971.             } else {
  972.                 $fieldArray[$ch->name] = $ch;
  973.             }
  974.         }
  975.     }
  976.     private function getFieldDefinitionCache($fieldDefinition, &$fieldArray)
  977.     {
  978.         $childArray $fieldDefinition->fieldDefinitionsCache;
  979.         if ($childArray == null) {
  980.             $childArray $fieldDefinition->childs;
  981.         }
  982.         foreach ($childArray as $ch) {
  983.             $fieldArray[$ch->name] = $ch;
  984.         }
  985.     }
  986.     private function getExcludeVariantsFields()
  987.     {
  988.         $excludeArray = array();
  989.         $excludeArray[] = "indaba";
  990.         $excludeArray[] = "view_in_web";
  991.         $excludeArray[] = "preview";
  992.         $excludeArray[] = "stock";
  993.         $excludeArray[] = "bsncode";
  994.         $excludeArray[] = "productstatus";
  995.         $excludeArray[] = "titleerp";
  996.         $excludeArray[] = "barcode";
  997.         $excludeArray[] = "ubicacion";
  998.         $excludeArray[] = "name";
  999.         $excludeArray[] = "shortdescription";
  1000.         $excludeArray[] = "longdescription";
  1001.         $excludeArray[] = "images";
  1002.         $excludeArray[] = "categories";
  1003.         $excludeArray[] = "documents";
  1004.         $excludeArray[] = "urlseofriendly";
  1005.         $excludeArray[] = "seodescription";
  1006.         return $excludeArray;
  1007.     }
  1008.     private function convertToML($quantity$unit)
  1009.     {
  1010.         $pintToMl 473.1764;
  1011.         $galToMl 3785.4118;
  1012.         if (!empty($quantity)) {
  1013.             $quantity trim("" $quantity);
  1014.             $quantityArray explode(" "$quantity);
  1015.             foreach ($quantityArray as $key => $quantity) {
  1016.                 $quantityArray[$key] = $this->fractionToDecimal($quantity);
  1017.             }
  1018.             if ($unit != "ml") {
  1019.                 switch ($unit) {
  1020.                     case "l" :
  1021.                         $quantity str_replace(","".""" $quantityArray[0]);
  1022.                         $quantity floatval($quantity) * 1000;
  1023.                         break;
  1024.                     case "pt" :
  1025.                         $quantity 0;
  1026.                         foreach ($quantityArray as $q) {
  1027.                             $quantity $quantity + ($pintToMl $q);
  1028.                         }
  1029.                         break;
  1030.                     case "gal" :
  1031.                         $quantity 0;
  1032.                         foreach ($quantityArray as $q) {
  1033.                             $quantity $quantity + ($galToMl $q);
  1034.                         }
  1035.                         break;
  1036.                 }
  1037.             }
  1038.         }
  1039.         return $quantity;
  1040.     }
  1041.     private function convertToMG($quantity$unit)
  1042.     {
  1043.         if (!empty($quantity)) {
  1044.             $quantity trim("" $quantity);
  1045.             $quantityArray explode(" "$quantity);
  1046.             foreach ($quantityArray as $key => $quantity) {
  1047.                 $quantityArray[$key] = $this->fractionToDecimal($quantity);
  1048.             }
  1049.             if ($unit != "g") {
  1050.                 switch ($unit) {
  1051.                     case "kg" :
  1052.                         $quantity str_replace(","".""" $quantityArray[0]);
  1053.                         $quantity floatval($quantity) * 1000;
  1054.                         break;
  1055.                 }
  1056.             }
  1057.         }
  1058.         return $quantity;
  1059.     }
  1060.     private function convertToMM($quantity$unit)
  1061.     {
  1062.         if (!empty($quantity)) {
  1063.             $quantity trim("" $quantity);
  1064.             $quantityArray explode(" "$quantity);
  1065.             foreach ($quantityArray as $key => $quantity) {
  1066.                 $quantityArray[$key] = $this->fractionToDecimal($quantity);
  1067.             }
  1068.             if ($unit != "mm") {
  1069.                 switch ($unit) {
  1070.                     case "m" :
  1071.                         $quantity str_replace(","".""" $quantityArray[0]);
  1072.                         $quantity floatval($quantity) * 1000;
  1073.                         break;
  1074.                     case "cm" :
  1075.                         $quantity str_replace(","".""" $quantityArray[0]);
  1076.                         $quantity floatval($quantity) * 10;
  1077.                         break;
  1078.                 }
  1079.             }
  1080.         }
  1081.         return $quantity;
  1082.     }
  1083.     private function fractionToDecimal($fraction)
  1084.     {
  1085.         $multipl 1;
  1086.         $numArray explode("/"$fraction);
  1087.         $numXArray explode("x"$numArray[0]);
  1088.         if (count($numXArray) == 2) {
  1089.             $numArray[0] = $numXArray[1];
  1090.             $multipl $numXArray[0];
  1091.         }
  1092.         if (count($numArray) == 2) {
  1093.             return (intval($numArray[0]) / intval($numArray[1])) * intval($multipl);
  1094.         } else {
  1095.             return $numArray[0];
  1096.         }
  1097.     }
  1098.     /*
  1099.      *
  1100.      * Own functions bsnbarcelona end
  1101.      */
  1102.     protected $prices = [];
  1103.     /**
  1104.      * Returns an array on min and max price for a product based on all it's children
  1105.      *
  1106.      * @param string $priceType (new|old)
  1107.      *
  1108.      * @return array|int|null
  1109.      */
  1110.     public function getPriceRange($priceType 'new')
  1111.     {
  1112.         if (!array_key_exists($priceType$this->prices)) {
  1113.             $method $priceType == 'new' 'getPrice' 'getPriceOld';
  1114.             if ($this->isVariant()) {
  1115.                 return $this->$method();
  1116.             } else {
  1117.                 $prices = [];
  1118.                 $colorSizeVariants $this->internalGetSizeVariants();
  1119.                 foreach ($colorSizeVariants as $sizeVariants) {
  1120.                     foreach ($sizeVariants as $sizeVariant) {
  1121.                         $prices[] = $sizeVariant->$method();
  1122.                     }
  1123.                 }
  1124.                 if ($prices) {
  1125.                     $min min($prices);
  1126.                     $max max($prices);
  1127.                     if ($min == $max) {
  1128.                         $this->prices[$priceType] = $min;
  1129.                     } else {
  1130.                         $this->prices[$priceType] = ['min' => $min'max' => $max];
  1131.                     }
  1132.                 } else {
  1133.                     $this->prices[$priceType] = null;
  1134.                 }
  1135.             }
  1136.         }
  1137.         return $this->prices[$priceType];
  1138.     }
  1139.     /**
  1140.      * @return \Pimcore\Model\Asset\Image|null
  1141.      */
  1142.     public function getFirstImageAsset()
  1143.     {
  1144.         if (method_exists($this"getImages")) {
  1145.             $imageList $this->getImages();
  1146.             $isOnlyOneImage = (count($imageList) == 1);
  1147.             if (count($imageList) > 1) {
  1148.                 foreach ($imageList as $imageObject) {
  1149.                     if (($imageObject->getWww()) && (($isOnlyOneImage) || ($imageObject->getOrder() < 2))) {
  1150.                         return $imageObject->getElement();
  1151.                     }
  1152.                 }
  1153.             } else {
  1154.                 if ($isOnlyOneImage) {
  1155.                     return $imageList[0]->getElement();
  1156.                 }
  1157.             }
  1158.         }
  1159.         return null;
  1160.     }
  1161.     /**
  1162.      * returns product variant that should be used for detail link
  1163.      *
  1164.      * @return \App\Model\DefaultProduct
  1165.      */
  1166.     public function getLinkProduct()
  1167.     {
  1168.         $firstSizeVariants $this->getColorVariants(true);
  1169.         return $this//Link of the same product, not to its variants
  1170. //        if (count($firstSizeVariants) == 0) {
  1171. //            // no variants
  1172. //            return $this;
  1173. //        } else {
  1174. //            return $firstSizeVariants[0];
  1175. //        }
  1176.     }
  1177.     /**
  1178.      * Returns concatenated category names for product
  1179.      *
  1180.      * @param bool $seo to suppress seo name, default is true and returns the seo name if available
  1181.      *
  1182.      * @return string
  1183.      */
  1184.     public function getCategoriesText($seo true)
  1185.     {
  1186.         $categories $this->getCategories();
  1187.         $categoriesArray = [];
  1188.         foreach ($categories as $item) {
  1189.             $categoriesArray[] = ($item->getUrlseofriendly() && $seo) ? $item->getUrlseofriendly() : $item->getTitle();
  1190.         }
  1191.         return implode(','$categoriesArray);
  1192.     }
  1193.     public function getMainMaterialText()
  1194.     {
  1195.         $mainMaterials $this->getMaterialComposition() ? $this->getMaterialComposition() : [];
  1196.         $mainMaterialsArray = [];
  1197.         foreach ($mainMaterials as $item) {
  1198.             if ($item->getPercent()) {
  1199.                 $mainMaterialsArray[] = $item->getPercent() . '% ' $item->getObject()->getName();
  1200.             } else {
  1201.                 $mainMaterialsArray[] = $item->getObject()->getName();
  1202.             }
  1203.         }
  1204.         return implode(','$mainMaterialsArray);
  1205.     }
  1206.     public function getSecondaryMaterialText()
  1207.     {
  1208.         $secondaryMaterials $this->getSecondaryMaterialComposition() ? $this->getSecondaryMaterialComposition() : [];
  1209.         $secondaryMaterialsArray = [];
  1210.         foreach ($secondaryMaterials as $item) {
  1211.             if ($item->getPercent()) {
  1212.                 $secondaryMaterialsArray[] = $item->getPercent() . '% ' $item->getObject()->getName();
  1213.             } else {
  1214.                 $secondaryMaterialsArray[] = $item->getObject()->getName();
  1215.             }
  1216.         }
  1217.         return implode(','$secondaryMaterialsArray);
  1218.     }
  1219.     public function getCanonicalId()
  1220.     {
  1221.         if ($this->isVariant()) {
  1222.             return $this->getParent()->getCanonicalId();
  1223.         } else {
  1224.             return $this->getId();
  1225.         }
  1226.     }
  1227.     /**
  1228.      * Returns the first size variant for all color variants (or just the color variants) of a product regardless if it's the main product or already a color variant
  1229.      *
  1230.      * @param $withSize switch the color with ot without the first size variant
  1231.      *
  1232.      * @return \App\Model\DefaultProduct[]
  1233.      */
  1234.     public function getColorVariants($withSize true)
  1235.     {
  1236.         if ($withSize) {
  1237.             $firstSizeVariants = [];
  1238.             foreach ($this->internalGetFirstSizeVariants() as $id => $sizeVariant) {
  1239.                 if ($sizeVariant) {
  1240.                     $firstSizeVariants[] = $sizeVariant;
  1241.                 } else {
  1242.                     $firstSizeVariants[] = AbstractObject::getById($id);
  1243.                 }
  1244.             }
  1245.             return $firstSizeVariants;
  1246.         } else {
  1247.             return $this->internalGetColorVariants();
  1248.         }
  1249.     }
  1250.     public $baseProduct null;
  1251.     public $baseColorVariant null;
  1252.     private $colorVariants null;
  1253.     public $firstSizeVariants null;
  1254.     private $sizeVariants null;
  1255.     protected function fillBaseProducts()
  1256.     {
  1257.         if (!$this->isVariant()) {
  1258.             $this->baseProduct $this;
  1259.             $this->baseColorVariant null;
  1260.         } elseif ($this->getType() == AbstractObject::OBJECT_TYPE_OBJECT) {
  1261.             $this->baseProduct $this->getParent();
  1262.             $this->baseColorVariant $this;
  1263.         } elseif ($this->getType() == AbstractObject::OBJECT_TYPE_VARIANT && $this->getParent()->getType() == AbstractObject::OBJECT_TYPE_OBJECT) {
  1264.             $this->baseColorVariant $this->getParent();
  1265.             $this->baseProduct $this->getParent()->getParent();
  1266.         } else {
  1267.             throw new \Exception('Invalid Product Tree with object ' $this->getId());
  1268.         }
  1269.     }
  1270.     protected function fillVariants()
  1271.     {
  1272.         $this->fillBaseProducts();
  1273.         $this->colorVariants $this->internalGetColorVariants();
  1274.         $this->firstSizeVariants = [];
  1275.         if (!empty($this->colorVariants)) {
  1276.             foreach ($this->colorVariants as $colorVariant) {
  1277.                 $children $colorVariant->getChildren(([AbstractObject::OBJECT_TYPE_VARIANT]));
  1278.                 $this->firstSizeVariants[$colorVariant->getId()] = reset($children);
  1279.             }
  1280.         }
  1281.     }
  1282.     public function internalGetBaseProduct()
  1283.     {
  1284.         if (empty($this->baseProduct)) {
  1285.             $this->fillVariants();
  1286.         }
  1287.         return $this->baseProduct;
  1288.     }
  1289.     protected function internalGetColorVariants()
  1290.     {
  1291.         if ($this->colorVariants === null) {
  1292.             $this->colorVariants $this->internalGetBaseProduct()->getChildren([AbstractObject::OBJECT_TYPE_OBJECT]);
  1293.         }
  1294.         return $this->colorVariants;
  1295.     }
  1296.     protected function internalGetSizeVariants()
  1297.     {
  1298.         if ($this->sizeVariants === null) {
  1299.             $this->sizeVariants = [];
  1300.             if (!empty($this->colorVariants)) {
  1301.                 foreach ($this->colorVariants as $colorVariant) {
  1302.                     $this->sizeVariants[$colorVariant->getId()] = $colorVariant->getChildren(([AbstractObject::OBJECT_TYPE_VARIANT]));
  1303.                 }
  1304.             }
  1305.         }
  1306.         return $this->sizeVariants;
  1307.     }
  1308.     protected function internalGetFirstSizeVariants()
  1309.     {
  1310.         if ($this->firstSizeVariants === null) {
  1311.             $this->fillVariants();
  1312.         }
  1313.         return $this->firstSizeVariants;
  1314.     }
  1315.     public function getBaseColorVariant()
  1316.     {
  1317.         if (empty($this->baseColorVariant)) {
  1318.             $this->fillVariants();
  1319.         }
  1320.         return $this->baseColorVariant;
  1321.     }
  1322.     /**
  1323.      * Returns size variants for a product regardless if it's the main product, a color child or a size variant
  1324.      *
  1325.      * @return \App\Model\DefaultProduct[]|null
  1326.      */
  1327.     public function getSizeVariants()
  1328.     {
  1329.         if (empty($this->baseProduct)) {
  1330.             $this->fillBaseProducts();
  1331.         }
  1332.         if ($this->baseColorVariant) {
  1333.             $list = new Product\Listing();
  1334.             $list->setCondition('o_parentId = ?'$this->baseColorVariant->getId());
  1335.             $list->setObjectTypes([AbstractObject::OBJECT_TYPE_VARIANT]);
  1336.             $list->setOrderKey('size');
  1337.             $list->setOrder('ASC');
  1338.             return SizeSort::sort($list->load());
  1339.         } else {
  1340.             return [];
  1341.         }
  1342.     }
  1343.     protected $isVariant null;
  1344.     /**
  1345.      * Checks if a a product is a variant or the main product
  1346.      *
  1347.      * @return bool
  1348.      */
  1349.     public function isVariant()
  1350.     {
  1351.         if ($this->isVariant === null) {
  1352.             if ($this->getType() == 'object' && $this->getParent() instanceof Folder) {
  1353.                 $this->isVariant false;
  1354.             } else {
  1355.                 $this->isVariant true;
  1356.             }
  1357.         }
  1358.         return $this->isVariant;
  1359.     }
  1360.     public function hasVariantKits(): bool
  1361.     {
  1362.         $variants $this->getAllActiveVariants();
  1363.         $kits false;
  1364.         if ($variants) {
  1365.             foreach ($variants as $variant) {
  1366.                 if ($variant->getKitProducts()){
  1367.                     $kits true;
  1368.                     break;
  1369.                 }
  1370.             }
  1371.         } else {
  1372.             if($this->getKitProducts()){
  1373.                 $kits true;
  1374.             }
  1375.         }
  1376.         return $kits;
  1377.     }
  1378.     public function isPartOfKit(): bool
  1379.     {
  1380.         $variants $this->getAllActiveVariants();
  1381.         $partOfKit false;
  1382.         if ($variants) {
  1383.             foreach ($variants as $variant) {
  1384.                 if ($variant->getParentKits()){
  1385.                     $partOfKit true;
  1386.                     break;
  1387.                 }
  1388.             }
  1389.         } else {
  1390.             if($this->getParentKits()){
  1391.                 $partOfKit true;
  1392.             }
  1393.         }
  1394.         return $partOfKit;
  1395.     }
  1396.     public function hasTechnologyAttributes()
  1397.     {
  1398.         return $this->getMainMaterialText() || $this->getSecondaryMaterialText() || $this->getFeatures();
  1399.     }
  1400.     public function getFirstCategory()
  1401.     {
  1402.         //\Pimcore\Model\DataObject\AbstractObject::setGetInheritedValues(true);
  1403.         if ($categories $this->getCategories()) {
  1404.             foreach ($categories as $cat) {
  1405.                 return $cat;
  1406.             }
  1407.         }
  1408.     }
  1409.     public function getPriceTax($tax)
  1410.     {
  1411.         $price $this->floatvalue($this->getPrice());
  1412.         return $price $this->floatvalue($tax);
  1413.     }
  1414.     /**
  1415.      * enables inheritance for field collections, if xxxInheritance field is available and set to string 'true'
  1416.      *
  1417.      * @param string $key
  1418.      *
  1419.      * @return mixed|\Pimcore\Model\DataObject\Fieldcollection
  1420.      */
  1421.     public function preGetValue($key)
  1422.     {
  1423.         if ($this->getClass()->getAllowInherit() && AbstractObject::doGetInheritedValues() && $this->getClass()->getFieldDefinition($key) instanceof \Pimcore\Model\DataObject\ClassDefinition\Data\Fieldcollections
  1424.         ) {
  1425.             $checkInheritanceKey $key 'Inheritance';
  1426.             if ($this->{
  1427.                 'get' $checkInheritanceKey
  1428.                 }() == 'true'
  1429.             ) {
  1430.                 $parentValue $this->getValueFromParent($key);
  1431.                 $data $this->$key;
  1432.                 if (!$data) {
  1433.                     $data $this->getClass()->getFieldDefinition($key)->preGetData($this);
  1434.                 }
  1435.                 if (!$data) {
  1436.                     return $parentValue;
  1437.                 } else {
  1438.                     $value = new \Pimcore\Model\DataObject\Fieldcollection($data->getItems());
  1439.                     if (!empty($parentValue)) {
  1440.                         foreach ($parentValue as $entry) {
  1441.                             $value->add($entry);
  1442.                         }
  1443.                     }
  1444.                     return $value;
  1445.                 }
  1446.             }
  1447.         }
  1448.         return parent::preGetValue($key);
  1449.     }
  1450.     function floatvalue($val)
  1451.     {
  1452.         $val str_replace(",""."$val);
  1453.         $val preg_replace('/\.(?=.*\.)/'''$val);
  1454.         return floatval($val);
  1455.     }
  1456.     public function getLimitedChildren($limit 10$objectTypes = [self::OBJECT_TYPE_VARIANT]) {
  1457.         $list = new Product\Listing();
  1458.         $list->setCondition('o_parentId = ?'$this->getId());
  1459.         $list->setOrderKey(sprintf('o_%s'$this->getChildrenSortBy()));
  1460.         $list->setOrder($this->getChildrenSortOrder());
  1461.         $list->setObjectTypes($objectTypes);
  1462.         $list->setLimit($limit);
  1463.         return $list->load();
  1464.     }
  1465. }