Список категорий не работает на странице категории - Magento - PullRequest
2 голосов
/ 18 сентября 2010

Во-первых, я новичок в Magento, поэтому, пожалуйста, объясните подробно, если вы можете помочь.

Я использовал следующий код:

  <div class="left-nav-inner">  
    <h3 id="products">Products</h3>
    <h4>Shop by:</h4>
    <ul id="product-menu">

<?php
/* Get the categories that are active for the store */
$_main_categories=$this->getStoreCategories();

/* Get the current category the user is in */
$_current_category=$this->getCurrentCategory();

/* Get the current category path */
$_categorypath = $this->getCurrentCategoryPath();
?>
<?php
if ($_main_categories):
    /* This bit cycles through the categories - setting the next one to current */
    foreach ($_main_categories as $_main_category):
      if($_main_category->getIsActive()):                             
           $cur_category=Mage::getModel('catalog/category')->load($_main_category->getId());
           $layer = Mage::getSingleton('catalog/layer');
           $layer->setCurrentCategory($cur_category);     

/* Write the main categories */           
?>                
<li><a href="<?php echo $this->getCurrentCategory()->getUrl()?>"><?php echo $this->getCurrentCategory()->getName();?></a></li>   


<?php 

/* Check the category variable loop against the current category path if it is - print sub categories */
if (in_array($this->getCurrentCategory()->getId(), $_categorypath)): ?>
<?php $_maincategorylisting=$this->getCurrentCategory()?>                        
<?php $_categories=$this->getCurrentChildCategories()?>
<?php if($_categories->count()):?>


<?php /* This resets the category back to the original pages category
****     If this is not done, subsequent calls on the same page will use the last category
****    in the foreach loop
*/   ?>
<?php $layer->setCurrentCategory($_current_category);  ?> 
<?php endif; ?>   

<?php endif; ?>                                   

<?php         
endif;
endforeach; 
else:
?>
<p>$_main_categories array was empty.</p>
<p>This might be because you are referencing this phtml file with a wrong type attribute. You should use <block type="catalog/navigation" ... /> !</p>
<?php endif; ?>
</div>

Это отображает списки в моем левом меню какоднако, когда я нажимаю на URL-адрес категории, на странице категории не отображаются продукты.

Я могу получить продукты для отображения, если удалить левый столбец в:

app / design / frontend/default/default/layout/catalog.xml

Я сделал это с помощью следующего кода:


Макет по умолчанию для категории


<catalog_category_default translate="label">
    <label>Catalog Category (Non-Anchor)</label>
    <remove name="left" />

Как вывидно, что я добавил «удалить имя = слева».

Мне нужно левое меню с категориями, отображаемыми на каждой странице веб-сайта, и мне нужно, чтобы продукты отображались при нажатии на категории...

Пожалуйста, помогите.

Ответы [ 3 ]

0 голосов
/ 14 марта 2013

Похоже, вам не хватает тега </ul> после вашего endforeach.

Посмотрите на ваш источник HTML. Вы можете обнаружить, что все находится на странице, просто вложено в тег <ul>, поэтому оно не отображается браузером.

Если я прав, это должно показать вам (обратите внимание на тег </ul> в конце):

 <div class="left-nav-inner">  
    <h3 id="products">Products</h3>
    <h4>Shop by:</h4>
    <ul id="product-menu">

<?php
/* Get the categories that are active for the store */
$_main_categories=$this->getStoreCategories();

/* Get the current category the user is in */
$_current_category=$this->getCurrentCategory();

/* Get the current category path */
$_categorypath = $this->getCurrentCategoryPath();
?>
<?php
if ($_main_categories):
    /* This bit cycles through the categories - setting the next one to current */
    foreach ($_main_categories as $_main_category):
      if($_main_category->getIsActive()):                             
           $cur_category=Mage::getModel('catalog/category')->load($_main_category->getId());
           $layer = Mage::getSingleton('catalog/layer');
           $layer->setCurrentCategory($cur_category);     

/* Write the main categories */           
?>                
<li><a href="<?php echo $this->getCurrentCategory()->getUrl()?>"><?php echo $this->getCurrentCategory()->getName();?></a></li>   


<?php 

/* Check the category variable loop against the current category path if it is - print sub categories */
if (in_array($this->getCurrentCategory()->getId(), $_categorypath)): ?>
<?php $_maincategorylisting=$this->getCurrentCategory()?>                        
<?php $_categories=$this->getCurrentChildCategories()?>
<?php if($_categories->count()):?>


<?php /* This resets the category back to the original pages category
****     If this is not done, subsequent calls on the same page will use the last category
****    in the foreach loop
*/   ?>
<?php $layer->setCurrentCategory($_current_category);  ?> 
<?php endif; ?>   

<?php endif; ?>                                   

<?php         
endif;
endforeach; 
?>
</ul><!-- See what I did here? -->
<?php
else:
?>

<p>$_main_categories array was empty.</p>
<p>This might be because you are referencing this phtml file with a wrong type attribute. You should use <block type="catalog/navigation" ... /> !</p>
<?php endif; ?>
</div>
0 голосов
/ 21 октября 2015

Перейдите на Админ -> cms-> pages-> home- page-> design-> custom design -> Добавить этот код

<reference name="left">
    <block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left.phtml"/>
</reference>
0 голосов
/ 19 сентября 2010

Я бы порекомендовал вам использовать Layoutviewer от Alan Storm для отладки того, что происходит с вашим целевым URL.Вы можете скачать его с этой статьи , обратите внимание, что вам нужно создать собственную декларацию модуля xml для вставки в app/etc/modules для активации модуля.

...