R5 adding item to existing order causes 100% profit

For general questions and discussions specific to the AbleCommerce GOLD ASP.Net shopping cart software.
Post Reply
User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

R5 adding item to existing order causes 100% profit

Post by AbleMods » Tue Sep 03, 2013 1:51 pm

When adding an item to an existing order, the COGS field is not populated on the new line item. As a result, sales/profit reports are no longer accurate as the item added now reflects a 100% profit margin.

If you have full source code, the fix to resolve this issue can be made in the /Orders/OrderItemRepository.cs class file. Look for this code in the CreateForProduct() method:

Code: Select all

                 // CALCULATE THE PRICE OF THE PRODUCT
                ProductCalculator pcalc = ProductCalculator.LoadForProduct(productId, quantity, optionList, kitList);
                baseItem.Sku = pcalc.Sku;
                baseItem.Price = pcalc.Price;
                baseItem.Weight = pcalc.Weight;

                // CHECK PRODUCT VARIANT
                ProductVariant variant = productVarientRepo.LoadForOptionList(productId, optionList);
                if (variant != null)
                {
                    baseItem.OptionList = optionList;
                    baseItem.VariantName = variant.VariantName;
                }

                // CHECK FOR DIGITAL GOODS
And replace it with this code:

Code: Select all

                // CALCULATE THE PRICE OF THE PRODUCT
                ProductCalculator pcalc = ProductCalculator.LoadForProduct(productId, quantity, optionList, kitList);
                baseItem.Sku = pcalc.Sku;
                baseItem.Price = pcalc.Price;
                baseItem.Weight = pcalc.Weight;

                // BEGIN MOD: AbleMods.com
                // DATE:  08/26/2013
                // BugFix:  CostofGoods is never populated when directly building OrderItem object
                
                // CHECK PRODUCT VARIANT
                ProductVariant variant = productVarientRepo.LoadForOptionList(productId, optionList);
                if (variant != null)
                {
                    baseItem.OptionList = optionList;
                    baseItem.VariantName = variant.VariantName;
                    decimal? variantCOGS = variant.CostOfGoods;
                    if (variantCOGS != null && variantCOGS > 0)
                    {
                        baseItem.CostOfGoods = variantCOGS.Value;
                    }
                }

                // Set CostOfGoods to base product COGS if new OrderItem object CostofGoods is still zero
                // In other words, only set it if a variant above hasn't already established as COGS value
                if (baseItem.Product != null && baseItem.CostOfGoods == 0) baseItem.CostOfGoods = baseItem.Product.CostOfGoods;

                // END MOD: AbleMods.com

                // CHECK FOR DIGITAL GOODS
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: R5 adding item to existing order causes 100% profit

Post by AbleMods » Wed Sep 04, 2013 8:09 am

Repairing the data is also necessary since the above fix only resolves the problem going forward.

To update your SQL data, you can use this query against your database. The data can only be repaired if the item sold still exists in your catalog. This query only fixes COGS on regular products sold, not variants. Use at your own risk.

Code: Select all

update ac_OrderItems
	set CostOfGoods = p.costofgoods
	from ac_OrderItems oi 
	left outer join ac_products p on oi.productid = p.productid
	where oi.CostOfGoods = 0 and OrderItemTypeId = 0
		and p.CostOfGoods <> 0 and optionlist is null
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

User avatar
Katie
AbleCommerce Admin
AbleCommerce Admin
Posts: 2651
Joined: Tue Dec 02, 2003 1:54 am
Contact:

Re: R5 adding item to existing order causes 100% profit

Post by Katie » Wed Sep 04, 2013 8:32 am

Thanks so much for posting this bug and the fix. It would be great if you could let me know via the green Feedback button in Gold. I would sure feel bad if we missed a bug report. You can just reference the forum post, so it shouldn't take more than a few seconds to let us know.

Thanks again for all you do!
Katie
Thank you for choosing AbleCommerce!

http://help.ablecommerce.com - product support
http://wiki.ablecommerce.com - developer support

User avatar
Katie
AbleCommerce Admin
AbleCommerce Admin
Posts: 2651
Joined: Tue Dec 02, 2003 1:54 am
Contact:

Re: R5 adding item to existing order causes 100% profit

Post by Katie » Wed Sep 04, 2013 3:13 pm

This one is already reported, so my last comment applies only to future issues.
Thank you for choosing AbleCommerce!

http://help.ablecommerce.com - product support
http://wiki.ablecommerce.com - developer support

Post Reply