Archive for category WP e-commerce

WordPress WP-ecommerce Search Page with Related Products Hack

If you are using WP-ecommerce on your WordPress site, what about displaying related products on your theme’s search page?

Just copy and paste the following code on your search.php file, on your theme folder. It will bring as results the title and first image of each product found, linked to the detail page.

<?php
/**
 * @package WordPress
 * @subpackage Toolbox
 */

get_header(); ?>

        <section id="primary">
            <div id="relprods" style="float:left;width:140px;margin-right:20px;">
            <?
            /*
                New code by Alvaron - brings two first product images - 08-22-2011
            */
                $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
                mysql_select_db(DB_NAME) or die ("Could not select database, check you wp-config file" . mysql_error());
                $sqlp ="select ID, post_title, post_name from wp_posts where post_type='wpsc-product' ";
                $sqlp .="and post_status='publish' ";
                $sqlp .="and (post_title like '%".$_GET['s']."%' ";
                $sqlp .="or post_content like '%".$_GET['s']."%') ";
                $sqlp .="order by id ASC ";
                $qryp = mysql_query($sqlp);
                $nrtp = mysql_num_rows($qryp);
                if($nrtp>0):
                    $mxctst= "max-width:550px";                     
                    echo "<b>".$nrtp. " Related Products for ".$_GET['s'].":</b><br><br>";
                    while($rsp = mysql_fetch_array($qryp)):
                        ++$prdcnt;
                    ?>
                        <p><?=$prdcnt;?>.
                        <a rel="<?php echo $rsp[1]; ?>" href="<?php echo get_bloginfo('siteurl')."/".$rsp[2]; ?>"><?php echo $rsp[1]; ?></a><br />
                    <?
                        $sqli = "select guid from wp_posts where post_type='attachment' and post_mime_type='image/jpeg' and post_parent=".$rsp[0];
                        $sqli .= " ORDER BY ID DESC ";
                        $sqli .= " LIMIT 1 ";
                        $qryi = mysql_query($sqli);
                        $nrti = mysql_num_rows($qryi);
                        while($rsi = mysql_fetch_array($qryi)):
                        ?>                                               
                                <a rel="<?php echo $rsp[1]; ?>" href="<?php echo get_bloginfo('siteurl')."/".$rsp[2]; ?>"><img class="product_image" id="product_image_<?php echo $rsp[0]; ?>" alt="<?php echo $rsp[1]; ?>" title="<?php echo $rsp[1]?>" src="<?php echo $rsi[0]; ?>" width="140"/></a>   
                        <?
                        endwhile;
                        ?>
                        </p>
                        <?
                    endwhile;
                endif;
                ?>
            </div>
            <div id="content" role="main" style="float:left;<?=$mxctst?>">

            <?php if ( have_posts() ) : ?>

                <header class="page-header">
                    <h1 class="page-title"><?php printf( __( 'Search Results for: %s', 'toolbox' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
                </header>

                <?php /* Display navigation to next/previous pages when applicable */ ?>
                <?php if ( $wp_query->max_num_pages > 1 ) : ?>
                    <nav id="nav-above">
                        <h1 class="section-heading"><?php _e( 'Post navigation', 'toolbox' ); ?></h1>
                        <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'toolbox' ) ); ?></div>
                        <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'toolbox' ) ); ?></div>
                    </nav><!-- #nav-above -->
                <?php endif; ?>
               
                <?php /* Start the Loop */ ?>
                <?php while ( have_posts() ) : the_post(); ?>
                   
                    <?php get_template_part( 'content', 'search' ); ?>

                <?php endwhile; ?>
               
                <?php /* Display navigation to next/previous pages when applicable */ ?>
                <?php if (  $wp_query->max_num_pages > 1 ) : ?>
                    <nav id="nav-below">
                        <h1 class="section-heading"><?php _e( 'Post navigation', 'toolbox' ); ?></h1>
                        <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'toolbox' ) ); ?></div>
                        <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'toolbox' ) ); ?></div>
                    </nav><!-- #nav-below -->
                <?php endif; ?>               

            <?php else : ?>

                <article id="post-0" class="post no-results not-found">
                    <header class="entry-header">
                        <h1 class="entry-title"><?php _e( 'Nothing Found', 'toolbox' ); ?></h1>
                    </header><!-- .entry-header -->

                    <div class="entry-content">
                        <p><?php _e( 'Sorry, but nothing matched your search criteria. Please try again with some different keywords.', 'toolbox' ); ?></p>
                        <?php get_search_form(); ?>
                    </div><!-- .entry-content -->
                </article><!-- #post-0 -->

            <?php endif; ?>

            </div><!-- #content -->
        </section><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>
Advertisements

Leave a comment

WordPress WP-ecommerce Two Images Hack on Single Product Page

Have you ever thought about displaying two or more images on your wpsc-single_product.php file instead of just one?

If you need to display more than one image, you just have to add this code to the single product page, changing values for LIMIT on the SQL query as you want.

Probably you will want to comment the thumbnail original code. It is right after the line with this conditional

<?php if ( wpsc_the_product_thumbnail()) : ?>

Well, here goes the hack.

<?
$conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db(DB_NAME) or die ("Could not select database, check you wp-config file" . mysql_error());
$sql = "select guid from wp_posts where post_type='attachment' and post_mime_type='image/jpeg' and post_parent=".wpsc_the_product_id();
$sql .= " ORDER BY ID ";
$sql .= " LIMIT 2 ";
$qry = mysql_query($sql);
$nrt = mysql_num_rows($qry);
while($rs = mysql_fetch_array($qry)):
?>
    <a rel="<?php echo wpsc_the_product_title(); ?>" class="<?php echo wpsc_the_product_image_link_classes(); ?>" href="<?php echo $rs[0]; ?>">
            <img class="product_image" id="product_image_<?php echo wpsc_the_product_id(); ?>" alt="<?php echo wpsc_the_product_title(); ?>" title="<?php echo wpsc_the_product_title(); ?>" src="<?php echo $rs[0]; ?>" width="280"/>
        </a>
<?
endwhile;
?>

Leave a comment

The New WP e-Commerce List Products and Images Hack

This post was moved to http://www.wpworking.com/hacks-2/the-new-wp-e-commerce-list-products-and-images-hack/


Well, this code bellow is what I call a “Chewbacca” code, but it works.

I present you the new hack to list products data and images where you want on your theme, if you are working with WP-ecommerce on WordPress.

It was tested on 3.8.5 version, and worked like a charm. If you are using older versions, check the old hack.

Also check WP e-Commerce Product Showroom 2.0.0 on the plugin menu.

$conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db(DB_NAME) or die ("Could not select database, check you wp-config file" . mysql_error());
// if you are note sure about the value of $wp_table_prefix, perform a search for this
// text on your site, the usual value is "wp_" or something
$sql = "select pt.ID, pt.post_title from wp_posts As pt  ";
$sql .= "LEFT JOIN wp_postmeta As mt ON pt.ID=mt.post_id  ";
$sql .= "WHERE pt.post_type = 'wpsc-product' ";
$sql .= "AND pt.post_status = 'publish' ";
$sql .= "GROUP BY mt.post_id ";
$sql .= "ORDER BY pt.post_title ";
$sql .= "LIMIT 3 ";
$qry = mysql_query($sql);
$nrt = mysql_num_rows($qry);
while($rs = mysql_fetch_array($qry)):
//
$sqlp = "select meta_value from wp_postmeta as wm, wp_posts wp ";
$sqlp .= "where wm.meta_key='_wpsc_price' and wm.post_id=".$rs[0];
$sqlp .= " GROUP BY wm.post_id";
$qryp = mysql_query($sqlp);
while($rsp = mysql_fetch_array($qryp)):
	$prc = $rsp[0];
endwhile;
//
$sqli = "select meta_value from wp_postmeta as wm, wp_posts wp ";
$sqli .= "where wm.meta_key='_thumbnail_id' and wm.post_id=".$rs[0];
$sqli .= " GROUP BY wm.post_id";
$qryi = mysql_query($sqli);
while($rsi = mysql_fetch_array($qryi)):
	//
	$sqlt = "select guid from wp_posts where ID=".$rsi[0];
	$qryt = mysql_query($sqlt);
	while($rst = mysql_fetch_array($qryt)):
		$pht = $rst[0];
	endwhile;
endwhile;


$htmlcod .= "<div class='showrpdiv'>\n";
$htmlcod .= "<ul>\n";
$htmlcod .= "<li><a href=".wpsc_product_url($rs[0]).">".$rs[1]."</a><br>";
$htmlcod .= "<a href='".wpsc_product_url($rs[0])."'>";
$htmlcod .= "<img src='".$pht."' style='width:".$tbwid."px'></a>\n";
$htmlcod .= "</li>\n";
$htmlcod .= "<li>".$prc."</li>\n";                   
$htmlcod .= "</ul>\n";
$htmlcod .= "</div>\n";

endwhile;

echo $htmlcod;

11 Comments

Meet WP e-Commerce Product Showroom Plugin – a custom list of products

I’m proud to present you my new WordPress plugin. It’s “WP e-Commerce Product Showroom“, a product list that you can customize through a widget on wp-admin and fit to your layout needs using a little bit of css.
Estou orgulhoso em apresentar a vocês meu novo plugin WordPress. É o “WP e-Commerce Product Showroom”, uma lista de produtos que você pode customizar através de um widget no wp-admin e adequar às suas necessidades de layout com um pouco de css.

If you are working with “WP e-Commerce”, all you have to do to is to follow the next simple steps:
Se você está trabalhando com “WP e-Commerce”, tudo que você deve fazer é seguir os próximos passos simples:

1. Upload wp_e_showrp folder to the /wp-content/plugins/ directory
Subir a pasta wp_e_showrp para o diretório /wp-content/plugins/
2. Activate the plugin through the ‘Plugins’ menu in WordPress
Ativar o plugin através do menu ‘Plugins’ no WordPress.
3. Register a widget sidebar on your functions file, for example, just paste the code bellow on your theme functions.php
Registrar um sidebar widget no seu arquivo functions, por exemplo cole o código abaixo no functions.php de seu tema.

<if ( function_exists('register_sidebar') ) register_sidebar(array( 'name' => 'wp_e_showrp', 'before_widget' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => '', ));>

Or

You if you have already registered any sidebar, you can drag the WP e-Commerce Product Showroom widget inside it, at wp-admin
Ou, se você já tem uma sidebar registrada, você pode arrastar o widget WP e-Commerce Product Showroom para dentro dela, no wp-admin.
1. Configure the widget on your wp-admin pannel and save
Configure o widget no seu painel wp-admin e salve.
2. Use the PHP code bellow where you want the widget to show, on your theme pages
Use o código PHP abaixo onde você quer que o widget apareça, nas páginas de seu tema

<if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('wp_e_showrp')) : endif;>

Now, the best part… 😉
Agora a melhor parte… 😉

As the result div uses a css class(showrpdiv), you can play with it and make the product list look like you want. Check the example bellow. If you put this on the same page you call the plugin, the list will change as you wish.
Como o div de resultado usa uma classe css(showrpdiv), você pode brincar com ela e fazer a lista de produtos aparecer como você quiser. Se você colocar um código como o abaixo na mesma página onde chama o plugin, a lista vai mudar como você desejar.

.showrpdiv{ float:left; } 
.showrpdiv ul a{ color:red; } 
.showrpdiv li{list-style: none;}

I hope you find it useful and helpful on your WordPress e-commerce projects.
Espero que você ache útil e que possa lhe ajudar em seus projetos de e-commerce com WordPress.

, ,

4 Comments

WP e-Commerce List Products and Images Hack

Important note: It works only for WP-ecommerce 3.6. For later versions, WP-ecommerce database has changed, so you will need the new hack.

You should also take a look on my WP e-Commerce Product Showroom Plugin, a configurable widget and a evolution of the code bellow.

If you are working with WP e-Commerce Plugin, with the code bellow, you will be able to get a kind of product list, with images, anywhere you want on your site.

Just change your database information, and the LIMIT on mysqlquery, and no more stress…

Good look, may the force be with you.

<?
   $conn = mysql_connect("SERVER", "USER", "PASS"); 
    mysql_select_db("DATABASE") or die ("Could not select database" . mysql_error());
    // if you are note sure about the value of $wp_table_prefix, perform a search for this
    // text on your site, the usual value is "wp_" or something
    $sql = "SELECT products.id,products.name,products.description,products.image,product_category.category_id ";
    $sql .= "FROM ".$wp_table_prefix."wpsc_product_list AS products ";
    $sql .= "LEFT JOIN ".$wp_table_prefix."wpsc_item_category_assoc AS product_category ON ";
    $sql .= "products.id=product_category.product_id ";
    $sql .= "WHERE products.publish=1 AND products.active=1 ORDER BY products.name LIMIT 3";
    $qry = mysql_query($sql);
    $nrt = mysql_num_rows($qry);
    while($rs = mysql_fetch_array($qry)):          
?>
                <div>
                    <ul>
                        <li><a href="<?php echo wpsc_product_url($rs[0]); ?>">
                        <img src="index.php?image_id={<?=$rs[3]?>}"></a>
                        <a href="<?php echo wpsc_product_url($rs[0]); ?>"><?=$rs[1];?></a></li>   
                        <li><?=calculate_product_price($rs[0]);?></li>                   
                               
                    </ul>                    
                </div>
<?
	endwhile;     
?>

,

7 Comments

%d bloggers like this: