We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 43151
    • 15 Posts
    Всем привет. Есть интернет магазин на шопкипере.
    в карточке товара есть куча ТВ полей/характеристик товара. ТВ поля поделены на группы (для каждого вида товара)
    При добавлении, заполняются общие поля и в 1 из групп.
    Как можно сделать листинг ТВ полей в шаблоне? А то сейчас приходится делать не очень красиво, кучу условий

    [[!If? &subject=`[[*materiali]]` &operator=`notempty` &operand=``
       &then=`<tr><td><span class="name">Применяемые материалы</span><span class="value">[[*materiali]]</span></td></tr>`]]	
    
    [[!If? &subject=`[[*mechanizm_dveri]]` &operator=`notempty` &operand=``
       &then=`<tr><td><span class="name">Механизм подъема двери:</span><span class="value">[[*mechanizm_dveri]]</span></td></tr>`]]
      • 43151
      • 15 Posts
      Нашел вот такой код:
      $resid_int = $modx->getOption('resourceId', $scriptProperties, $modx->resource->get('id'));
      
      if (isset($resid_int )){
      $tvs = array(); 
      
          //tv
          $tv_query = $modx->newQuery('modTemplateVarResource');
          $tv_query->leftJoin('modTemplateVar','modTemplateVar',array("modTemplateVar.id = tmplvarid"));
          $tv_query->where(array('contentid'=>$resid_int));
          $tv_query->select($modx->getSelectColumns('modTemplateVarResource','modTemplateVarResource','',array('id','tmplvarid','contentid','value')));
          $tv_query->select($modx->getSelectColumns('modTemplateVar','modTemplateVar','',array('name')));
          $tvars = $modx->getCollection('modTemplateVarResource',$tv_query);
          foreach ($tvars as $tvar) {
              $tvar = $tvar->toArray();
              if (!empty($tvar['value']))
                  $tvs[$tvar['name']] = $tvar['value'];
      $output.=$tvar['name']." - ".$tvar['value'];
          }
       
      }
      return $output;


      Выводит ВСЕ ТВ поля, но как сделать фильтр по категории и получить заголовок ТВ поля?
        • 43151
        • 15 Posts
        вот что у меня получилось:
        <?php
        $resid_int = $modx->getOption('resourceId', $scriptProperties, $modx->resource->get('id'));
        
        $listElementTplName = $modx->getOption('listElementTpl', $scriptProperties, null);
        $listElementTpl = $modx->getParser()->getElement('modChunk', $listElementTplName);
        if ($listElementTpl) {
                $listElementTpl->setCacheable(false);
        } else {
                $modx->log(modX::LOG_LEVEL_ERROR, 'getComplexCharacteristics: could not find chunk - ' . $listElementTplName);
                return;
        }
        
        if (isset($resid_int )){
        $tvs = array(); // массив с тв параметрами
        
            //tv
            $tv_query = $modx->newQuery('modTemplateVarResource');
            $tv_query->leftJoin('modTemplateVar','modTemplateVar',array("modTemplateVar.id = tmplvarid"));
            $tv_query->where(array('contentid'=>$resid_int));
            $tv_query->select($modx->getSelectColumns('modTemplateVarResource','modTemplateVarResource','',array('id','tmplvarid','contentid','value')));
            $tv_query->select($modx->getSelectColumns('modTemplateVar','modTemplateVar','',array('name')));
            $tvars = $modx->getCollection('modTemplateVarResource',$tv_query);
        
            foreach ($tvars as $tvar) {
                $tvar = $tvar->toArray();
                if (!empty($tvar['value']))
        
                    $tvNameOrId = $tvar['name'];
                    if (is_numeric($tvNameOrId)) {
                       $tvObj = $modx->getObject('modTemplateVar',$tvNameOrId);
                    } else {
                       $tvObj = $modx->getObject('modTemplateVar',array('name' => $tvNameOrId));
                    }
                    $fields = $tvObj->toArray();
        
                    if ($fields['category']!="") {
        $tvData[category]=$fields['category'];
        $tvData[caption]=$fields['caption'];
        $tvData[name]=$fields['name'];
        $tvData[value]=$fields['value'];
        
        if ($fields['output_properties']['delimiter']!="")
        $tvar['value']=str_replace('||',$fields['output_properties']['delimiter'],$tvar['value']);
        
                    //$output .= $listElementTpl->process($tvData);
                    $output.='
        <tr><td><span class="name">'.$fields['caption'].'</span><span class="value">'.$tvar['value'].'</span></td></tr>
        '; 
        }               }
         
        }
        return $output;


        выводит все ТВ параметры, если ТВ относится к какой то группе и не пустой.