我在我的magento中创建了10个产品和两个类别'A'和'B'。这10个产品被分配到A类而不是B类。我想根据sku的属性值仅显示B类中的3个产品。 我在app / design / frontend / my_theme_package / mytheme / catalog / product / list.phtml中使用以下代码:
<?php
$products = Mage::getResourceModel('catalog/product_collection');
$products->addAttributeToSelect('sku', '9780007512119');
$products->addAttributeToFilter('visibility', array('neq' => 1));
$products->addAttributeToFilter('status', 1);
$products->load();
if ($products->getFirstItem())
{
$product = $products->getFirstItem();
echo $product->getName();
}
else
{
echo 'No product exists with the name ' . $name;
}
&GT;
答案 0 :(得分:0)
addAttributeToSelect方法仅过滤属性,而不过滤基于属性的产品,如addAttributeToFilter。
请尝试使用此代码:
<?php
$products = Mage::getResourceModel('catalog/product_collection');
$products->addAttributeToFilter('sku', '9780007512119');
$products->addAttributeToFilter('visibility', array('neq' => 1));
$products->addAttributeToFilter('status', 1);
$products->load();
if ($products->getFirstItem())
{
$product = $products->getFirstItem();
echo $product->getName();
}
else
{
echo 'No product exists with the name ' . $name;
}