示例#1
0
        public override decimal CalculateProductPrice(Telerik.Sitefinity.Ecommerce.Orders.Model.CartDetail detail, bool useExchangeRate)
        {
            decimal productPrice = detail.Price;

            if (detail.Sku == EcommerceOrderCalculatorCustom.DonationProductSku && productPrice == 0)
            {
                CartOrder cartOrder = detail.Parent;

                PropertyDescriptorCollection properties   = TypeDescriptor.GetProperties(cartOrder);
                PropertyDescriptor           property     = properties[EcommerceOrderCalculatorCustom.CartOrderDonationAmountFieldName];
                MetafieldPropertyDescriptor  metaProperty = property as MetafieldPropertyDescriptor;
                if (metaProperty != null)
                {
                    var val = metaProperty.GetValue(cartOrder);
                    if (val != null)
                    {
                        decimal donationAmount = decimal.Parse(val.ToString());
                        if (donationAmount != 0 && detail.Sku == EcommerceOrderCalculatorCustom.DonationProductSku)
                        {
                            detail.Price = donationAmount;

                            detail.BasePrice = detail.Price;
                            productPrice     = detail.Price;
                        }
                    }
                }
            }

            return(Convert(productPrice, useExchangeRate));
        }
示例#2
0
        protected List <String> getCustomFields(Type type, Type filter = null)
        {
            // we are geting the metafield associated with the product we have created and check the name of the field
            var           props   = TypeDescriptor.GetProperties(type);
            List <String> theList = new List <String>();

            foreach (var singleProp in props)
            {
                if (singleProp.GetType() == typeof(MetafieldPropertyDescriptor))
                {
                    MetafieldPropertyDescriptor customField = singleProp as MetafieldPropertyDescriptor;
                    if (filter != null)
                    {
                        if (customField.PropertyType.Equals(filter))
                        {
                            theList.Add(customField.Name);
                        }
                    }
                    else
                    {
                        theList.Add(customField.Name);
                    }
                }
            }
            return(theList);
        }
示例#3
0
        protected void AddToCartButton_Command(object sender, EventArgs e)
        {
            try
            {
                int quantity = 1;

                IShoppingCartAdder shoppingCartAdder   = new ShoppingCartAdder();
                string             defaultCurrencyName = Config.Get <EcommerceConfig>().DefaultCurrency;

                OptionsDetails optionsDetails = new OptionsDetails();

                decimal price = 0;
                if (!decimal.TryParse(DonationAmountDropDown.Value.ToString(), out price))
                {
                    price = Convert.ToDecimal(OtherAmountControl.Value);
                }

                this.Product.Price = price;
                shoppingCartAdder.AddItemToShoppingCart(this, this.OrdersManager, this.Product, optionsDetails, quantity, defaultCurrencyName);

                // Save the donation amount in custom field
                OrdersManager ordersManager = OrdersManager.GetManager();
                string        cookieKey     = EcommerceConstants.OrdersConstants.ShoppingCartIdCookieName;
                if (SystemManager.CurrentContext.IsMultisiteMode)
                {
                    cookieKey += SystemManager.CurrentContext.CurrentSite.Id;
                }

                HttpCookie shoppingCartCookie = HttpContext.Current.Request.Cookies[cookieKey];

                CartOrder cartOrder = null;
                if (shoppingCartCookie == null || !shoppingCartCookie.Value.IsGuid())
                {
                    // throw new ArgumentException("The shopping cart cookie does not exist or its value is not a valid string.");
                    cartOrder = ordersManager.CreateCartOrder();
                }
                else
                {
                    Guid cartOrderId = new Guid(shoppingCartCookie.Value);
                    cartOrder = ordersManager.GetCartOrder(cartOrderId);
                }

                if (cartOrder != null)
                {
                    PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(cartOrder);
                    PropertyDescriptor           property   = properties["DonationAmount"];

                    MetafieldPropertyDescriptor metaProperty = property as MetafieldPropertyDescriptor;

                    if (metaProperty != null)
                    {
                        metaProperty.SetValue(cartOrder, price);
                        ordersManager.SaveChanges();
                    }
                }

                this.AddedToCartMessage.ShowPositiveMessage("Donation added to cart");
            }
            catch (Exception ex)
            {
                this.AddedToCartMessage.ShowNegativeMessage("Failed to add donation to cart, try again");
            }
        }