简体   繁体   English

用于分类视图的magento 1.9 list.phtml文件:即使存在子分类,也可以查看产品?

[英]magento 1.9 list.phtml file for category view: view products even if subcategories exist?

At the moment, if a category has products in it, it shows a list of products, which is great. 目前,如果类别中包含产品,那么它会显示产品列表,这很棒。 However, if a category has a set of products & subcategories in it, it only shows the subcategories rather than the products. 但是,如果类别中包含一组产品和子类别,则仅显示子类别,而不显示产品。

If a category has products and subcategories in it, I want magento to list the products to the user rather than the subcategories in the main viewing space, as it is already showing a list of subcategories on the sidebar. 如果类别中包含产品和子类别,我希望magento向用户列出产品,而不是在主查看空间中列出子类别,因为它已经在侧边栏中显示了子类别列表。

This is my current list.phtml: https://bpaste.net/show/66110a7264bc 这是我当前的列表.phtml: https ://bpaste.net/show/66110a7264bc

What would I have to do to the list.phtml to have it prioritize showing products? 我需要对list.phtml进行什么操作才能使其优先显示产品? Let's say I have a category that has 5 products and 5 subcategories. 假设我的类别包含5个产品和5个子类别。 The subcategories already show on the side, so I'd like it to show a list of the products in the category. 子类别已显示在侧面,因此我希望它显示该类别中的产品列表。

I am thinking for the first line, 我在想第一行,

<?php if (count($subCatIds) > 1) { ?>

Should be something related to if the products is < 1, show the list of subcategories. 如果产品<1,则应与之相关,并显示子类别列表。 So I made it say 所以我说了

    <?php if (count($productCollection) < 1) { ?>

My thought process was, if the number of products is 0, then show the subcategories, but it is not working out that way. 我的思考过程是,如果产品数量为0,则显示子类别,但这种方式无法解决。

What am I missing? 我想念什么?

I would solve the problem by this way (if you know exactly where to show only subcategories, products or both): 我将通过这种方式解决该问题(如果您确切地知道仅在哪里显示子类别,产品或两者都显示):

1.The category edit page in the Magento admin panel has the tab 'Display Settings' and the fields 'Display Mode' and 'CMS Block'. 1. Magento管理面板中的类别编辑页面具有“显示设置”选项卡以及“显示模式”和“ CMS阻止”字段。 If you choose the 'Products only' mode the only products will be displayed on the category page. 如果您选择“仅产品”模式,则仅产品将显示在类别页面上。 If you choose the 'Static block only'mode the only chosen in the 'CMS Block' field static block will be displayed on the category page. 如果选择“仅静态块”模式,则“ CMS块”字段静态块中的唯一选择将显示在类别页面上。 If you choose the 'Static block and products' Magento will show both: static block will be the first, products list - the second. 如果您选择“静态块和产品”,Magento将同时显示:静态块是第一个,产品列表是第二个。

You may find the logic in the catalog/category/view.phtml 您可以在catalog / category / view.phtml中找到逻辑

<?php if($this->isContentMode()): ?>
<?php echo $this->getCmsBlockHtml() ?>

<?php elseif($this->isMixedMode()): ?>
    <?php echo $this->getCmsBlockHtml() ?>
    <?php echo $this->getProductListHtml() ?>

<?php else: ?>
    <?php echo $this->getProductListHtml() ?>
<?php endif; ?>

2.You may create a CMS Block with the subcategories of current category, set it to the 'CMS Block' field and choose the option of the 'Display Mode' you need for the current category. 2.您可以使用当前类别的子类别创建一个CMS模块,将其设置为“ CMS模块”字段,然后选择当前类别所需的“显示模式”选项。

Or 要么

1.You may try to add the condition to the logic in the catalog/category/view.phtml - if the current category has products: 1.如果当前类别中包含产品,则可以尝试将条件添加到catalog / category / view.phtml中的逻辑中:

$products = Mage::getModel('catalog/product')
->getCollection()
->addCategoryFilter($category)

Or 要么

1.Add elseif to the condition to list.phtml: 1.将elseif添加到list.phtml的条件中:

<?php if ($_categoryCollection) : ?>
...
<?php elseif (!$_productCollection->count()): ?>
...
<?php else: ?>
...
<?php endif; ?>

2.The $_categoryCollection is: 2. $_categoryCollection是:

$currentCategory = Mage::registry('current_category');

$collection = Mage::getResourceModel('catalog/category_collection')
            ->setStore(Mage::app()->getStore())
            ->addAttributeToSelect('name')
            ->addAttributeToSort('name','ASC')
            ->addAttributeToSelect('url_key')
            ->addAttributeToSelect('image')
            ->addFieldToFilter('parent_id', $currentCategory->getEntityId())
            ->addFieldToFilter('is_active', 1)
            ->load();

If the solution doesn't fit, please, show the code of the list.phtml (your link returns 404), catalog/category/view.phtml, and the way you are displaying subcategories. 如果解决方案不合适,请显示list.phtml(您的链接返回404),catalog / category / view.phtml的代码以及显示子类别的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM