View Single Post
  #1  
Old 05-13-2012, 11:25 AM
  ADDISON's Avatar 
ADDISON ADDISON is offline
 

X-Man
  
Join Date: Jan 2008
Posts: 2,613
 

Lightbulb How to change Add Date field for a Product

Hello Guys,

As you may know in table [xcart_products] there is a field named [add_date]. This is a very powerful field for customization of XC (mark a product as new, newest products, ...). Its value you see it is in UNIX date format (e.g. 2147483647 = Tue, 19 Jan 2038 03:14:07 +0000).

In the past many of you asked in this forum how to change this field in Admin -> Product page. Here is a solution for you free of charge checked and functioning in XC v4.5.0 (you can choose your new date with jQuery UI). By default for new products the date is set for today.

Step 1 - Here are the files we have to change:

- [XC-Dir]/include/product_modify.php
- [XC-Dir]/skin/common_files/main/products_details.tpl

product_modify.php

Search for the following string: // Update product data.

after:
Code:
$small_item = $small_item == 'Y' ? 'N' : 'Y';
add:
Code:
$add_date = func_prepare_search_date($add_date);

Search for the following string $query_data = array (

after:
Code:
'title_tag' => $title_tag,
add:
Code:
'add_date' => $add_date,

product_modify.tpl

Search for the following string $lng.lbl_availability. After this html table row for product availability (the one with html select) paste the following code:

Code:
<tr> <td class="FormButton" nowrap="nowrap">{$lng.lbl_add_date}:</td> <td class="ProductDetails"> {include file="main/datepicker.tpl" name="add_date" date=$product.add_date} </td> </tr>

Step 2 - New Label

We have to add a new label in languages. I have called this label "lbl_add_date" with value "Add Date". You can also execute the following query with phpMyAdmin or inside XC interface

PHP Code:
INSERT INTO `xcart_languages` (`code`, `name`, `value`, `topic`) VALUES('en','lbl_add_date','Add Date','Labels'); 

I have attached the files I modified v4.5.0. Please note to do a backup before replacement in their folders (rename your original files with extensions like .ph_ or .tp_).

As improvement I could change the behavior to see the sticky container coming (Apply button) after altering a value. For this I should create a new template called datapicker_p.tpl and leave only an input html tag in product_modify.tpl. Sticky container comes only if input/check boxes tags exists in product_modify.tpl. You can do it by your own, I can live without it.

Also "Mark a product as new" feature with a time configured in Appearance or just (Start - End) time in product modified page is a piece of cake based on this thread. Looking for volunteers.

In my humble opinion this easy customization should be done years before and being standard in all XC versions.
Attached Files
File Type: php product_modify.php (51.5 KB, 229 views)
File Type: tpl product_details.tpl (20.6 KB, 231 views)
__________________
X-Cart Next: Business 5.2 (learning and testing)
X-Cart Classic: Gold and Gold Plus 4.7
Lots of Modules and Customizations
OS in use: Red Hat Enterprise, Fedora, CentOS, Debian, Ubuntu, Linux Mint, Kali Linux
Ideas for Server configuration (basicaly): Nginx/Pound (reverse proxy), Apache/Nginx (webserver), Squid/Varnish (cache server), HHVM or (PHP-FPM + PHP 5.6 + opcache), MariaDB/Percona MySQL Server, Redis (storing sessions)

You can catch my ideas here: http://ideas.x-cart.com
Reply With Quote