Page 1 of 1

Basket Pricing Calculation?

Posted: Tue Nov 12, 2013 3:10 pm
by chemistrudy
Hi All,

Could anyone shed some light on pricing calculations that are performed when an item is added to the cart? Running Gold R6, WSP.

We have some users with special pricing for certain product variants. They aren't a discount, from the users/customers perspective it is just the "price" (as you'll notice reading through my code snippet, they are stored in the db as percentages of the standard price). The out of the box special pricing doesn't work for us, because depending on the option/variant the user chooses, the price is different.

This has always been a little painful for us, but it is the way it is.

In any case, I have created a custom table with the special price rules in it. I can display the correct price on the product page, as I've added code to ConLib/Utility/ProductPrice.aspx to perform this. For anyone interested it is:

Code: Select all

//CUSTOMIZATION TO GET CUSTOMER SPECIAL PRICE AND DISPLAY IT WITHOUT SHOWING ANY KIND OF DISCOUNT  ENERCO RLO 11/11/13
                        //find the right vcId (CustomerNumber)
                        IList<CommerceBuilder.Users.UserSetting> usersetting;
                        usersetting = UserSettingDataSource.LoadForUser(AbleContext.Current.User.Id);
                        string vcId = "";
                        decimal myprice = 0;
                        foreach (UserSetting setting in usersetting)
                        {
                            if (setting.FieldName == "customer_number")
                            {
                                vcId = setting.FieldValue;
                            }
                        }
                        //Get the records from the database
                        if (vcId.IsNotNullOrEmpty())
                        {
                            string sql = "SELECT CustomerNumber, ProductOptionID, PriceModifier FROM ac_UserCustSpecialPrice_Enerco WHERE CustomerNumber = '";
                            sql = sql + vcId + "'";
                            IList result = NHibernateHelper.CreateSQLQuery(sql).List();

                            foreach (object[] dataRow in result)
                            {
                                //if a record matched, adjust the price.

                                if (_OptionList.IndexOf(dataRow[1].ToString()) != -1) //it matches!
                                {
                                    myprice = Math.Round(priceWithVAT * (1 + Convert.ToDecimal(dataRow[2].ToString())),0);
                                    Price.Text = string.Format(_PriceFormat, myprice.LSCurrencyFormat("ulc"));
                                }
                            }
                        }
                        //END CUSTOMIZATION
This works great for price display, just the way we want it to.
But, when the item is added to the basket, the standard price for the variant is used. I can't seem to find where the price is calculated when the item is added to the basket. Could someone point me in the right place?

Thanks in advance,

Rudy

P.S. I don't have Able's source code...maybe it is needed for this function...

Re: Basket Pricing Calculation?

Posted: Wed Nov 13, 2013 6:24 am
by jmestep
You can override Able's product/variant price calculation by overriding the default basket service. You would put your special basket calculations in a file that uses your service, then use your service instead of Able's.
Able provided this way to help in handling situations such as yours and I've used it a couple of times. It's pretty cool.
Here is info:
http://wiki.ablecommerce.com/index.php/ ... or_AC_Gold

Re: Basket Pricing Calculation?

Posted: Wed Nov 13, 2013 8:31 am
by chemistrudy
Judy!

You are an AbleCommerce Angel.

Of course I haven't done it yet, but this will work very nicely to meet my pricing need. As well as probably be useful in the future for some as of yet unknown need.

A million and one thanks for opening the door to this customization path.

Rudy