2017-01-04 3 views
1

Magento версии: 1.9.2.4 У меня есть файл /app/design/frontend/MY_THEME_NAME/default/template/catalog/product/view.phtmlПоказать все атрибуты из продуктов в описании вкладки (Magento 1.9.2.4)

с кодом:

<?php if ($detailedInfoGroup = $this->getChildGroup('detailed_info', 'getChildHtml')):?> 
    <!-- fix full size backround start--> 
    </div> 
    </div> 
    </div> 
    <!-- fix full size backround start--> 
<div class="specific"> 
    <div class="container"> 
    <div class="row"> 
     <div class="col-sm-12"> 
      <div class="specific__tab"> 
       <div class="tabs"> 
        <ul class="tabs-ctrl"> 
         <?php 
          reset($detailedInfoGroup); 
          $first_key = key($detailedInfoGroup); 
         ?> 
         <?php foreach ($detailedInfoGroup as $alias => $html):?> 
         <li class="tabs-ctrl-item <?php if($alias == $first_key): ?>active<?php endif; ?>" data-class="<?php echo $alias?>"><?php echo $this->escapeHtml($this->getChildData($alias, 'title')) ?></li> 
         <?php endforeach;?> 
        </ul> 
        <ul class="tabs-list"> 
         <?php foreach ($detailedInfoGroup as $alias => $html):?> 
         <li class="tabs-list-item list-<?php echo $alias?> <?php if($alias == $first_key): ?>active<?php endif; ?>"> 
          <?php echo $html ?> 
         </li> 
         <?php endforeach;?> 


        </ul> 
       </div> 
      </div><!-- specific__tab--> 
     </div> 
    </div> 
    </div> 
</div><!-- specific--> 
    <!-- fix full size backround end--> 
    <div class="container"> 
    <div class="row"> 
    <div class="col-xs-12"> 
    <!-- fix full size backround end--> 
<?php endif; ?> 

Это шоу Описание и дополнительные вкладки.

В файле /app/design/frontend/MY_THEME_NAME/default/template/catalog/product/view/description.phtml

Я следующий код:

<?php $_description = $this->getProduct()->getDescription(); ?> 
<?php if ($_description): ?> 
    <h2><?php echo $this->__('Details') ?></h2> 
    <div class="std"> 
     <?php echo $this->helper('catalog/output')->productAttribute($this->getProduct(), $_description, 'description') ?> 
    </div> 
<?php endif; ?> 

И в файле/приложение/дизайн/интерфейс/MY_THEME_NAME/по умолчанию/шаблон/Каталог/продукта/вид/attributes.phtml

Я следующий код:

<?php 
    $_helper = $this->helper('catalog/output'); 
    $_product = $this->getProduct() 
?> 
<?php if($_additional = $this->getAdditionalData()): ?> 
    <h2><?php echo $this->__('Additional Information') ?></h2> 
    <table class="data-table" id="product-attribute-specs-table"> 
     <col width="25%" /> 
     <col /> 
     <tbody> 
     <?php foreach ($_additional as $_data): ?> 
      <tr> 
       <th class="label"><?php echo $this->escapeHtml($this->__($_data['label'])) ?></th> 
       <td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td> 
      </tr> 
     <?php endforeach; ?> 
     </tbody> 
    </table> 
    <script type="text/javascript">decorateTable('product-attribute-specs-table')</script> 
<?php endif;?> 

Если я просто скопирую и вставляю этот код в description.phtml - он не работает, $ _additional пуст или не существует.

Итак, как я могу показать все атрибуты на вкладке «Описание»? Я читал здесь много тем и до сих пор не нашел решения. Большое спасибо!

ответ

1

Найдено решение моей проблемы:

Создать файл /app/code/local/Mage/Catalog/Block/Product/View/Description.php

с followind кодом:

class Mage_Catalog_Block_Product_View_Description extends Mage_Core_Block_Template 
{ 
    protected $_product = null; 

    function getProduct() 
    { 
     if (!$this->_product) { 
      $this->_product = Mage::registry('product'); 
     } 
     return $this->_product; 
    } 

    /** 
    * $excludeAttr is optional array of attribute codes to 
    * exclude them from additional data array 
    * 
    * @param array $excludeAttr 
    * @return array 
    */ 
    public function getAdditionalData(array $excludeAttr = array()) 
    { 
     $data = array(); 
     $product = $this->getProduct(); 
     $attributes = $product->getAttributes(); 
     foreach ($attributes as $attribute) { 
      if ($attribute->getIsVisibleOnFront() && !in_array($attribute->getAttributeCode(), $excludeAttr)) { 
       $value = $attribute->getFrontend()->getValue($product); 

       if (!$product->hasData($attribute->getAttributeCode())) { 
        $value = Mage::helper('catalog')->__('N/A'); 
       } elseif ((string)$value == '') { 
        $value = Mage::helper('catalog')->__('No'); 
       } elseif ($attribute->getFrontendInput() == 'price' && is_string($value)) { 
        $value = Mage::app()->getStore()->convertPrice($value, true); 
       } 

       if (is_string($value) && strlen($value)) { 
        $data[$attribute->getAttributeCode()] = array(
         'label' => $attribute->getStoreLabel(), 
         'value' => $value, 
         'code' => $attribute->getAttributeCode() 
        ); 
       } 
      } 
     } 
     return $data; 
    } 

} 

И теперь я могу использовать $ _additional = $ this-> getAdditionalData(); на вкладке «Описание».

0

Это работает для меня в tabs.phtml Magento ver. 1.9.3.4

$_product = Mage::registry('current_product'); 
Смежные вопросы