Displaying the cost instead of the price in the PDF Invoice

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
I have a question about customizing the PDF Invoice.  
When you add a product to your store, nopcommerce has a place for you to enter the cost of the product (the amount you have to pay for the product.) as well as the price of the product (the amount you charge your customer).  
I want to be able to display the cost of each of the products instead of the price in my customized version of the PDF Invoice.  

In the PdfService.cs of nopcommerce it has the following code:

//////////////////////////////////////////////////////////////////////////////////////////////////////

                    //price
                    string unitPrice = string.Empty;
                    switch (order.CustomerTaxDisplayType)
                    {
                        case TaxDisplayType.ExcludingTax:
                            {
                                var opvUnitPriceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderProductVariant.UnitPriceExclTax, order.CurrencyRate);
                                unitPrice = _priceFormatter.FormatPrice(opvUnitPriceExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, lang, false);
                            }
                            break;
                        case TaxDisplayType.IncludingTax:
                            {
                                var opvUnitPriceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderProductVariant.UnitPriceInclTax, order.CurrencyRate);
                                unitPrice = _priceFormatter.FormatPrice(opvUnitPriceInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, lang, true);
                            }
                            break;
                    }
                    cell = new PdfPCell(new Phrase(unitPrice, font));
                    cell.HorizontalAlignment = Element.ALIGN_LEFT;
                    productsTable.AddCell(cell);


/////////////////////////////////////////////////////////////////////////////////////////////////////

Is there any way that I can reference the unit cost instead of the unit price?  “orderProductVariant.UnitPriceExclTax” seems to be referencing the price without tax, how would I replace this to reference the cost without tax?  Also, is there I way that I can find the total cost that the order is to me instead of the total price that I am charging my customer?  I am using version 2.4 of nopcommerce. Thanks in advance!
12 years ago
orderProductVariant.UnitPriceExclTax and UnitPriceInclTax are going to have already accounted for a lot of stuff like Discounts.

You're probably better off changing that line to something like orderProductVariant.ProductVariant.ProductCost
12 years ago
Thank you so much! I tried changing the code like you said and now on my customized PDF Invoice under the price column it displays the cost instead of the price!
There is one more thing that I need to figure out.  Under the Total column in the PDF Invoice where it takes into account the quantity the total is based off of the price instead of the cost. Also, I will need to change the sub-total.  Is there a similar approach to doing this as well?
It looks like the total column is base off of the "orderProductVariant.PriceExclTax"
Thanks in advance!
12 years ago
Yeah, it's probably using the Order's SubTotal and TotalCost fields which add up shipping, discounts, tax, etc.  You can probably just run a sum of ProductCost and update it in your loop.  In that case your SubTotal and Total would always be the same.

Why are you using Cost instead of Price, though?
12 years ago
Thanks for getting back to me!
I have copied the code for the PDF invoice so now I have the regular PDF invoice and my customized invoice both accessible through the administration panel.
The reason I want to have the customized invoice display the cost instead of the price is because I will be drop shipping. The regular PDF invoice will be for my costumer’s order.  The cost based PDF invoice will be for my order that I give to the company I am selling products from. Ideally, I will want to find the total cost and retain the shipping cost in the PDF, but not retain the tax because I am in a different state then the company I am working with.
I understand the general idea of what you are saying to do. However, I am not really a programmer so I don’t really know that much, but I am willing to learn.  If I were to make a loop that found the sum of the cost of the products could I add the shipping to that sum? Is the shipping held in a variable like the cost of the product was? I really appreciate your responses. Thanks again!
12 years ago
Yes, you can get shipping from the Order object.

OrderShippingInclTax
OrderShippingExclTax


To get the total cost for an order you could just do:


decimal totalCost = 0.0m;

foreach(OrderProductVariant opv in Order.OrderProductVariants)
{
    totalCost += opv.ProductVariant.ProductCost * opv.Quantity;
}
12 years ago
You have been a great help to me.  I really appreciate you taking the time to explain how to do this. It looks like everything is working out except one thing. I get an error on the “Order.OrderProductVariants” in the foreach loop. It says, “An object reference is required for the non-static field, method, or property ‘Nop.Core.Domain.Orders.Order.OrderProductVariants.get’.  I am working in the Express edition.  Do I need a reference somewhere or am I not putting the code in the right place? Thanks!
12 years ago
Sorry, I shouldn't have capitalized the O in Order.  It's trying to reference the Order class instead of the individual order that you are working on.

Should be:


decimal totalCost = 0.0m;

foreach(OrderProductVariant opv in order.OrderProductVariants)
{
    totalCost += opv.ProductVariant.ProductCost * opv.Quantity;
}
12 years ago
Thanks!  

It works. Now it correctly calculates the sub-total based on the cost.

I really appreciate the time you have taken to help me. Thanks again!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.