Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Magento getModel('catalog/product')->带有addAttributeToSelect('*')的getCollection()未返回说明_Php_Magento - Fatal编程技术网

Php Magento getModel('catalog/product')->带有addAttributeToSelect('*')的getCollection()未返回说明

Php Magento getModel('catalog/product')->带有addAttributeToSelect('*')的getCollection()未返回说明,php,magento,Php,Magento,我有下面的代码从magento获取所有产品数据,但它没有返回描述字段。我只得到简短的描述。实际上,除了描述之外,它还缺少几个字段。无论如何,代码如下: $collection = Mage::getModel('catalog/product')->getCollection() ->joinField( 'qty', 'cataloginventory/stock_item', 'qty', 'product_id=e

我有下面的代码从magento获取所有产品数据,但它没有返回描述字段。我只得到简短的描述。实际上,除了描述之外,它还缺少几个字段。无论如何,代码如下:

$collection = Mage::getModel('catalog/product')->getCollection()
            ->joinField(
                    'qty', 'cataloginventory/stock_item', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', 'left'
            )
            ->addAttributeToFilter('status', 1) // enabled
            ->addUrlRewrite()
            ->addPriceData()
            ->addStoreFilter($store_id)
            ->addAttributeToSelect('*');
    Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($collection);
    Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($collection);
    $collection->setOrder('sku', 'desc');
这将在I var_dump时创建以下查询:

SELECT 1 AS `status`, `e`.`entity_id`, `e`.`type_id`, `e`.`attribute_set_id`, `at_qty`.`qty`, `price_index`.`price`, `price_index`.`tax_class_id`, `price_index`.`final_price`, IF(price_index.tier_price IS NOT NULL, LEAST(price_index.min_price, price_index.tier_price), price_index.min_price) AS `minimal_price`, `price_index`.`min_price`, `price_index`.`max_price`, `price_index`.`tier_price`, `e`.`entity_id`, `e`.`attribute_set_id`, `e`.`type_id`, `e`.`allow_open_amount`, `e`.`cost`, `e`.`created_at`, `e`.`email_template`, `e`.`enable_googlecheckout`, `e`.`giftcard_amounts`, `e`.`giftcard_type`, `e`.`gift_message_available`, `e`.`gift_wrapping_available`, `e`.`gift_wrapping_price`, `e`.`has_options`, `e`.`image_label`, `e`.`is_recurring`, `e`.`is_redeemable`, `e`.`lifetime`, `e`.`links_exist`, `e`.`links_purchased_separately`, `e`.`links_title`, `e`.`msrp`, `e`.`msrp_display_actual_price_type`, `e`.`msrp_enabled`, `e`.`name`, `e`.`news_from_date`, `e`.`news_to_date`, `e`.`open_amount_max`, `e`.`open_amount_min`, `e`.`price`, `e`.`price_type`, `e`.`price_view`, `e`.`recurring_profile`, `e`.`required_options`, `e`.`shipment_type`, `e`.`short_description`, `e`.`sku`, `e`.`sku_type`, `e`.`small_image`, `e`.`small_image_label`, `e`.`special_from_date`, `e`.`special_price`, `e`.`special_to_date`, `e`.`tax_class_id`, `e`.`thumbnail`, `e`.`thumbnail_label`, `e`.`updated_at`, `e`.`url_key`, `e`.`url_path`, `e`.`use_config_email_template`, `e`.`use_config_is_redeemable`, `e`.`use_config_lifetime`, `e`.`visibility`, `e`.`weight`, `e`.`weight_type`, `e`.`brand`, `e`.`brand_value`, `e`.`new_in`, `e`.`new_in_value`, `e`.`amconf_simple_price`, `e`.`volume_weight`, `e`.`product_3rd_type`, `e`.`product_3rd_type_value`, `e`.`product_sub_type`, `e`.`product_sub_type_value`, `e`.`product_type`, `e`.`product_type_value`, `e`.`parent_sku`, `at_inventory_in_stock`.`is_in_stock` AS `inventory_in_stock` FROM `catalog_product_flat_1` AS `e`
 LEFT JOIN `cataloginventory_stock_item` AS `at_qty` ON (at_qty.`product_id`=e.entity_id) AND (at_qty.stock_id=1)
 INNER JOIN `catalog_product_index_price` AS `price_index` ON price_index.entity_id = e.entity_id AND price_index.website_id = '1' AND price_index.customer_group_id = 0
 INNER JOIN `cataloginventory_stock_item` AS `at_inventory_in_stock` ON (at_inventory_in_stock.`product_id`=e.entity_id) AND ((at_inventory_in_stock.use_config_manage_stock = 0 AND at_inventory_in_stock.manage_stock=1 AND at_inventory_in_stock.is_in_stock=1) OR (at_inventory_in_stock.use_config_manage_stock = 0 AND at_inventory_in_stock.manage_stock=0) OR (at_inventory_in_stock.use_config_manage_stock = 1 AND at_inventory_in_stock.is_in_stock=1))
所以只有简短的描述,但我不知道为什么没有描述

我知道我能行

Mage::getModel('catalog/product')->load($product->getId())
但是我不想多次查询数据库。当我进行getCollection时,有没有办法解决这个问题或获取这些字段


更新:似乎我的主要问题是,当我运行第一个代码时,我只得到必需的字段。在获取$collection的部分中,我希望在产品的描述页面中包含其他字段。如果不为每个产品加载,代码是什么?

请尝试将产品列表中使用的描述字段的产品属性设置为“是”。这将解决您的问题并避免单个产品型号的负载


但请确保在更改此属性后,您必须重新索引数据。

Magento在像这样使用模型集合时,最初不会加载所有属性

$collections = Mage::getModel('catalog/product')->getCollection(); 
选择表格是很重要的

SELECT `e`.* FROM `catalog_product_entity` AS `e`
使用orm表的Magento。如果我们在这里面多挖点

foreach($collections as $collection) {
    echo $collection->getName();
}
现在您可以看到附加的quire将运行

更多详情请访问

但您可以从平面表中获取所有产品详细信息集合,而无需多次查询数据库。为此,您需要在管理->系统->配置->目录->目录->前端-> 在这里,您可以看到启用平面目录的选项

Use Flat Catalog Category -> Enable
Use Flat Catalog Product  -> Enable
有关平面目录的更多详细信息,请访问

现在你看到了查询,它会是这样的

选择1作为状态、e.entity\u id、e.type\u id、e.attribute\u set\u id、e.entity\u id、e.attribute\u set\u id、e.type\u id、e.allow\u open\u amount、e.cost、e.created\u at、e.email\u模板、e.enable\u googlecheckout、e.giftcard\u amounts、e.giftcard\u type、e.giftcard\u message\u available、e.gift\u包装、e.gift\u价格、e.has\u选项、e.image\u标签、,e.is_定期,e.is_可赎回,e.lifetime,e.links_存在,e.links_单独购买,e.links_标题,e.msrp,e.msrp_显示实际价格类型,e.msrp_启用,e.name,e.news_自日期,e.news_至日期,e.open_最大金额,e.open_最小金额,e.price,e.price_类型,e.price_视图,e.rective_配置文件,e.required_选项,e.u类型,e.short\u description、e.sku、e.sku\u type、e.small\u image、e.small\u image\u label、e.special\u from\u date、e.special\u price、e.special\u to\u date、e.tax\u class\u id、e.缩略图、e.缩略图\u label、e.updated\u at、e.url\u key、e.url\u路径、e.use\u config\u email\u模板、e.use\u config\u可赎回、e.use\u配置、e.config\u生命周期、e.visibility、e.weight、e\u type、,e.项链长度,e.项链长度\u目录中的值\u产品\u平面\u 1为e

但请记住,有些方法在平面目录中不可用,如果禁用了,也不可用

Function Name                   Flat Catalog Enabled    Flat Disabled
setLoadProductCount($flag)       No                      Yes
setProductStoreId($storeId)      No                      Yes
addParentPathFilter($parent)     Yes                     No
addStoreFilter()                 Yes                     No
addSortedField($sorted)          Yes                     No

我觉得我的问题有点不同。我用附加信息更新了问题。所以,对于这个特殊的,他们根据需要设置简短的描述,而描述不是。我需要找到一种方法将它们包含在我的第一个查询中。