magento使用getModel('catalog/product')获取更多信息

注意:

$collection = Mage::getModel('catalog/product')->getCollection()

    ->addFieldToFilter('type_id',array('eq'=>'configurable'));

该获取产品信息语句,只返回默认的以下10条信息:

array(10) { ["entity_id"]=> string(6) "281568" ["entity_type_id"]=> string(1) "4" ["attribute_set_id"]=> string(4) "1527" ["type_id"]=> string(12) "configurable" ["sku"]=> string(11) "41401323579" ["has_options"]=> string(1) "1" ["required_options"]=> string(1) "1" ["created_at"]=> string(19) "2015-12-04 15:59:29" ["updated_at"]=> string(19) "2015-12-07 13:38:55" ["stock_item"]=> object(Varien_Object)#43683 (7) { ["_data":protected]=> array(1) { ["is_in_stock"]=> NULL } ["_hasDataChanges":protected]=> bool(false) ["_origData":protected]=> NULL ["_idFieldName":protected]=> NULL ["_isDeleted":protected]=> bool(false) ["_oldFieldsMap":protected]=> array(0) { } ["_syncFieldsMap":protected]=> array(0) { } } }

 

如若想多返回一些其它有用的信息,可以使用addAttributeToSelect

$collection = Mage::getModel('catalog/product')->getCollection()

    ->addAttributeToSelect('image')

    ->addFieldToFilter('type_id',array('eq'=>'configurable'));

返回:

array(11) { ["entity_id"]=> string(6) "281568" ["entity_type_id"]=> string(1) "4" ["attribute_set_id"]=> string(4) "1527" ["type_id"]=> string(12) "configurable" ["sku"]=> string(11) "41401323579" ["has_options"]=> string(1) "1" ["required_options"]=> string(1) "1" ["created_at"]=> string(19) "2015-12-04 15:59:29" ["updated_at"]=> string(19) "2015-12-07 13:38:55" ["image"]=> string(53) "/hashproduct/d/4/d4722bd311ac84238a835574cb3f4519.jpg" ["stock_item"]=> object(Varien_Object)#43892 (7) { ["_data":protected]=> array(1) { ["is_in_stock"]=> NULL } ["_hasDataChanges":protected]=> bool(false) ["_origData":protected]=> NULL ["_idFieldName":protected]=> NULL ["_isDeleted":protected]=> bool(false) ["_oldFieldsMap":protected]=> array(0) { } ["_syncFieldsMap":protected]=> array(0) { } } }

 

同理:

$collection = Mage::getModel('catalog/product')->getCollection()

            ->addStoreFilter($this->_getStoreId($store))

            ->addAttributeToSelect('name')

            ->addAttributeToSelect('description')

            ->addAttributeToSelect('short_description')

            ->addAttributeToSelect('meta_title')

            ->addAttributeToSelect('meta_keyword')

            ->addAttributeToSelect('meta_description');

你可能感兴趣的:(Magento)