Skip to content

chen0040/unity-magento-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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));
}));

About

Magento client implemented in Unity3D

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages