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.
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..
$html_desc_text = vars_truncate($html_desc_text,'150');
Offline
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
####################################################################### # 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
(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
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?
Offline
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
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.
Offline
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.
####################################################################### # 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
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
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.
Offline
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
The answer is about half a dozen posts up in this very thread:
https://forum.kryptronic.com/viewtopic. … 910#p38910
Offline
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
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:
<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:
(CGIGET TYPE="SUB" VALUE="ste_prod_disp")
Offline
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
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!
Offline
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
Do you have a link available where we can see the problem?
Offline
sent you a PM with the link
Offline
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
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)
Offline
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
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
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...
Offline
Time to learn some PERL and start debugging... WOW...Thanks I guess
Offline
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