如何使用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 :(得分:1)
在api请求中发送pagesize和pagenum的get参数。
require_once '../app/Mage.php';
Mage::app('default');
$pageSize = $_GET['pagesize']
$pageNum = $_GET['pagenum']
$productCollection = Mage::getModel('catalog/product')
->getCollection()
->setPageSize($pageSize)
->setCurPage($pageNum );
print_r($productCollection);