繁体   English   中英

Drupal商业请求的外观如何?

[英]How does Drupal commerce requests looks like?

假设我在Drupal上有商务网站。 有Drupal Commerce模块。 我想使用api从我的商店中检索完整的订单。 可能吗? 我找不到任何有关此请求的外观的信息(响应格式等)。 另外我不需要php示例,也许有Rest API?

我认为,从简单到(有点)复杂的方法很少。

  • 由于您仅提及检索数据,因此简单的方法是创建列出所有订单的新视图,因此可以配置此视图以将输出呈现为XML或JSON。 使用的模块可以是Views数据导出或Views数据源。

  • 第二种解决方案是创建一个自定义模块,该模块使用hook_menu创建自定义端点URL,该模块调用一个回调函数,您可以在其中定义所需的输出

function YOURMODULE_menu() {
  $items = array();
  $items['api/order'] = array(
    'title' => 'API Orders',
    'page callback' => 'YOURMODULE_api_orders_callback',
    'access arguments' => array('access content')
  );
  $items['api/order/%'] = array(
    'title' => 'API Orders',
    'page callback' => 'YOURMODULE_api_orders_callback',
    'page arguments' => array(2),
    'access arguments' => array('access content')
  );
  return $items;
}

function YOURMODULE_api_orders_callback($order_id = NULL) {
  $order_ids = array();
  if(!is_null($order)) {
    array_push($order_ids, $order_id);
  }

  // Load all orders or only 1 order 
  // We can use commerce_order_load_multiple()  
  // or use EntityFieldQuery() if need a complex logic filtering orders
  $orders = commerce_order_load_multiple($order_ids);
  drupal_json_output($orders);
}
  • 最后一种解决方案是使用服务模块,创建自定义模块并创建自定义服务,您可以在其中定义自定义资源(在本例中为commerce_order) 可在此处找到创建自定义服务的教程👉https : //valuebound.com/resources/blog/how-to-create-custom-web-services-for-drupal-7-0

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM