Giter VIP home page Giter VIP logo

unity-magento-client's Introduction

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

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

List Categories

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

StartCoroutine(MagentoService.Instance.DownloadRootCategory(rootCategory =>
	{
		List<Category> categories = rootCategory.children_data;
		foreach (Category c in categories)
		{
			Debug.Log("Downloaded category: " + c.name + " (id: " + c.id + ")");
			// do something else with each category here.
		}
	}
);

List Product Summary under a Category

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

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

Obtain detail of a product given its SKU

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

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

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

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

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

StartCoroutine(MagentoService.Instance.DownloadProductImageUrlList(sku, (urls) =>
{
	foreach(string url in urls){
		Debug.Log(url);
	}
}));

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

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

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

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

unity-magento-client's People

Contributors

chen0040 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.