我需要使用magento列出所有具有至少一个可配置选项的简单产品。
循环内的条件是什么?
<?php require_once 'app/Mage.php';
umask(0);
set_time_limit(0); // ignore php timeout
ignore_user_abort(true); // keep on going even if user pulls the plug*
while(ob_get_level())ob_end_clean(); // remove output buffers
ob_implicit_flush(true); // output stuff directly
//error_reporting(E_ALL);
/* not Mage::run(); */
Mage::app('default');
// get product collection (All product)
$storeId = Mage::app()->getStore()->getId();
$visibility = array(
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG);
$_productCollection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('visibility', $visibility)
->setStoreId($storeId)
->addStoreFilter($storeId);
foreach ($_productCollection as $pro):
endforeach;
?>
答案 0 :(得分:0)
首先我不会使用:addAttributeToSelect('*')
你会减慢速度。
$products = Mage::getModel('catalog/products')->getCollection()->addAttributeToFilter('type_id', 'simple')->addAttributeToSelect('name');
foreach ($products as $product) {
echo $product->getName();
}
试试看。