Add Product Cost Price Field In Backend

I needed to have a product “Cost Price” field added next to the Price and List Price fields in the products area of the CS-Cart admin (not displayed in the shop front end) so I could record the last cost price of a product.



I am using CS-Cart v4.1.2 and thanks to brandonvd I was able to do it in v2.2.5 however there has been no update for v4.1.2 so I have adapted Brandon’s tutorial for v4.1.2 and post it here to help others who may also want the same thing.



These changes will add an editable Cost field next to the Price field in the product list (Products → Products) and also add an editable Cost field when creating or editing a product.



[attachment=7808:1.jpg] [attachment=7809:2.jpg]



NOTES:

  1. This does include adding a couple of lines in a core CS-Cart file so if you update your CS-Cart version it will most probably overwrite the changes so you will need to reapply the changes again
  2. This has some limitations such as:

    a.) Not included in the field list of product data imports or exports

    b.) Doesn’t have separate cost field for product options

    c.) and possibly some other areas that I don’t have a need for personally so I haven’t looked where to apply other changes.



    Installation
  3. We need to first create a Cost field in the cscart_products table of our database. So copy the following code and in phpMyAdmin select your database and paste the code in the SQL area and run it. Check that a new field “cost” has been added to your cscart_products table after the product_code field.
ALTER TABLE `cscart_products` ADD `cost` DECIMAL (10,2) AFTER `product_code` ;
```<br />
<br />
2. Add a language entry for Cost in Administration -> Languages -> Translations. Add a new entry with these details:<br />
Language variable: cost<br />
Value: Cost<br />
<br />
3. This is where we add some lines into a core CS-Cart file.<br />
a.) Open the fn.catalog.php file located at \app\functions<br />
<br />
b.) Find<br />
```php
'products.company_id',
```<br />
and add after it<br />
```php
'products.cost',
```<br />
<br />
c.) Find<br />
```php
'price' => 'price',
```<br />
and add after it<br />
```php
'cost' => 'products.cost',
```<br />
<br />
d.) Find<br />
```php
		array(<br />
			'name' => '[data][price]',<br />
			'text' => __('price')<br />
		),
```<br />
and add after it<br />
```php
array(<br />
	'name' => '[data][cost]',<br />
	'text' => __('cost')<br />
),
```<br />
<br />
4. Open the manage.tpl template located at \design\backend\templates\views\products<br />
a.) Find<br />
```php
<th width="45%"><a class="cm-ajax" href="{"`$c_url`&sort_by=product&sort_order=`$search.sort_order_rev`"|fn_url}" data-ca-target-id={$rev}>{__("name")}
```<br />
and add after that<br />
```php
<th width="10%"><a class="cm-ajax" href="{"`$c_url`&sort_by=cost&sort_order=`$search.sort_order_rev`"|fn_url}" data-ca-target-id={$rev}>{__("cost")} ({$currencies.$primary_currency.symbol nofilter}){if $search.sort_by == "cost"}{$c_icon nofilter}{else}{$c_dummy nofilter}{/if}</a></th>
```<br />
<br />
b.) Find<br />
```php
<th width="15%"><a class="cm-ajax" href="{"`$c_url`&sort_by=price&sort_order=`$search.sort_order_rev`"|fn_url}" data-ca-target-id={$rev}>{__("price")}
```<br />
and change the 15% to 10%<br />
<br />
c.) Find<br />
```php
<th width="15%"><a class="cm-ajax" href="{"`$c_url`&sort_by=list_price&sort_order=`$search.sort_order_rev`"|fn_url}" data-ca-target-id={$rev}>
```<br />
and change the 15% to 10%<br />
<br />
d.) Find<br />
```php
{include file="views/companies/components/company_name.tpl" object=$product}<br />
</td>
```<br />
and add after that<br />
```php
<td><br />
	<input type="text" name="products_data[{$product.product_id}][cost]" size="6" value="{$product.cost}" class="input-mini input-hidden" /><br />
</td>
```<br />
<br />
5. Open the update.tpl template located at \design\backend\templates\views\products<br />
There are 2 options that you may like to use here. The first option places the Cost field above the List Price field in the Pricing/Inventory section of the product entry/edit page, as in the screen shot above. Option 2 places the Cost field above the Price field and moves the List Price field below the Price field keeping all the prices together as in this screen shot:<br />
[attachment=7810:3.jpg]<br />
<br />
[b]OPTION 1[/b]<br />
a.) Find<br />
```php
<div class="control-group"><br />
	<label class="control-label" for="elm_product_code">{__("sku")}:</label><br />
	<div class="controls"><br />
		<input type="text" name="product_data[product_code]" id="elm_product_code" size="20" maxlength="32"  value="{$product_data.product_code}" class="input-long" /><br />
	</div><br />
</div>
```<br />
and add after that<br />
```php
<div class="control-group"><br />
	<label class="control-label" for="elm_cost">{__("cost")} ({$currencies.$primary_currency.symbol nofilter}):</label><br />
	<div class="controls"><br />
		<input type="text" name="product_data[cost]" id="elm_cost" size="10" value="{$product_data.cost|default:"0.00"}" class="input-long" /><br />
	</div><br />
</div>
```<br />
<br />
[b]OPTION 2[/b]<br />
a.) Find<br />
```php
<div class="control-group {$no_hide_input_if_shared_product}"><br />
	<label for="elm_price_price" class="control-label cm-required">{__("price")} ({$currencies.$primary_currency.symbol nofilter}):</label><br />
	<div class="controls"><br />
		<input type="text" name="product_data[price]" id="elm_price_price" size="10" value="{$product_data.price|default:"0.00"|fn_format_price:$primary_currency:null:false}" class="input-long" /><br />
		{include file="buttons/update_for_all.tpl" display=$show_update_for_all object_id='price' name="update_all_vendors[price]"}<br />
	</div><br />
</div>
```<br />
and add BEFORE that<br />
```php
<div class="control-group"><br />
	<label class="control-label" for="elm_cost">{__("cost")} ({$currencies.$primary_currency.symbol nofilter}):</label><br />
	<div class="controls"><br />
		<input type="text" name="product_data[cost]" id="elm_cost" size="10" value="{$product_data.cost|default:"0.00"}" class="input-long" /><br />
	</div><br />
</div>
```<br />
<br />
b.) Find<br />
```php
<div class="control-group"><br />
	<label class="control-label" for="elm_list_price">{__("list_price")} ({$currencies.$primary_currency.symbol nofilter}) :</label><br />
	<div class="controls"><br />
		<input type="text" name="product_data[list_price]" id="elm_list_price" size="10" value="{$product_data.list_price|default:"0.00"}" class="input-long" /><br />
	</div><br />
</div>
```<br />
Cut that code out and paste it in after<br />
```php
<div class="control-group {$no_hide_input_if_shared_product}"><br />
	<label for="elm_price_price" class="control-label cm-required">{__("price")} ({$currencies.$primary_currency.symbol nofilter}):</label><br />
	<div class="controls"><br />
		<input type="text" name="product_data[price]" id="elm_price_price" size="10" value="{$product_data.price|default:"0.00"|fn_format_price:$primary_currency:null:false}" class="input-long" /><br />
		{include file="buttons/update_for_all.tpl" display=$show_update_for_all object_id='price' name="update_all_vendors[price]"}<br />
	</div><br />
</div>
```<br />
<br />
6. That's it...please test to make sure it is working ok<br />
<br />
Hope you find this helpful and I encourage others to make their solutions available to everyone else<p><a href="127.0.0.1/uploads/monthly_03_2014/post-9081-0-38242000-1394053708.jpg">2.jpg</a></p><p><a href="127.0.0.1/uploads/monthly_03_2014/post-9081-0-49505600-1394053707.jpg">1.jpg</a></p><p><a href="127.0.0.1/uploads/monthly_03_2014/post-9081-0-93676900-1394057031.jpg">3.jpg</a></p>

Hi



For those who cant do this we have a ready made addon that has also some extra features like margin calculation and import/export cost via csv



Find more at [url=“Τιμή Προμηθευτή και Κέρδος - CS-Cart Addons/Πρόσθετα at Cscart.Biz | CS-Cart Market by Dvs.gr”]http://www.cscart.biz/product-286.html[/url]



Fotis

WOW, 65 Euro, that's $100 Australian…a bit steep in price there mate but thanks anyway

Hi there Ian



It is a fairly complex Addon .

You got import and export via csv but most of all on the fly calculation of profit margin in the product screen(via Ajax)



Have a look here https://www.youtube…e2g4mZv4sw#t=71



Fotis

Thanks for the tutorial - I don’t like touching the core files, so I modified the 2 tpl files and made a custom add-on to load them. Is there a way to avoid touching the core [color=#282828][font=arial, verdana, tahoma, sans-serif]fn.catalog.php?[/font][/color]



[color=#282828][font=arial, verdana, tahoma, sans-serif]I’m still very new at CS-Cart - but appreciate the user contributions![/font][/color]



[color=#282828][font=arial, verdana, tahoma, sans-serif]I’ve attached my mods and notes… hopefully one of you smart guys out there can take the ball the rest of the way across the line for me / us :-)[/font][/color]



[attachment=7859:COGS add-on.zip]

COGS add-on.zip

The fn.catalog.php is the main tool used to get the data from the database to the template files and then save the cost data back into the database. Sorry but I can't help with bypassing this as I am not a developer as such. I personally don't have an issue with it as they are small changes and I just reinsert the changes after any CS-Cart updates

Hi DVS I purchased the addon it shows failed. Payment went through order #700

Hi Gizmo



I already took action, email me at info@dvs.gr

hi lan,



can i use this way to add a new filed for UPC / EAN code?



Thank,



Jack

i did it.

it shows a filed for UPC but i met two problem.

  1. the code i insert shows in currency format.
  2. the field does not show up in the front sotre



    Really appreciate your help on this.



    Sincerely,



    Jack

Hi,

Would it be easier to use the Features Tab. You can put the UPC or EAN Code there

Hi Fotis -



Does your margin addon support Option Variant Modifiers? For instance, XXXL shirt costs $2 more for the consumer but supplier price $1 more.



thanks,

Glen


[quote name='dvsgr' timestamp='1395617081' post='179958']

Hi there Ian



It is a fairly complex Addon .

You got import and export via csv but most of all on the fly calculation of profit margin in the product screen(via Ajax)



Have a look here https://www.youtube…e2g4mZv4sw#t=71



Fotis

[/quote]

Hi Glen



No we don't support that, I but I can Customize this for you.



Just pm me a detailed description on how you want this to work.





Fotis

[quote name='vivophone' timestamp='1404364328' post='186873']

Hi,

Would it be easier to use the Features Tab. You can put the UPC or EAN Code there

[/quote]



thanks for the tip.



if i use the feature, it will kill more time when i do bulk uploading… that is why i want to get column for the UPC and other by adding a new field.

[quote name='londonman' timestamp='1404371547' post='186885']

thanks for the tip.



if i use the feature, it will kill more time when i do bulk uploading… that is why i want to get column for the UPC and other by adding a new field.

[/quote]



Hi londoman



if you want to insert another code we have this addon http://www.cscart.bi…routz-mpn.html It works exaclty as the SKU (searchable, mass import/export) and is shows up in the client product screen.



Is this something for you?



Fotis

Note: This seems to work ok for v4.2.1

Does anybody know how to get this to work for v 4.3.1?



The code:

'products.company_id',



Does not exist in fn.catalog.php

I have a fully working module that adds Incoming price column in backend. It allows you to import-export this value…

Working with: 4.1.x-4.3.x

This really should be implemented by CS-Cart a long time ago. Im amazed we need add ons for such a basic shopping cart feature.



Please vote for it here:

http://cscart.uservoice.com/forums/134344-cs-cart/suggestions/561057-ability-for-profit-calculation-and-reports-on-sale

I have a fully working module that adds Incoming price column in backend. It allows you to import-export this value...
Working with: 4.1.x-4.3.x

Why in the world would you post this and not provide info on how to get the module?