1
如何使用REST API获取带分页的产品列表?我有以下代码 -Magetno REST API - 获取带分页的产品列表
require_once '../app/Mage.php';
Mage::app('default');
$productCollection = Mage::getResourceModel('catalog/product');
print_r($productCollection);
输出
[_data:protected] => Array
(
[entity_type_id] => 4
[entity_type_code] => catalog_product
[entity_model] => catalog/product
[attribute_model] => catalog/resource_eav_attribute
[entity_table] => catalog/product
[value_table_prefix] =>
[entity_id_field] =>
[is_data_sharing] => 1
[data_sharing_key] => default
[default_attribute_set_id] => 4
[increment_model] =>
[increment_per_store] => 0
[increment_pad_length] => 8
[increment_pad_char] => 0
[additional_attribute_table] => catalog/eav_attribute
[entity_attribute_collection] => catalog/product_attribute_collection
)
任何人都可以请帮助我。
更新按照你的建议,我已经更新代码为 -
require_once '../app/Mage.php';
Mage::app('default');
$pageSize = $_REQUEST['pagesize'];
$pageNum = $_REQUEST['pagenum'];
$productCollection = Mage::getModel('catalog/product')
->getCollection()
->setPageSize($pageSize)
->setCurPage($pageNum)
->addAttributeToSelect('*');
print_r($productCollection->getData());
,输出是现在 -
[0] => Array
(
[entity_id] => 12
[entity_type_id] => 4
[attribute_set_id] => 4
[type_id] => simple
[sku] => 20707
[has_options] => 1
[required_options] => 1
[created_at] => 2016-01-06 21:15:31
[updated_at] => 2016-10-03 00:49:21
)
但还是没能得到产品名称,描述,图片等还有什么我失踪的东西吗?
谢谢了拉维的答复,则打印以下数组 - [0] =>数组 ( [ENTITY_ID] => 12 [entity_type_id] => 4 [attribute_set_id] => 4 [ type_id] =>简单 [sku] => 20707 [has_options] => 1 [required_options] => 1 [created_at] => 2016-01-06 21:15:31 [updated_at] => 2016- 10-03 00:49:21 )我需要产品相关的字段,如产品名称,描述,图片等 –
您可以更改上述代码如下 –
Mage :: getModel('catalog/product') - > getCollection() - > addAttributeToSelect('sku') - > addAttributeToSelect('name') - > setPageSize($ pageSize) - > setCurPage($ pageNum) ; –