Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

What's New can you alter it?


Duke1974

Recommended Posts

Posted

Hey there,

 

I was wondering is there a way to alter the what's new section on the front page to also have a few items placed on there permantly?

 

I just want to have a few items on the front page to stay there so that visitors to the site will see them as soon as they go to the page.

Posted
Hey there,

 

I was wondering is there a way to alter the what's new section on the front page to also have a few items placed on there permantly?

 

I just want to have a few items on the front page to stay there so that visitors to the site will see them as soon as they go to the page.

 

By default, the What's New box displays items with the most recent products_date_added value.

 

I made a hack in perl to change this date value for selected items in order to make sure that the What's New box would display them. Of course, as soon as you add new products, they will take over as the latest, so my hack has to be run again after each product addition. If you add new products often, then you'd probably want to automate the hack. I include the code below.

 

There is probably a better way, such as replacing the What's New box with some kind of Featured Items box but I was too lazy/in too big a hurry to look around for such a thing. You may want to look through the contributions.

 

 

Note that this hack uses a field which I added to my store. If you want to use this, you'd need to change that product_item_code to a unique field in your products table.

 

It also assumes the presence of a directory for storing a text file which stores the choices. Note also that the paths are set for a Mac OS X default webserver location on the filesystem.

 

There may be other stuff you need to tweak and some of those perl modules may need to be installed.

 

#!/usr/bin/perl -w
print "Content-type: text/html\n\n";

use strict;

use DBI;
use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser);
use DBD::mysql;
use Data::Dumper;
use LWP::Simple qw($ua get getstore);
use DateTime::Format::MySQL;
#################################################
# globals
#################################################
my $q = new CGI;	# create new CGI object

my $uploadDir = '../Documents/uploads/';
my $configFile = $uploadDir . '10Codes.txt';

my $user = "MYSQLUSERNAME";
my $pass = "MYSQLPASSWORD";

my $dsn2 = "DBI:mysql:host=HOSTNAME;database=oscommerce";  
my $dbh2 = DBI->connect ($dsn2, $user, $pass)				  
or die "Cannot connect to server\n";

my $uploadPath = "/Library/WebServer/Documents/uploads/";

#  paths
my $imagePath = "/Library/WebServer/Documents/catalog/images/products/";
my $serverImagePath = "/catalog/images/products/"; # relative to doc root

#################################################
# main
#################################################

$| = 1;

my $then = time;
my @list = &getCurrentList();
my $val;
my @outList;
&printHead();

my $submit =  $q->param('submit');  

if (! $q->param){

&displayGUI(@list);

&printFoot(); # finishes with an exit;

}

# submit button pressed?
if ($submit){  

#if search button pressed
if ($submit =~ /Show These/){

	my @values = split(/&/,$ENV{QUERY_STRING});

	for (my $i=0; $i < 10; $i++){

		$val = $values[$i];
		$val =~  s/txt\d=//;
		print "$val <br>  ";
		push @outList,$val;
	}

	if(@outList){

		&updateDB(@outList);
		&updateConfigFile(@outList);
	}
}
&printFoot(); # finishes with an exit; 
}

#################################################
# subroutines
#################################################
sub printHead(){

print"<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>";
print "<html>\n<head>\n<title>U p d a t e :::: the store!</title>";
print "\n<link rel='stylesheet' type='text/css' href=../catalog/stylesheet.css>\n";
print "</head>\n<body style='margin: 28px; A color=#990033' >\n";
}


sub printFoot(){

my $now = time;

my $difference = $now - $then;

my $seconds	=  $difference % 60;
 $difference = ($difference - $seconds) / 60;
my $minutes	=  $difference % 60;
 $difference = ($difference - $minutes) / 60;
my $hours	  =  $difference % 24;

print"<p> elapsed time: $hours:$minutes:$seconds";
print"<br><a href='pick10.cgi'>Reload the Pick 10 Form</a>";
print"<hr><br><a href='/admin/update/up2.php'> Uploady doohickey</a>";
 print"</body></html>";
exit;
}

# reads a text file and returns an array of product_item_codes in the file 
sub getCurrentList(){

my @lines;

my $buffer;

print "opening: $configFile \n" if $verbose;

open(IN, $configFile) || die "cannot open $configFile for reading: $!";

# read file into a string
while (<IN>) {
   $buffer .= $_;
}

close(IN) || die "cannot close $configFile: $!";

# replace bad line-breaks 
$buffer =~ s/\r/\n/g;

# split the buffer into an array
@lines = split /^/m, $buffer;

return @lines;
}  

sub displayGUI(){
my @list = @_;
my $fieldName;
my $val;
print "Replace any or all of these items for the store's front page";
print "<br>vendor catalog codes only please.";
print "<br><form action='pick10.cgi'>";


for (my $i=0; $i < 10; $i++){
$fieldName = "txt$i";
$val = $_[$i];
print "<br><input type='text' name=$fieldName value=$val > ";

  }

print"<input type='submit' name='submit' value='Show These Ten Items'></form>";

}
# compile a list of prod code, artist, title
# send list to a tabbed file for image searching, choosing and dbing
sub updateConfigFile() {
my @insertList = @_;

open(FILE,">$configFile")
	or  die "cannot open $configFile for writing: $!";

  		   # step through the list inserting needed fields into a text file	
foreach (@insertList) {

  		print FILE "$_\n";

}

close(FILE);
}

sub updateDB(){
my @insertList = @_;

my $table = 'products';
my $keyColumn = 'products_item_code';
my $i = 0;

my ($sec,$min,$hour,$mday,$mon,$year,$wday,
	$yday,$isdst)=localtime(time);
my $yyyy_mm_dd = sprintf( "%4d-%02d-%02d", $year+1900,$mon+1,$mday );
my $hms = sprintf( "%02d:%02d:%02d", $hour,$min,$sec );

my $MySQLTime = "$yyyy_mm_dd $hms";

my $dt = DateTime::Format::MySQL->parse_datetime( $MySQLTime);

my $queryString ="UPDATE $table \
				 SET  products_date_added = ?
				 WHERE $keyColumn=?";

my $sth = $dbh2->prepare($queryString)
or die "Couldn't prepare statement: " . $dbh2->errstr;	 

foreach(@insertList) {

$sth->execute(
		  $dt, 
		  $_[$i],  # products_item_code
						)
	or die "Couldn't execute statement: " . $sth->errstr;   

   $i++;
}
  print "ok then ... updated $i store record(s) - $dt<p>";
}

Posted

oh wow thats fantastic!

 

I'll give it a shot this afternoon and see how it works out

 

Thanks so much!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...