question

daksshbhambre avatar image
daksshbhambre asked

List Store in playfab

So i am new to playfab and i want to make a store in my unity game where you can see the name of the item and the cost of the item like a list scroll view . But i don't know how to get the display name and the price from the playfab store and i also want to list the item. I tried searching for tutorial but no luck ): please tell me the code used to do this.

unity3dIn-Game Economygame manager
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Gosen Gao avatar image
Gosen Gao answered

You can use API GetStoreItems to get the item’s info for a specific store. But it is not include the DisplayName, you may need to call API GetCatalogItems to get the DisplayName. Or you can add the DiaplayerName to the store item’s CustomData. Usually, it is recommended to locally cache catalog items for future reference. With code below you can get item’s ItemId, DiaplayName and prices, then you can use it to implement UI in the game.

public Dictionary<string, CatalogItem> Map = new Dictionary<string, CatalogItem>();

void Start()
{
    PlayFabClientAPI.LoginWithCustomID(new LoginWithCustomIDRequest
    {
        CustomId = "Gosen"
    },
    result => {
        GetCatalogItems();
    },
    error => { 
        Debug.Log(error.GenerateErrorReport());
    });
}

public void GetCatalogItems()
{
    PlayFabClientAPI.GetCatalogItems(new GetCatalogItemsRequest
    {
        CatalogVersion = "Main"
    },
    result => {
        foreach (CatalogItem item in result.Catalog)
        {
            Map.Add(item.ItemId, item);
        }
        GetStoreItems();
    },
    error => {
        Debug.Log(error.GenerateErrorReport());
    });
}

public void GetStoreItems()
{
    PlayFabClientAPI.GetStoreItems(new GetStoreItemsRequest
    {
        StoreId = "TestStore",

    },
    result => {
        foreach (var item in result.Store)
        {
            Debug.Log("ItemId:" + item.ItemId);
            Debug.Log("VirtualCurrencyPrices:" + item.VirtualCurrencyPrices["GC"]);
            Debug.Log("DisplayName:" + Map[item.ItemId].DisplayName);
        }
    },
    error => {
        Debug.Log(error.GenerateErrorReport());
    });
}
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

daksshbhambre avatar image daksshbhambre commented ·

Thank you so much!

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.