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:
- 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
- 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
- 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>