gpt4 book ai didi

Magento 获取所有产品

转载 作者:行者123 更新时间:2023-12-02 11:50:24 24 4
gpt4 key购买 nike

我试图获取整个 magento 产品集合,没有任何过滤器或限制,但我无法获取所有产品。

我已经尝试过各种方法,但它们都给我提供了非常有限的产品选择。假设商店包含 5000 种产品,但它只显示 500 种。当我检查目录 -> 产品时,它确实显示了整个列表。

Mage::getModel('catalog/product')->getCollection();
Mage::getResourceModel('catalog/product_collection')->addAttributeToSelect('*');
Mage::getModel("catalog/product")->getResourceCollection()->load();

它们都返回相同的数量 (500),而我预计它会为我提供 5000 个产品。我不想使用 Zend 或 PHP,而是坚持使用 Magento 方式来获取它们。

有谁知道如何真正获得所有产品,或者可以为我指出正确的方向,为什么这不起作用?

返回的选择字符串是:

SELECT 1 AS `status`, `e`.`entity_id`, `e`.`type_id`, `e`.`attribute_set_id` FROM `catalog_product_flat_4` AS `e`

最佳答案

//to overwrite limit but you need first to increase your memory limit

$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*') // select all attributes
->setPageSize(5000) // limit number of results returned
->setCurPage(1); // set the offset (useful for pagination)

// we iterate through the list of products to get attribute values
foreach ($collection as $product) {
echo $product->getName(); //get name
echo (float) $product->getPrice(); //get price as cast to float
echo $product->getDescription(); //get description
echo $product->getShortDescription(); //get short description
echo $product->getTypeId(); //get product type
echo $product->getStatus(); //get product status

// getCategoryIds(); returns an array of category IDs associated with the product
foreach ($product->getCategoryIds() as $category_id) {
$category = Mage::getModel('catalog/category')->load($category_id);
echo $category->getName();
echo $category->getParentCategory()->getName(); // get parent of category
}
//gets the image url of the product
echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).
'catalog/product'.$product->getImage();
echo $product->getSpecialPrice();
echo $product->getProductUrl(); //gets the product url
echo '<br />';
}

关于Magento 获取所有产品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8880657/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com