项目作者: chen0040

项目描述 :
Magento client implemented in Unity3D
高级语言: C#
项目地址: git://github.com/chen0040/unity-magento-client.git
创建时间: 2017-07-20T02:04:39Z
项目社区:https://github.com/chen0040/unity-magento-client

开源协议:MIT License

下载


unity-magento-client

Magento client implemented in Unity3D

Install

Git clone this project and export it as a unity package, then import the package into your own project. The sample code can be found in the folder MageClientSample/MagentoServiceSample.cs

Usage

Before calling any magento api, the base url of the magento site must be initialized:

Initialization

  1. MagentoService.Instance.Initialize("http://www.your-magento.com");

List Categories

The sample code below shows how to download the categories from the magento site:

  1. StartCoroutine(MagentoService.Instance.DownloadRootCategory(rootCategory =>
  2. {
  3. List<Category> categories = rootCategory.children_data;
  4. foreach (Category c in categories)
  5. {
  6. Debug.Log("Downloaded category: " + c.name + " (id: " + c.id + ")");
  7. // do something else with each category here.
  8. }
  9. }
  10. );

List Product Summary under a Category

The sample code below shows how to download list all product summaries under a particular category

  1. long categoryId = 10;
  2. StartCoroutine(MagentoService.Instance.DownloadProductsInCategory(categoryId, (catId, products) => {
  3. for(int i=0; i < 6 && i < products.Count; ++i)
  4. {
  5. CategoryProduct categoryProduct = products[i];
  6. Debug.Log("Download products in category " + categoryId + ": " + categoryProduct.sku);
  7. // use the sku to retrieve the product detail here
  8. }
  9. );

Obtain detail of a product given its SKU

The sample code below shows to download the product detail associated with a particular sku

  1. string sku = "product_dynamic_17";
  2. StartCoroutine(MagentoService.Instance.DownloadProductDetail(sku, (product) => {
  3. Debug.Log("Name for sku " + product.sku + ": " + product.name);
  4. Debug.Log("Price for sku " + product.sku + ": " + product.price);
  5. Debug.Log("Weight for sku " + product.sku + ": " + product.weight);
  6. }));

Obtain list of medias under the product (images and videos)

The sample code below shows how to download the media list under a product using its sku

  1. StartCoroutine(MagentoService.Instance.DownloadProductMediaList(sku, (mediaList) => {
  2. foreach(ProductMedia media in mediaList){
  3. Debug.Log("type: " + media.media_type + "\tfilename: " + media.file);
  4. }
  5. }));

If you prefer to get the list of image urls instead of the ProductMedia List as given by the above api call, the sample code below shows how to obtains urls of all images associated with a product using its sku

  1. StartCoroutine(MagentoService.Instance.DownloadProductImageUrlList(sku, (urls) =>
  2. {
  3. foreach(string url in urls){
  4. Debug.Log(url);
  5. }
  6. }));

Obtain a byte array for each image under a product

The sample code below shows how to download all the image byte arrays under a product using its sku

  1. string sku = "product_dynamic_17";
  2. StartCoroutine(MagentoService.Instance.DownloadProductImages(sku, (bytes) => {
  3. Debug.Log("Bytes for product " + sku + " is " + bytes.Length);
  4. }));

Obtain a texture for each image under a product

The sample code below shows how to download all the image textures under a product using its sku

  1. string sku = "product_dynamic_17";
  2. StartCoroutine(MagentoService.Instance.DownloadProductTextures(sku, (texture) => {
  3. Debug.Log("texture for product " + sku + " is " + (texture != null));
  4. }));