简体   繁体   English

如何使用带有Rails gem的Shopify API访问客户组中的客户

[英]How to access customers in a customer group using Shopify API with rails gem

I am using the Shopify API gem in my rails app to access customers and orders. 我在Rails应用程序中使用Shopify API gem来访问客户和订单。

I can pull down Customer Groups fine like below and all working well. 我可以像下面那样很好地拉低客户组,并且一切正常。

ShopifyAPI::CustomerGroup.find

I know want to access customers within a customer group, using the API call /admin/customer_groups/#{id}/customers.json 我知道要使用API​​调用/admin/customer_groups/#{id}/customers.json访问客户组中的客户

How do I do this in the same format as I do for the groups (ie using the Shopify API gem) 如何以与群组相同的格式执行此操作(即使用Shopify API gem)

UPDATE: Version 3.0.3 of the shopify_api gem adds a customers method to CustomerGroup that fetches all customers for that group. 更新:3.0.3版本shopify_api宝石增加了customers的方法来CustomerGroup是获取所有客户该组。

You can now do things like this: 您现在可以执行以下操作:

  group = ShopifyAPI::CustomerGroup.find(123)
  customers = group.customers

-- -

Right now you have to do this: 现在,您必须执行以下操作:

Customer.find(:all, :params => {:customer_group_id => customer_group.id})

Where customer_group is the one you retrieved from your earlier call. 其中customer_group是您从先前调用中检索到的那个。

HOWEVER. 然而。 I've just added a pull request to the shopify_api repo that encapsulates this call in a customers method on the CustomerGroup resource directly. 我刚刚向shopify_api存储库中添加了拉取请求,该请求将调用直接封装在CustomerGroup资源上的customers方法中。 Once it gets approved you'll be able to call .customers on any customer group you have and it'll give you all the customers. 一旦获得批准,您就可以在您拥有的任何客户组中致电.customers ,它将为您提供所有客户。

Here's the pull request for reference: https://github.com/Shopify/shopify_api/pull/40 以下是拉取请求以供参考: https : //github.com/Shopify/shopify_api/pull/40

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

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