简体   繁体   中英

Ruby XML Parsing with Nokogiri/XPath

I have a shopify store that I want to automatically update the product variants inventory levels with, using a live xml feed from the wholesaler I use.

I'm learning to program (Ruby) and this is my first project, but after researching here is how I think it should work.

Use Ruby/Nokugiri to parse the XML feed from the wholesaler, and then Xpath to locate both the unique product variant SKU code, and the stock level.

Somehow I need to use this SKU to refer back to my Shopify store product XML list, and pull out the variants unique ID using the SKU code.

Then use something like the builder gem to build the XML format that shopify needs, and then use curl to PUT the changes. I'm guessing I loop this process for every product?

I know Shopify only has a 300 call limit, so I've got the article on putting a delay in the script, but I get the feeling the above method isn't the easiest way to go about this?

With Shopify you need to apply the variant stock level update against unique variant xml files, so I need to build the unique xml file/code and PUT it against /admin/variants/#[thevariantid].xml

I'm looking forward to trying to put this together and learning in the process, but am I on the right track with this? Are there simpler gems I should be looking at?

nb I've only recently started learning Ruby, and will head to Rails afterwards. I know a bit about XML and it's structure so should be ok finding what I need with XPath.

You're on the right track, but I'd use the shopify_api gem to do the talking to Shopify instead of having to form the XML and URIs yourself: https://github.com/Shopify/shopify_api

There's an article on our wiki that might also help you out with regards to the API call limit but just let me know if you need more space – we're pretty flexible and the limit is really just there to keep scripts from going wild and affecting service for everyone else.

您建议的路径看起来不错,只是不需要使用“ builder” gem,因为Nokogiri内置了一些非常不错的XML构建

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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