Php Magento类别中的最低价格

Php Magento类别中的最低价格,php,magento,Php,Magento,因此,我创建了一个sub.phtml文件,该文件通过检索类别的子类别并在页面上显示相关标题、图像等,为我创建类别登录页 不过,我也希望列出这些类别中产品的最低价格(“例如从19.99起”) 这是我目前的代码: <?php $category = Mage::getSingleton('catalog/layer')->getCurrentCategory(); $categories = $category->getCollection() ->addAt

因此,我创建了一个sub.phtml文件,该文件通过检索类别的子类别并在页面上显示相关标题、图像等,为我创建类别登录页

不过,我也希望列出这些类别中产品的最低价格(“例如从19.99起”)

这是我目前的代码:

<?php
$category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
$categories = $category->getCollection()
        ->addAttributeToSelect(array('name', 'thumbnail'))
        ->addAttributeToFilter('is_active', 1)
        ->addIdFilter($category->getChildren())
        
?>

<?php
$lowest_product = Mage::getModel('catalog/product')->getCollection()
    ->setOrder('price', 'asc')
    ->setPageSize(1) // just select one product, which will be the cheapest
    ->setCurPage(1)
    ->joinField(
        'category_id', 'catalog/category_product', 'category_id', 
        'product_id = entity_id', null, 'left'
    ) // add a join so you can filter by category id
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('category_id', $category->getId())
    ->addAttributeToFilter('status', 1) // only select active products
    ->addAttributeToFilter(array(array('attribute'=>'visibility', 'eq'=>"4"))) // only products which are visible
    ->getFirstItem(); // only get the first item
?>
<div class="container">
    <?php foreach ($categories as $category): ?>
    <a class="catA" href="<?php echo $category->getUrl() ?>">
        <div class="catBox">
            <div class="catBoxImage"><img src="<?php echo Mage::getBaseUrl('media') . 'catalog' . DS . 'category' . DS . $category->getThumbnail() ?>" alt="<?php echo $this->htmlEscape($category->getName()) ?>"></div>
            <div class="catBoxText">
                <h2><?php echo $category->getName() ?></h2>
                <p class="catP">From: <span class="red"><?php echo Mage::helper('core')->currency(Mage::helper('tax')->getPrice($lowest_product, $lowest_product->getPrice()), true, false) ?></span></p>
            </div>
        </div>
    </a>
    <?php endforeach; ?>
</div>


提前感谢您的帮助。

要获得某一类别中价格最低的产品,您可以执行以下操作:

$lowest_product = Mage::getModel('catalog/product')->getCollection()
    ->setOrder('price', 'asc')
    ->setPageSize(1) // just select one product, which will be the cheapest
    ->setCurPage(1)
    ->joinField(
        'category_id', 'catalog/category_product', 'category_id', 
        'product_id = entity_id', null, 'left'
    ) // add a join so you can filter by category id
    ->addAttributeToSelect('*')
    ->addStoreFilter(Mage::app()->getStore()->getId())
    ->addAttributeToFilter('category_id', $category->getId())
    ->addAttributeToFilter('status', 1) // only select active products
    ->addAttributeToFilter(array(array('attribute'=>'visibility', 'eq'=>"4"))) // only products which are visible
    ->getFirstItem(); // only get the first item
现在您可以拨打:

<?php echo Mage::helper('core')->currency(Mage::helper('tax')->getPrice($lowest_product, $lowest_product->getPrice()), true, false) ?>

已更新

<?php
$category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
$categories = $category->getCollection()
        ->addAttributeToSelect(array('name', 'thumbnail'))
        ->addAttributeToFilter('is_active', 1)
        ->addIdFilter($category->getChildren())

?>


<div class="container">
<?php foreach ($categories as $category): ?>
<?php
    $lowest_product = Mage::getModel('catalog/product')->getCollection()
    ->setOrder('price', 'asc')
    ->setPageSize(1) // just select one product, which will be the cheapest
    ->setCurPage(1)
    ->joinField(
        'category_id', 'catalog/category_product', 'category_id', 
        'product_id = entity_id', null, 'left'
    ) // add a join so you can filter by category id
    ->addAttributeToSelect('*')
    ->addStoreFilter(Mage::app()->getStore()->getId())
    ->addAttributeToFilter('category_id', array('in' => $category->getId()))
    ->addAttributeToFilter('status', 1) // only select active products
    ->addAttributeToFilter(array(array('attribute'=>'visibility', 'eq'=>"4"))) // only products which are visible
    ->getFirstItem(); // only get the first item
?>

<a class="catA" href="<?php echo $category->getUrl() ?>">
    <div class="catBox">
        <div class="catBoxImage"><img src="<?php echo Mage::getBaseUrl('media') . 'catalog' . DS . 'category' . DS . $category->getThumbnail() ?>" alt="<?php echo $this->htmlEscape($category->getName()) ?>"></div>
        <div class="catBoxText">
            <h2><?php echo $category->getName() ?></h2>
            <p class="catP">From: <span class="red"><?php echo Mage::helper('core')->currency(Mage::helper('tax')->getPrice($lowest_product, $lowest_product->getPrice()), true, false) ?></span></p>
        </div>
    </div>
</a>
<?php endforeach; ?>


你是想得到一个类别中价格最低的产品,还是每种产品的最低价格?对不起,一个类别中价格最低的产品似乎无法让它发挥作用,我对PHP的使用非常差,但可能做了一些错误的事情。这是因为它是一个集合,所以目前需要foreach,我会用一个有效的修正来修正我的答案。我想它几乎就在那里了,唯一的问题是它在所有类别上显示:0.00!-非常感谢您的帮助,我在测试安装中试用过,效果很好,您能使用
并让我知道它的输出吗?嗯,最初的一个输出每个“0.00英镑”,那个输出“0.00000s”