Kryptronic Software Support Forum

You are viewing this forum as a guest. Login to an existing account, or create a new account, to reply to topics and to create new topics.

#1 08-28-2004 00:59:53

Steven
Member
Registered: 04-21-2004
Posts: 84

Link And Truncated Item Description On Main Page

I know best sellers are displayed on (CGIVAR)common_url(/CGIVAR)&pg=bestsell and specials are on (CGIVAR)common_url(/CGIVAR)&pg=specials

I want to keep those two pages intact...

What I also want to do is have down the right hand side of my website on ste_layout a dynamic listing of say the first 3 of each in those categories to be displayed like this

##BEST SELLERS##


Designed for the serious business
user, we have created the perfect
PC for the working...


Designed for the serious business
user, we have created the perfect
PC for the working...


Designed for the serious business
user, we have created the perfect
PC for the working...

with the titles being linked to the product, and the description pulled, and truncated to say 50 characters

I know the truncation code would be..

Code:

$html_desc_text = vars_truncate($html_desc_text,'150');

Offline

 

#2 08-28-2004 06:27:51

Steven
Member
Registered: 04-21-2004
Posts: 84

Re: Link And Truncated Item Description On Main Page

I can't believe I worked this out by myself.  CCP is a huge learning curve..

Add the following to the top of your ste_prod.pl

Code:

#######################################################################
# Ste Prod bestDisp                                                    #
#######################################################################

sub ste_prod_bestdisp {

&initialize_sub_add('ste_prod_bestdisp');

#########
######### Because different SQL engines have different syntaxes
######### for the LIMIT string, we need to use next/previous
######### links only for those that support the syntax.
#########

my $sql_limit_string = "";

if ($tables_data_source{'product'} eq "CSV") {

$sql_limit_string = "$csv_limit_syntax";

} elsif ($tables_data_source{'product'} eq "ALT") {

$sql_limit_string = "$alt_limit_syntax";

} ######### End of if statement.

$fd_startrow = "0";

if ($sql_limit_string ne "") {

$sql_limit_string =~ s/start/$fd_startrow/gs;
$sql_limit_string =~ s/rows/$store_products_to_display_per_page/gs;

} ######### End of if statement.

#########
######### Because different SQL engines have different syntaxes
######### for the TOP string, we need to enforce limits on the 
######### views we present in different ways.
#########

my $sql_top_string = "";
my $sql_select_string = "";

if ($tables_data_source{'product'} eq "CSV") {

$sql_top_string = "$csv_top_syntax";

} elsif ($tables_data_source{'product'} eq "ALT") {

$sql_top_string = "$alt_top_syntax";

} ######### End of if statement.

if ($sql_top_string ne "") {

$sql_top_string =~ s/rows/$store_products_to_display_per_page/gs;
$sql_top_string =~ s/table/product/gs;

} ######### End of if statement.

if ($sql_top_string eq "") {

$sql_select_string = "SELECT columns FROM product";

} else {

$sql_select_string = "$sql_top_string";

} ######### End of if statement.

#########
######### Build the column line.
#########

$column_line = "product_id,product_name,product_desclong";

#########
######### Insert the column string into our SQL SELECT string and
######### create the SQL statement.
#########

$sql_select_string =~ s/columns/$column_line/gs;

$sql_statement = "

$sql_select_string
WHERE product_bestsell='Y'
ORDER BY RAND()
LIMIT 4

";

#########
######### Handle the results.
#########

@bestdisp = database_call('product','SELECT',$sql_statement);

foreach $row(@bestdisp) {

($product_id,$product_name,$product_desclong) = @$row;

$product_id_encoded = vars_urlencode($product_id);

print "<b><A HREF=\"$common_url&pg=prod&ref=$product_id_encoded\">";

&ste_prod_show_desc($product_name);

print "</A></b>";



$prod_desc_truntext = "$product_desclong";
$prod_desc_truntext =~ s/<[^>]*.//gs;

$prod_desc_truntext = vars_truncate($product_desclong,'60');

&ste_prod_show_desc($prod_desc_truntext);


} ######### End of foreach statement.

&initialize_sub_remove('ste_prod_bestdisp');

} ######### End of subroutine.

Call this from ste_layout.txt using

Code:

(CGIGET TYPE="SUB" VALUE="ste_prod_bestdisp")

This code picks 4 random products from the best sellers page and displays them where ever the above tag is used.  The title of the product is linked and the product desciption, truncated to 60 characters is also displayed underneath the title.

I'm trying to close the gap (space) between the title and the description.  Anyone know how to do this?

Steven

Offline

 

#3 08-28-2004 09:43:26

superhero2000
Member
From: Harrisburg, PA
Registered: 03-26-2003
Posts: 1025
Website

Re: Link And Truncated Item Description On Main Page

Steven,

I tried implementing the above code you posted and nothing displays.  This is what I get when I look at the source code of the webpage:

<!-- DISPLAY ERROR: SUBROUTINE ste_prod_bestdisp GENERATED MESSAGE: DBD::AnyData::st fetchall_arrayref failed: Attempt to fetch row from a Non-SELECT statement at /home/leafofev/public_html/cgi-bin/store/library/common/database.pl line 626.

SELECT product_id,product_name,product_desclong FROM product
WHERE product_bestsell='Y'
ORDER BY RAND()
LIMIT 4

-->

Any ideas?


Vinh
VQC Designs, LLC


Offline

 

#4 08-28-2004 17:16:14

Steven
Member
Registered: 04-21-2004
Posts: 84

Re: Link And Truncated Item Description On Main Page

Superhero,

Are you using CSV or MySQL? .. I'm pretty sure that MySQL is required for this to work.  Sorry that I forgot to mention. 

Steven

Offline

 

#5 09-09-2004 10:48:57

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19798
Website

Re: Link And Truncated Item Description On Main Page

Correct, RAND only works for MySQL - it's not implemented in the CSV driver (see pod on DBD::AnyData for more info).


Nick Hendler

Offline

 

#6 09-09-2004 12:30:21

theblade24
Member
From: Tampa, Florida
Registered: 11-19-2003
Posts: 384
Website

Re: Link And Truncated Item Description On Main Page

Try replacing this:

#########
######### Handle the results.
#########

@bestdisp = database_call('product','SELECT',$sql_statement);

foreach $row(@bestdisp) {

($product_id,$product_name,$product_desclong) = @$row;

$product_id_encoded = vars_urlencode($product_id);

print "<b><A HREF=\"$common_url&pg=prod&ref=$product_id_encoded\">";

&ste_prod_show_desc($product_name);

print "</A></b>";



$prod_desc_truntext = "$product_desclong";
$prod_desc_truntext =~ s/<[^>]*.//gs;

$prod_desc_truntext = vars_truncate($product_desclong,'60');

&ste_prod_show_desc($prod_desc_truntext);


} ######### End of foreach statement.

&initialize_sub_remove('ste_prod_bestdisp');

} ######### End of subroutine.

With this:

#########
######### Handle the results.
#########

@bestdisp = database_call('product','SELECT',$sql_statement);

foreach $row(@bestdisp) {

($product_id,$product_name,$product_desclong) = @$row;

$product_id_encoded = vars_urlencode($product_id);

print "<br><b><A HREF=\"$common_url&pg=prod&ref=$product_id_encoded\">$product_name</a></b>";

$prod_desc_truntext = "$product_desclong";
$prod_desc_truntext =~ s/<[^>]*.//gs;

$prod_desc_truntext = vars_truncate($product_desclong,'60');

&ste_prod_show_desc($prod_desc_truntext);

} ######### End of foreach statement.

&initialize_sub_remove('ste_prod_bestdisp');

} ######### End of subroutine.


CCP 5.1
CCP 5.1
CCP 5.1

Offline

 

#7 07-31-2005 02:39:36

MajorD
Member
Registered: 06-20-2005
Posts: 10
Website

Re: Link And Truncated Item Description On Main Page

Thanks for the inspirational code.

I've taken Steven's code 1 step farther on my customer's site so that the code will display the following:

-Randomly grab 1 product from Best Sellers  1 product from New Items.
-Also display the large image associated with the product.
-Make the large image a clickable link to the product detail page.



Call the random New Items product by using this variable:
(CGIGET TYPE="SUB" VALUE="ste_prod_newdisp")


Call the random Best Seller product by using this variable: 
(CGIGET TYPE="SUB" VALUE="ste_prod_bestdisp")


Be advised:my customer's product images reside in their own directory (for different reasons), so I hard coded the image path - you will need to change this.


Code:

#######################################################################
# Ste Prod bestDisp  - displays 1 random Best Seller on Splash Page   #
#######################################################################

sub ste_prod_bestdisp {

&initialize_sub_add('ste_prod_bestdisp');

#########
######### Because different SQL engines have different syntaxes
######### for the LIMIT string, we need to use next/previous
######### links only for those that support the syntax.
#########

my $sql_limit_string = "";

if ($tables_data_source{'product'} eq "CSV") {

$sql_limit_string = "$csv_limit_syntax";

} elsif ($tables_data_source{'product'} eq "ALT") {

$sql_limit_string = "$alt_limit_syntax";

} ######### End of if statement.

$fd_startrow = "0";

if ($sql_limit_string ne "") {

$sql_limit_string =~ s/start/$fd_startrow/gs;
$sql_limit_string =~ s/rows/$store_products_to_display_per_page/gs;

} ######### End of if statement.

#########
######### Because different SQL engines have different syntaxes
######### for the TOP string, we need to enforce limits on the
######### views we present in different ways.
#########

my $sql_top_string = "";
my $sql_select_string = "";

if ($tables_data_source{'product'} eq "CSV") {

$sql_top_string = "$csv_top_syntax";

} elsif ($tables_data_source{'product'} eq "ALT") {

$sql_top_string = "$alt_top_syntax";

} ######### End of if statement.

if ($sql_top_string ne "") {

$sql_top_string =~ s/rows/$store_products_to_display_per_page/gs;
$sql_top_string =~ s/table/product/gs;

} ######### End of if statement.

if ($sql_top_string eq "") {

$sql_select_string = "SELECT columns FROM product";

} else {

$sql_select_string = "$sql_top_string";

} ######### End of if statement.

#########
######### Build the column line.
#########

$column_line = "product_imglg,product_id,product_name,product_desclong";

#########
######### Insert the column string into our SQL SELECT string and
######### create the SQL statement.
#########

$sql_select_string =~ s/columns/$column_line/gs;

$sql_statement = "

$sql_select_string
WHERE product_bestsell='Y'
ORDER BY RAND()
LIMIT 1

";

#########
######### Handle the results.
#########

@bestdisp = database_call('product','SELECT',$sql_statement);

foreach $row(@bestdisp) {

($product_imglg,$product_id,$product_name,$product_desclong) = @$row;

$product_id_encoded = vars_urlencode($product_id);
print "<b><A HREF=\"$common_url&pg=prod&ref=$product_id_encoded\">";
print "<IMG SRC=\"http://www.DOMAINNAME.com/images/$product_imglg\" WIDTH=\"\" BORDER=\"0\">";
print "</A>";


print "<A HREF=\"$common_url&pg=prod&ref=$product_id_encoded\">";

&ste_prod_show_desc($product_name);

print "</A></b>";



$prod_desc_truntext = "$product_desclong";
$prod_desc_truntext =~ s/<[^>]*.//gs;

$prod_desc_truntext = vars_truncate($product_desclong,'60');

&ste_prod_show_desc($prod_desc_truntext);


} ######### End of foreach statement.

&initialize_sub_remove('ste_prod_bestdisp');

} ######### End of subroutine.


#######################################################################
# Ste Prod newDisp  - displays 1 random New Item on Splash Page       #
#######################################################################

sub ste_prod_newdisp {

&initialize_sub_add('ste_prod_newdisp');

#########
######### Because different SQL engines have different syntaxes
######### for the LIMIT string, we need to use next/previous
######### links only for those that support the syntax.
#########

my $sql_limit_string = "";

if ($tables_data_source{'product'} eq "CSV") {

$sql_limit_string = "$csv_limit_syntax";

} elsif ($tables_data_source{'product'} eq "ALT") {

$sql_limit_string = "$alt_limit_syntax";

} ######### End of if statement.

$fd_startrow = "0";

if ($sql_limit_string ne "") {

$sql_limit_string =~ s/start/$fd_startrow/gs;
$sql_limit_string =~ s/rows/$store_products_to_display_per_page/gs;

} ######### End of if statement.

#########
######### Because different SQL engines have different syntaxes
######### for the TOP string, we need to enforce limits on the
######### views we present in different ways.
#########

my $sql_top_string = "";
my $sql_select_string = "";

if ($tables_data_source{'product'} eq "CSV") {

$sql_top_string = "$csv_top_syntax";

} elsif ($tables_data_source{'product'} eq "ALT") {

$sql_top_string = "$alt_top_syntax";

} ######### End of if statement.

if ($sql_top_string ne "") {

$sql_top_string =~ s/rows/$store_products_to_display_per_page/gs;
$sql_top_string =~ s/table/product/gs;

} ######### End of if statement.

if ($sql_top_string eq "") {

$sql_select_string = "SELECT columns FROM product";

} else {

$sql_select_string = "$sql_top_string";

} ######### End of if statement.

#########
######### Build the column line.
#########

$column_line = "product_imglg,product_id,product_name,product_desclong";

#########
######### Insert the column string into our SQL SELECT string and
######### create the SQL statement.
#########

$sql_select_string =~ s/columns/$column_line/gs;

$sql_statement = "

$sql_select_string
WHERE product_new='Y'
ORDER BY RAND()
LIMIT 1

";

#########
######### Handle the results.
#########

@newdisp = database_call('product','SELECT',$sql_statement);

foreach $row(@newdisp) {

($product_imglg,$product_id,$product_name,$product_desclong) = @$row;

print "<IMG SRC=\"http://www.DOMAINNAME.com/images/$product_imglg\" WIDTH=\"\" BORDER=\"0\">";

$product_id_encoded = vars_urlencode($product_id);

print "<b><A HREF=\"$common_url&pg=prod&ref=$product_id_encoded\">";

&ste_prod_show_desc($product_name);

print "</A></b>";



$prod_desc_truntext = "$product_desclong";
$prod_desc_truntext =~ s/<[^>]*.//gs;

$prod_desc_truntext = vars_truncate($product_desclong,'60');

&ste_prod_show_desc($prod_desc_truntext);


} ######### End of foreach statement.

&initialize_sub_remove('ste_prod_newdisp');

} ######### End of subroutine.

Offline

 

#8 12-08-2008 14:39:20

about2flip
Member
Registered: 02-09-2002
Posts: 125

Re: Link And Truncated Item Description On Main Page

I know this is an old old post, but I can't get this to work. It is not displaying anything. I followed the code exactly and placed the (CGIGET TYPE="SUB" VALUE="ste_prod_bestdisp") in a table of my ste_layout.txt

Any help would be great. Thanks

Offline

 

#9 12-08-2008 14:58:46

rachaelseven
Member
From: Massachusetts, USA
Registered: 01-23-2006
Posts: 3169
Website

Re: Link And Truncated Item Description On Main Page

Do a view source on the resulting page and see if there are any errors shown.  They'll be displayed as HTML comments in the source code and might give us a clue toward the problem.  Otherwise, reverse engineering and debugging unsupported code, without any idea what the problem is, would be beyond the scope of the forum.


Rachael Katz
- Custom Focusing Screens for DSLR Cameras

Offline

 

#10 12-08-2008 19:42:32

about2flip
Member
Registered: 02-09-2002
Posts: 125

Re: Link And Truncated Item Description On Main Page

This is what I get...

<!-- DISPLAY ERROR: SUBROUTINE ste_prod_bestdisp GENERATED MESSAGE: DBD::AnyData::st fetchall_arrayref failed: Attempt to fetch row from a Non-SELECT statement at /var/www/vhosts/flowersbymarlo.com/cgi-bin/library/common/database.pl line 624.



SELECT product_imglg,product_id,product_name,product_desclong FROM product
WHERE product_bestsell='Y'
ORDER BY RAND()
LIMIT 3

Offline

 

#11 12-08-2008 21:20:34

rachaelseven
Member
From: Massachusetts, USA
Registered: 01-23-2006
Posts: 3169
Website

Re: Link And Truncated Item Description On Main Page

The answer is about half a dozen posts up in this very thread:

https://forum.kryptronic.com/viewtopic. … 910#p38910


Rachael Katz
- Custom Focusing Screens for DSLR Cameras

Offline

 

#12 12-08-2008 22:05:17

about2flip
Member
Registered: 02-09-2002
Posts: 125

Re: Link And Truncated Item Description On Main Page

I know, I tried the above. Can u tell me what they meant by this?

it's not implemented in the CSV driver (see pod on DBD::AnyData for more info)

Is there another way to display best sellers in the ste_layout?

Thanks Again

Offline

 

#13 12-08-2008 23:11:26

rachaelseven
Member
From: Massachusetts, USA
Registered: 01-23-2006
Posts: 3169
Website

Re: Link And Truncated Item Description On Main Page

If your database is running in CSV mode (the default), then this mod will not work because it relies on the RAND function which does not work on CSV databases.  In order to make this mod work, you would need to establish a MySQL database and convert the product table to run in MySQL mode.  And no, I will not explain how to do that... it's covered multiple times on the forum already - search is your friend.  You can display products in the best sellers by editting the product description and setting the Display In Best Sellers setting to 'Yes'.   Those products will then appear on the Best Sellers page, which can be linked to with the following code:

Code:

<A HREF="(CGIVAR)common_url(/CGIVAR)&pg=bestsell">best sellers</A><BR><BR>

If you want the products to appear on the splash page, then set the Display On Store Splash Page setting to 'Yes' and make sure the following appears somewhere in the splash page HTML:

Code:

(CGIGET TYPE="SUB" VALUE="ste_prod_disp")

Rachael Katz
- Custom Focusing Screens for DSLR Cameras

Offline

 

#14 12-09-2008 09:56:20

about2flip
Member
Registered: 02-09-2002
Posts: 125

Re: Link And Truncated Item Description On Main Page

First, I want to THANK YOU!!!! Got it working somewhat. I just want to know does the code above stop the image from displaying? I only get the link, and a description. How can I get it to show the image?

Also when I click on the bestseller it takes me to a blank page which displays this:
There are currently no items available that match your selection. Please select from the menu to continue.

Any suggestions will be greatly appreciated Again. Thanks

Offline

 

#15 12-09-2008 10:09:32

rachaelseven
Member
From: Massachusetts, USA
Registered: 01-23-2006
Posts: 3169
Website

Re: Link And Truncated Item Description On Main Page

The image or lack thereof is probably a result of the display type setting.  In your admin area, under Global Settings -> Manage Store settings, you can select the display type for best sellers, splash page, etc.  If you are getting a blank best sellers page, that means that none of your products are set to display on the best sellers page - go into individual product configuration pages and enable them to display on the best sellers page.  Good luck!


Rachael Katz
- Custom Focusing Screens for DSLR Cameras

Offline

 

#16 12-09-2008 10:43:09

about2flip
Member
Registered: 02-09-2002
Posts: 125

Re: Link And Truncated Item Description On Main Page

No. when I do pg=bestsell, the item shows up. but when I click on the bestsell product using the code above it does not go to the product page. Also, I do have it set to image and description.

This is my link location for one of them:
http://www.domain.com/cgi-bin/cp-app.cg … hidtwo.jpg

It comes up blank pages instead of showing the product.

Thanks

Last edited by about2flip (12-09-2008 10:50:32)

Offline

 

#17 12-09-2008 10:47:50

Dave
Member
Registered: 07-05-2003
Posts: 11233

Re: Link And Truncated Item Description On Main Page

Do you have a link available where we can see the problem?

Offline

 

#18 12-09-2008 10:51:49

about2flip
Member
Registered: 02-09-2002
Posts: 125

Re: Link And Truncated Item Description On Main Page

sent you a PM with the link

Offline

 

#19 12-09-2008 10:59:06

Dave
Member
Registered: 07-05-2003
Posts: 11233

Re: Link And Truncated Item Description On Main Page

Maybe it's just me and my lack of understanding of 5.1 but that link is pointing to a product reference that appears to be formatted as a jpg (the ref ends in .jpg). If I remove the wedding/ and .jpg from the ref part of the URL you sent it seems to work correctly.

Offline

 

#20 12-09-2008 10:59:10

rachaelseven
Member
From: Massachusetts, USA
Registered: 01-23-2006
Posts: 3169
Website

Re: Link And Truncated Item Description On Main Page

What is the product reference string for that product?  The one shown in the example URL above won't work, so you have either entered an unacceptable product reference string or the mod you attempted has messed something up.

EDIT: GMTA.  Dave is exactly correct on this one - the reference string is the problem.

Last edited by rachaelseven (12-09-2008 11:00:13)


Rachael Katz
- Custom Focusing Screens for DSLR Cameras

Offline

 

#21 12-09-2008 11:02:33

Dave
Member
Registered: 07-05-2003
Posts: 11233

Re: Link And Truncated Item Description On Main Page

about2flip, if this site isn't live yet I would suggest converting it to version 6 and use that as a base rather than continue with 5.1.

Offline

 

#22 12-09-2008 11:05:26

about2flip
Member
Registered: 02-09-2002
Posts: 125

Re: Link And Truncated Item Description On Main Page

Yes. I noticed that it is pointing to an image, and I don't know why? That product shows up correctly when it is called from the menu. or if I use the pg=bestsell, it comes up. Is it the code above that is calling the image?

Offline

 

#23 12-09-2008 11:19:54

rachaelseven
Member
From: Massachusetts, USA
Registered: 01-23-2006
Posts: 3169
Website

Re: Link And Truncated Item Description On Main Page

If it works properly from category pages and the best seller page, then the code above must have a flaw.  Time to learn some PERL and start debugging...


Rachael Katz
- Custom Focusing Screens for DSLR Cameras

Offline

 

#24 12-09-2008 11:32:57

about2flip
Member
Registered: 02-09-2002
Posts: 125

Re: Link And Truncated Item Description On Main Page

Time to learn some PERL and start debugging... WOW...Thanks I guess

Offline

 

#25 12-09-2008 11:38:39

about2flip
Member
Registered: 02-09-2002
Posts: 125

Re: Link And Truncated Item Description On Main Page

Got it working.. I used the first code above. Anyway you can just glance at the first code above and tell me how to get the image in, and to close the big gap between the link and description:

http://www.flowersbymarlo.com/cgi-bin/c … =orchidtwo

Thanks

Offline

 

Board footer