0

嗨,我是 magento 的新手,我需要从特定类别中获取产品

为此我有使用

<?php 
$id1=4;
$category1 = Mage::getModel('catalog/category')->load($id1);
$collection1 = $category1->getProductCollection();
$collection1->addAttributeToSelect('name');
$collection1->addAttributeToSelect('description');
$collection1->addAttributeToSelect('image');
$collection1->addAttributeToSelect('producturl');
$collection1->addAttributeToSelect('prlce');

$products1 = $collection1->getItems();
$_helper1 = $this->helper('catalog/output'); ?> 

                                                <?php foreach ($products1 as $product1){  ?>

    <?php echo $this->htmlEscape($product1->getPrice()) ?>

    <?php } ?>

在这里它显示了名称、图像和网址,但是当我试图回显价格时,它没有显示任何内容。请建议我在哪里做错了

4

1 回答 1

0

这就是你的做法:

<?php

// Test Params
$cat_id   = 4;
$store_id = 1;

// Load Category
$category = Mage::getModel('catalog/category')->load($cat_id);

// Load Category Products
$categoryProducts = $category->getProductCollection();

// Iterate Through Product Collection
foreach ($categoryProducts as $categoryProduct)
{
    // Load Product At Specified Store Id
    $product = Mage::getModel('catalog/product')
               ->setStoreId($store_id)
               ->load($categoryProduct->getId());

    // Debug
    print_r($product->getData());

    // Get Price (e.g.)
    echo 'Product Price: '. $product->getPrice()
}

?>
于 2013-11-01T14:34:30.413 回答