Load all variants for product on custom page

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Load all variants for product on custom page

Post by jmestep » Mon Jan 05, 2009 8:54 am

I'm trying to fix a page someone did for the multiple purchase of products with variants. He used ProductOptionCollection productOption = ProductOptionDataSource.LoadForProduct(ProductList[iProductListCount].ProductId); to create a collection to display
and with that, the option sku doesn't get passed to the basket and the availability isn't checked.
Is there something comparable for variants? I've tried ProductVariantCollection productOption = ProductVariantDataSource.LoadAllForProduct(ProductList[iProductListCount].ProductId);
and get the error CS0120: An object reference is required for the nonstatic field, method, or property 'CommerceBuilder.Products.ProductVariantDataSource.LoadAllForProduct(int)'

I've looked at other methods of variants also.
What would be the best way to approach this?

Thanks
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Load all variants for product on custom page

Post by mazhar » Mon Jan 05, 2009 10:21 am

You can load the variants as below

Code: Select all

ProductVariantCollection pvc = ProductVariantDataSource.LoadForProduct(productId);
GridView1.DataSource = pvc;
GridView1.DataBind();
If you want to load a single variant depending upon the option choices then it would be

Code: Select all

OptionChoiceCollection occ = OptionChoiceDataSource.LoadForOption(optionId);
        int[] choiceIds = new int[]{occ[0].OptionChoiceId};
        ProductVariant pv = ProductVariantDataSource.LoadForOptionList(productId,choiceIds);
        Response.Write(pv.Sku);
Where in above code I just have a single option with three
choices and I am loading the one of three variants which is for first choice.
CS0120: An object reference is required for the nonstatic field, method, or property 'CommerceBuilder.Products.ProductVariantDataSource.LoadAllForProduct(int)'
Make sure your ProductList variable has some valid reference value.

Post Reply