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