Page 1 of 1

Load all variants for product on custom page

Posted: Mon Jan 05, 2009 8:54 am
by jmestep
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

Re: Load all variants for product on custom page

Posted: Mon Jan 05, 2009 10:21 am
by mazhar
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.