Fetching value from collection

Posted by user334119 on Stack Overflow See other posts from Stack Overflow or by user334119
Published on 2010-05-06T06:03:49Z Indexed on 2010/05/06 6:08 UTC
Read the original article Hit count: 313

Filed under:

public string GetProductVariantImageUrl(ShoppingCartItem shoppingCartItem) { string pictureUrl = String.Empty; ProductVariant productVariant = shoppingCartItem.ProductVariant; ProductVariantAttributeValueCollection pvaValues = shoppingCartItem.Attributes; [here the count comes 0]{case1} }

public string GetAttributeDescription(ShoppingCartItem shoppingCartItem) { string result = string.Empty;

        ProductVariant productVariant = shoppingCartItem.ProductVariant;

if (productVariant != null) { ProductVariantAttributeValueCollection pvaValues = shoppingCartItem.Attributes;[here count is 1] } }

WHY am i not able to get count as 1 for the case1.

/// <summary>
/// Represents a shopping cart item
/// </summary>
public class ShoppingCartItem : BaseEntity
{
    #region Fields
    private ProductVariant _cachedProductVariant;
    private ProductVariantAttributeValueCollection _cachedPvaValues;
    #endregion

    #region Ctor
    /// <summary>
    /// Creates a new instance of the shopping cart class
    /// </summary>
    public ShoppingCartItem()
    {
    }
    #endregion

    #region Properties
    /// <summary>
    /// Gets or sets the shopping cart item identifier
    /// </summary>
    public int ShoppingCartItemID { get; set; }

    /// <summary>
    /// Gets or sets the shopping cart type identifier
    /// </summary>
    public int ShoppingCartTypeID { get; set; }

    /// <summary>
    /// Gets or sets the customer session identifier
    /// </summary>
    public Guid CustomerSessionGUID { get; set; }

    /// <summary>
    /// Gets or sets the product variant identifier
    /// </summary>
    public int ProductVariantID { get; set; }

    /// <summary>
    /// Gets or sets the product variant attribute identifiers
    /// </summary>
    public List<int> AttributeIDs { get; set; }

    /// <summary>
    /// Gets or sets the text option
    /// </summary>
    public string TextOption { get; set; }

    /// <summary>
    /// Gets or sets the quantity
    /// </summary>
    public int Quantity { get; set; }

    /// <summary>
    /// Gets or sets the date and time of instance creation
    /// </summary>
    public DateTime CreatedOn { get; set; }

    /// <summary>
    /// Gets or sets the date and time of instance update
    /// </summary>
    public DateTime UpdatedOn { get; set; }
    #endregion

    #region Custom Properties

    /// <summary>
    /// Gets the log type
    /// </summary>
    public ShoppingCartTypeEnum ShoppingCartType
    {
        get
        {
            return (ShoppingCartTypeEnum)ShoppingCartTypeID;
        }
    }

    /// <summary>
    /// Gets the product variant
    /// </summary>
    public ProductVariant ProductVariant
    {
        get
        {
            if (_cachedProductVariant == null)
            {
                _cachedProductVariant = ProductManager.GetProductVariantByID(ProductVariantID);
            }
            return _cachedProductVariant;
        }
    }

    /// <summary>
    /// Gets the product variant attribute values
    /// </summary>
    public ProductVariantAttributeValueCollection Attributes
    {
        get
        {
            if (_cachedPvaValues == null)
            {
                ProductVariantAttributeValueCollection pvaValues = new ProductVariantAttributeValueCollection();
                foreach (int attributeID in this.AttributeIDs)
                {
                    ProductVariantAttributeValue pvaValue = ProductAttributeManager.GetProductVariantAttributeValueByID(attributeID);
                    if (pvaValue != null)
                        pvaValues.Add(pvaValue);
                }
                _cachedPvaValues = pvaValues;
            }
            return _cachedPvaValues;
        }
    }

    /// <summary>
    /// Gets the total weight
    /// </summary>
    public decimal TotalWeigth
    {
        get
        {
            decimal totalWeigth = decimal.Zero;
            ProductVariant productVariant = ProductVariant;
            if (productVariant != null)
            {
                decimal attributesTotalWeight = decimal.Zero;
                foreach (ProductVariantAttributeValue pvaValue in this.Attributes)
                {
                    attributesTotalWeight += pvaValue.WeightAdjustment;
                }
                decimal unitWeight = productVariant.Weight + attributesTotalWeight;
                totalWeigth = unitWeight * Quantity;
            }
            return totalWeigth;
        }
    }

    /// <summary>
    /// Gets a value indicating whether the shopping cart item is free shipping
    /// </summary>
    public bool IsFreeShipping
    {
        get
        {
            ProductVariant productVariant = this.ProductVariant;
            if (productVariant != null)
                return productVariant.IsFreeShipping;
            return true;
        }
    }

© Stack Overflow or respective owner

Related posts about ASP.NET