Any example code for simple data access?

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
User avatar
moopa
Lieutenant (LT)
Lieutenant (LT)
Posts: 59
Joined: Tue May 13, 2008 10:11 am

Any example code for simple data access?

Post by moopa » Fri May 30, 2008 4:49 am

Hi.
We are currently using the demo of ablecommerce to see if we can customize it for our needs.
To get (almost) to the point, most of the actual front end is irrelevant for us and i just want to use products database and load single products into flash using a convenient method such as xml. I have downloaded the API docs but on their own they are a little daunting. Can anyone point me in the direction of a simple example getting a single product from the database using the api? It will be a great help to me!

Thank you very much.

Dave

User avatar
m_plugables
Commander (CMDR)
Commander (CMDR)
Posts: 149
Joined: Tue Mar 11, 2008 12:44 am
Contact:

Re: Any example code for simple data access?

Post by m_plugables » Fri May 30, 2008 5:05 am

Following code will load a product for some product id

Code: Select all

Product product = ProductDataSource.Load(productid);
Following code will load product or products based upon some SQL criteria

Code: Select all

ProductCollection products = ProductDataSource.LoadForCriteria("some sql criteria like Name='abx' ");
You can found more information on this thread.
viewtopic.php?f=42&t=7297
Image
Visit the links below to Download Plugins for your AC7 Store
http://www.plugables.com
http://blog.plugables.com

User avatar
moopa
Lieutenant (LT)
Lieutenant (LT)
Posts: 59
Joined: Tue May 13, 2008 10:11 am

Re: Any example code for simple data access?

Post by moopa » Fri May 30, 2008 6:33 am

mazhar: Thanks very much for the post. I was tinkering and had worked out getting a product and i am pleased to say i did it in the same way you have!
I wrote a little test code and thought it may help other people who have just installed ablecommerce (below).

Code: Select all

  protected void Page_Load(object sender, EventArgs e)
    {
        int ProductId = 1; // Test product id

        // Load a product
        Product p = CommerceBuilder.Products.ProductDataSource.Load(ProductId);

        StringBuilder sb = new StringBuilder();
        sb.Append("Product Name: " + p.Name + "<br />");
        sb.Append("Price: " + p.Price + "<br />");
        sb.Append("Product Image: " + p.ImageUrl + "<br />");

        // Display product options (for example color or size).
        ProductOptionCollection poCollection = p.ProductOptions;
        foreach (ProductOption po in poCollection)
        {
            // Display each of the option choices (Small, Medium Large).
            OptionChoiceCollection ocCollection = po.Option.Choices;
            sb.Append("<br />Option: " + po.Option.Name + "<br /><br />");
            foreach(OptionChoice oc in ocCollection)
            {
                sb.Append("Choice: " + oc.Name.ToString() + "<br />");
            }
        }
        Response.Write(sb.ToString());
    }
Many thanks

Dave

User avatar
m_plugables
Commander (CMDR)
Commander (CMDR)
Posts: 149
Joined: Tue Mar 11, 2008 12:44 am
Contact:

Re: Any example code for simple data access?

Post by m_plugables » Fri May 30, 2008 6:51 am

Thanks for sharing your experience, these sort of things can help out many people.
Image
Visit the links below to Download Plugins for your AC7 Store
http://www.plugables.com
http://blog.plugables.com

Post Reply