src/Product/BasicData/RenderBasicProductData.php line 56

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Klaravik\Product\BasicData;
  4. use Klaravik\Model\ProductValue;
  5. use Klaravik\Product\BasicData\BasicProductData;
  6. use Klaravik\Translate\Trans;
  7. use stdClass;
  8. class RenderBasicProductData
  9. {
  10.     private Trans $trans;
  11.     private stdClass $productObject;
  12.     /**
  13.      * @param Trans $trans
  14.      * @param stdClass $productObject
  15.      */
  16.     public function __construct(Trans $transstdClass $productObject)
  17.     {
  18.         $this->trans $trans;
  19.         $this->productObject $productObject;
  20.     }
  21.     /**
  22.      * @return array
  23.      */
  24.     private function highLightMakeModel(): array
  25.     {
  26.         if (empty($this->productObject->fabrikat)) {
  27.             $this->productObject->fabrikat $this->trans->get('text_label_page-product_highlight-unknown');
  28.         }
  29.         if (empty($this->productObject->model)) {
  30.             $this->productObject->model $this->trans->get('text_label_page-product_highlight-unknown');
  31.         }
  32.         $productValueMake  = (new ProductValue())->setValue($this->productObject->fabrikat);
  33.         $productValueModel = (new ProductValue())->setValue($this->productObject->model);
  34.         return [
  35.             $this->trans->get('text_label_page-product_highlight-model') => $productValueMake,
  36.             $this->trans->get('text_label_productEditor_base_model')     => $productValueModel
  37.         ];
  38.     }
  39.     /**
  40.      * @param int $products_id
  41.      * @param int $categories_id
  42.      * @return string
  43.      */
  44.     public function renderHtml(int $products_idint $categories_id): array
  45.     {
  46.         $getProductBasicData = (new BasicProductData($this->trans))->getProductBasicData($products_id$categories_id);
  47.         $getProductBasicData['highLight'] = array_merge($this->highLightMakeModel(), $getProductBasicData['highLight']);
  48.         $htmlOutput '';
  49.         if (!empty($getProductBasicData['highLight'])) {
  50.             $htmlOutput .=  '<div class="object-information__highlight">';
  51.             foreach ($getProductBasicData['highLight'] as $productFieldValue => $basicDataModel) {
  52.                 $htmlOutput .=  '
  53.                 <div class="object-information__highlight-item">
  54.                     <div class="object-information__highlight-key">'.$productFieldValue.':</div>
  55.                     <div class="object-information__highlight-value">'.$basicDataModel->getValue().'</div>
  56.                 </div>';
  57.             }
  58.             $htmlOutput .=  '</div>';
  59.         }
  60.         if (!empty($getProductBasicData['basicData'])) {
  61.             $htmlOutput .= '
  62.             <div class="object-information expander-script" data-expander="basicData">
  63.                 <div class="expander-script__container">';
  64.                 foreach ($getProductBasicData['basicData'] as $headLine => $headLineGroup) {
  65.                     if (empty($headLineGroup)) {
  66.                         continue;
  67.                     }
  68.                     $htmlOutput .= '
  69.                     <div class="object-information">
  70.                         <span class="object-information__title">'$headLine .':</span>
  71.                         <div class="object-information__items">';
  72.                         foreach ($headLineGroup as $basicDataName => $basicDataType) {
  73.                             foreach ($basicDataType as $basicDataModel) {
  74.                                 $htmlOutput .=
  75.                                 '<div class="object-information__item">
  76.                                     <span class="object-information__item-key">'.$basicDataName.'</span>
  77.                                     <span class="object-information__item-value">'.$basicDataModel->getValue().'</span>
  78.                                 </div>';
  79.                             }
  80.                         }
  81.                     $htmlOutput .='
  82.                         </div>
  83.                     </div>';
  84.                 }
  85.             $htmlOutput .= '
  86.                 </div>
  87.                 <div class="expander-script__toggle button--primary button--outlined button--large" data-expander="basicData">
  88.                     <span class="toggler-text">'$this->trans->get("text_label_page-product_extra-vehicle-dropdown") .'</span>
  89.                     <span class="arrow-icon"><i class="ri-arrow-down-s-line"></i></span>
  90.                 </div>
  91.             </div>';
  92.         }
  93.         return [
  94.             'htmlOutput'      => $htmlOutput,
  95.             'loadingHelp'     => $getProductBasicData['loadingHelp'],
  96.             'loadingHelpText' => $getProductBasicData['loadingHelpText']
  97.         ];
  98.     }
  99. }