+1-888-365-2779
Try Now
More in this section

Forums / Ecommerce / Variants and attributes

Variants and attributes

10 posts, 0 answered
  1. Nick
    Nick avatar
    113 posts
    Registered:
    21 Oct 2008
    22 Dec 2011
    Link to this post
    Is there any example code or documentation for the product attributes? We need to create custom product templates for different product types and this includes controlling/customising how we present and work with the variants. I've bumbled through some code myself today but it would be handy to get some real examples direct from Telerik for how to work with the attributes from code.

    thanks
  2. Svetoslav Petsov
    Svetoslav Petsov avatar
    456 posts
    Registered:
    24 Sep 2012
    27 Dec 2011
    Link to this post
    Hi,

     We still don't have code samples for most of the ECommerce parts, as it is a relatively new addition to Sitefinity and is being developed and changed with each release. However, you can share exactly what difficulties you are experiencing with the ECommerce API (the attributes in particular) and I will assist you in solving the problem.

    Kind regards,
    Svetoslav Petsov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Nick
    Nick avatar
    113 posts
    Registered:
    21 Oct 2008
    03 Jan 2012
    Link to this post
    The current scenario is as follows:

    We have a custom product detail control that displays the product details. This control needs to display the product data differently depending on the type of product it is displaying, so this control loads a separate control that dictates this product type specific layout and behaviour. One of the key differences between products is the variants available, and how they are presented to the customer. For this example, say we have the following variations available for a product:

    Attribute: Single Box, or Case of 10
    Then for each attribute there are multiple size options.

    For the product page for this type of product we need to display two columns, the first column will list the Singe Box options, the second column will show the Box of 10 options. We'll be using quantity boxes to allow the customer to select how many of each option they would like before adding their choices to the basket.

    I know that at the moment the attributes are flat, and I suspect a hierarchical structure would make this easier (as a side question, when are hierarchical attributes expected to be released, I didn't see them in the road map the last time I looked?), so I guess the help I need here is to do the following:

    //get all size options for the product, bind this to a repeater of some sort
    //on databound of each size option
      //check against each attribute (looking for Single Box for the first column, then Case of 10 for the second) and if there is one, display the quantity controls.

    I have attached a jpg of the layout so you can understand this better.

    thanks


  4. Svetoslav Petsov
    Svetoslav Petsov avatar
    456 posts
    Registered:
    24 Sep 2012
    05 Jan 2012
    Link to this post
    Hello,

     Here's a sample code that gets a single product, then gets its variations for a specific attribute ("size") and for each variation gets the its relevant value. You can then add the values to a collection and bind it to the desired control. The same can be done for all the other variations.

    CatalogManager mng = CatalogManager.GetManager();
                var product = mng
                    .GetProducts()
                    .Where(p => p.Title == "Test")
                    .Single();
                var variations2 = mng
                    .GetProductVariations(product.Id)
                    .Where(v => v
                        .ProductVariationDetail[0]
                        .ProductAttributeParent
                        .Name == "size");
                foreach (var item in variations2)
                {
                    var val = item.ProductVariationDetail[0].ProductAttributeValueParent.Title;
                }

    Let me know if this doesn't provide the desired functionality or if you need further assistance with it.

    Kind regards,
    Svetoslav Petsov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Nick
    Nick avatar
    113 posts
    Registered:
    21 Oct 2008
    13 Jan 2012
    Link to this post
    Hi, thanks for the suggestion, I've just got around to trying it;

    I have my product (ProductItem), and from there I'm doing the following:

    CatalogManager catMan = CatalogManager.GetManager();
    var singleOptions = catMan.GetProductVariations(ProductItem.Id).Where(v => v.ProductVariationDetail[0].ProductAttributeParent.Name == "single-box");
    
    But this gives me the following error:
    An exception occured during the execution of '
    Extent<Telerik.Sitefinity.Ecommerce.Catalog.Model.ProductVariation>().Where(p => ((p.ApplicationName == OpenAccessProvider.ApplicationName) AndAlso (p.Parent.Id == value(Telerik.Sitefinity.Modules.Ecommerce.Catalog.Data.OpenAccessCatalogDataProvider+<>c__DisplayClass6).productId))).Where(v => (v.ProductVariationDetail.get_Item(0).ProductAttributeParent.Name == "single-box"))'.

    The further message displayed in browser is:
    Execution of 'System.Collections.Generic.IList`1[[Telerik.Sitefinity.Ecommerce.Catalog.Model.ProductVariationDetail, Telerik.Sitefinity.Model, Version=4.4.2117.0, Culture=neutral, PublicKeyToken=b28c218413bdf563]]:get_Item(Int32)' on the database server side currently not implemented.
  6. Svetoslav Petsov
    Svetoslav Petsov avatar
    456 posts
    Registered:
    24 Sep 2012
    18 Jan 2012
    Link to this post
    Hi,

     I apologize, I skipped a part of the code when I pasted it. You should call .ToList() for the IQueryable collection, before filtering, as Open Access currently does not support nested Where clauses, here's the whole correct code:

    CatalogManager mng = CatalogManager.GetManager();
     
                var product = mng
     
                    .GetProducts()
     
                    .Where(p => p.Title == "Test")
     
                    .Single();
     
                var variations2 = mng
     
                    .GetProductVariations(product.Id)
                    .ToList()
     
                    .Where(v => v
     
                        .ProductVariationDetail[0]
     
                        .ProductAttributeParent
     
                        .Name == "size");
     
                foreach (var item in variations2)
                {
     
                    var val = item.ProductVariationDetail[0].ProductAttributeValueParent.Title;
     
                }


    Greetings,
    Svetoslav Petsov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Nick
    Nick avatar
    113 posts
    Registered:
    21 Oct 2008
    20 Jan 2012
    Link to this post
    OK, I've got this pulling the variations out fine,

    var singleOptions = mng.GetProductVariations(ProductItem.Id).ToList().Where(v => v.ProductVariationDetail[0].ProductAttributeParent.Name == "single-box");

    However, how I can make sure they are in the same order as they are displayed in the backend? - going into the product list and viewing the variations allows me to sort them manually, but they don't come out in that order and I can't see any ordinal property to use in an orderby clause.
  8. Svetoslav Petsov
    Svetoslav Petsov avatar
    456 posts
    Registered:
    24 Sep 2012
    21 Jan 2012
    Link to this post
    Hi,

     The product variations in the Backend are ordered by their LastModified property, as far as I can see from my project. I cannot move/reorder them manually. Are you sure you can do that? If so, can you send me a video of that behavior so I can reproduce it locally? Thanks in advance. 

    Regards,
    Svetoslav Petsov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  9. Nick
    Nick avatar
    113 posts
    Registered:
    21 Oct 2008
    23 Jan 2012
    Link to this post
    Hi,

    Sorry my last post was a bit misleading. The sorting is done in the attributes section, not the product section. I'll try to get a video together later, but for the now the re-ordering is done by:

    Ecommerce > Attributes
    From the Attributes list, select an attribute
    From here, the values within that attribute can be sorted using drag and drop.

    The obvious example here is that I'm pulling out size variants and I want (need) to make sure they are ordered; Small, Medium, Large, X-Large. At the moment they are not coming out in that order, despite me ordering like that using the drag and drop. 
  10. Svetoslav Petsov
    Svetoslav Petsov avatar
    456 posts
    Registered:
    24 Sep 2012
    23 Jan 2012
    Link to this post
    Hello,

     I understand now. If you want to sort the attributes, then you will have to sort the collection that consists of attribute items values (which is actually the second collection that you are going to create). This means that you need to sort the final collection that you will create. You can do something like that:

    List<ProductAttributeValue> list = new List<ProductAttributeValue>();
                foreach (var item in variations2)
                {
     
                    var val = item.ProductVariationDetail[0].ProductAttributeValueParent;
                    list.Add(val);
     
                }
                list.OrderBy(i => i.Ordinal);

    Regards,
    Svetoslav Petsov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
10 posts, 0 answered