• I have a WP e-Commerce site up and running perfectly.

    I saw somebody else’s site on the WP e-Commerce forums that was using breadcrumbs. Does anybody know how to setup breadcrumbs? It is probably something simple that I am missing 😛

Viewing 7 replies - 1 through 7 (of 7 total)
  • @jon_bell; Hey Jon. This is an easy one to fix… Login to your admin page. Click the e-Commerce tab, then click settings > then click presentation.

    This is where you will find what you are looking for.

    Although if you are running an old version that might explain why you did not notice breadcrumb navigation

    @mercime; that link did not work for me 😛

    The link’s working for me, or did you mean the plugin linked is not to your taste?

    Breadcrumb NavXT won’t automagically work with e-commerce as it will only see the real WordPress pages, not the product pages from e-commerce that don’t have an associated WordPress page. I have hacked e-commerce before into using WordPress shortcode API, and to create a new WordPress page for each product and category (all nice and hierarchical). Once I did that Breadcrumb NavXT worked perfectly with it. Without doing something like that Breadcrumb NavXT will only be able to generate the breadcrumb trail up to the last WordPress page, but not into the e-commerce stuff.

    mercime; I mean the link did not open when I clicked on it.

    mtekk; Cool. Can you please give us a quick step by step instruction on how to achieve this? We can add it to the plugin core?

    I looked over my hacks and modifications, and it’s safe to say most of it is quite hacky (my methods in some areas force a particular permalink structure which is not ideal). Therefore I will include some code in here, but more importantly I’ll discuss better methods of doing what I did. Warning, this will be quite long.

    Ok, here’s what you need to do. First off I believe the short code thing is already in WP Shopping cart (IIRC I just had to fix a broken regular expression, but you should consider migrating away from custom solutions to the WP shortcode API) the way to check if it’s fixed is see if the shortcode tags [wpsc_category=id] and [wpsc_product=id] where id is the product or category id works. Nothing real magical involved in getting these working (as I said before I think they are both included, just one didn’t work due to a regex problem that I fixed but conveniently didn’t tag as a change).

    Now I created a prod2cat function, which finds the nice name associated with the category of a product based on the product’s ID. This appears to be used in permalink generation (I had to do a grep to figure out what I used this for). It used the category-product relations from the item_category_associations table. Since in the setup I did these modifications for would always have a “real” WordPress page for each wp e-commerce category and product.

    After that I had to modify homepage_products_functions.php and product_display_functions.php to use this function for making the desired permalinks. Rather than do that what probably should be done is make prod2wpPageID and cat2wpPageID functions that map the e-commerce ids for products and categories to their WordPress page counterparts, then the get_permalink function supplied by WordPress could be used for permalink generation. It may also be beneficial to further wrap this into your own get_permalink function.

    In display-items.php the nzshpcrt_prod2cat function is used in aiding in the creation of pages for products. This is the code I used:

    //This creates a new page when a product is added
    	//Use the ID to get the name of the category.
    	$parent_name = nzshpcrt_prod2cat($product_id);
    	//Get the id for the parent page
    	$sql = "SELECT ID FROM $wpdb->posts WHERE post_title = '" . $parent_name . "' LIMIT 1";
    	$parent = $wpdb->get_row($sql);
    	//Setup the query for the new page
    	$ppost_content = "[wpsc_product=" . $product_id . "]";
    	$ppost_title = $wpdb->escape($_POST['name']);
    	$ppost_name = strtolower(str_replace (" ", "-", $ppost_title));
    	$ppost_modified = date("Y-m-d H:i:s");
      	$ppost_modified_gmt = gmdate("Y-m-d H:i:s");
    	//Submitting the post via the API
    	wp_insert_post(array(
    		'post_author'		=> '1',
    		'post_date'		=> $ppost_modified,
    		'post_date_gmt'		=> $ppost_modified_gmt,
    		'post_modified'		=> $ppost_modified,
    		'post_modified_gmt'	=> $ppost_modified_gmt,
    		'post_title'		=> $ppost_title,
    		'post_content'		=> $ppost_content,
    		'post_excerpt'		=> '',
    		'post_status'		=> 'publish',
    		'post_name'		=> $ppost_name,
    		'post_type' 		=> 'page',
    		'comment_status'	=> 'closed',
    		'ping_status'		=> 'closed',
    		'comment_count'		=> '0',
    		'post_parent'		=> $parent->ID)
    	);

    This was placed starting at line 447, in relation to what’s going on in the file, it’s right after the category associations are figured out and committed to the database. Here the sql statement should probably be replaced by $wpdb->prepare. It may be wise to change the post_status from publish to inherit or something else so that it is not immediately available in case the user wants to tweak it a bit (or have that as an user defined option). Additionally, code to either hide or delete the page when the product is deleted must be added.

    Now something similar to this has to be done for display-category.php the only difference is the lack of call to nzshpcrt_prod2cat, which is replace with a db query and code to figure out the nicename of the parent page (the products page). From what I’ve shown above that could be easily adapted.

    If this would be integrated into the core of e-commerce it would in my opinion make everyone’s life a little easier as all the permalink magic is handled by WordPress :).

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘WP e-Commerce site up and running’ is closed to new replies.