LightSpeed Webstore Pagination: don’t want pagination to show when there’s only 1 page

I don’t want to see pagination when there’s only 1 page (of products). There’s nothing more annoying than seeing that stupid < 1 > – even more so when there are only 3 products in a particular category.

Here is a solution that uses the Products Per Page in Tools > eCommerce > admin panel > appearance > Products > Products Per Page & the Pagination code in crumbtrail.tpl.php OR product_list.tpl.php. In Brooklyn Template the pagination code is in product_list.tpl.php. I think the other Templates have it placed in crumbtrail.tpl.php.

I used the pagination code I found in Brooklyn product_list.tpl.php and just tweaked it a teeny bit. Brooklyn adds a new code (webstore 2.5 and up) to get rid of the default arrow images which I like because those arrow images filenames are hardcoded in a core file which is a huge pain in the butt. So if your pagination code is in crumbtrail.tpl.php, your Template is probably not based on Brooklyn and you will have to incorporate the new code into crumbtrail.tpl.php in order to get rid of the pagination arrow images:

 if($this->dtrProducts->Paginator) {
	$this->dtrProducts->Paginator->LabelForPrevious = _sp('previous');
	$this->dtrProducts->Paginator->LabelForNext = _sp('next');
}
	$strPaginator = $this->dtrProducts->Paginator->Render(false);

?>

If you get stuck just open Brooklyn, find product_list.tpl.php and you will see what I mean.

By telling TotalItemCount only to show pagination if there are more products in a category than the amount you chose in Products Per Page, you can make it go away when there’s only 1 page. Here the TotalItemCount is told to check if there are more than 8 products on a page:

<?php if ($this->dtrProducts->TotalItemCount > 8) : ?>
<?php if($this->dtrProducts->Paginator) {  echo $strPaginator; } ?>
<?php endif; ?>

When there are more than 8 products, pagination shows up. This pagination thing has bugged me for a while. I was glad to find a solution and I hope it helps someone else. Please do be aware that if the Products Per Page number is changed you have to change the number in the pagination code, too.

In many places in the templates I see conditional statements checking to see if a particular setting has been set in the configuration settings. So I’m sure if I gave it a bit more time I could use a conditional statement to check what the Products Per Page amount is and that way if the setting is ever changed one wouldn’t have to edit the template file as well. But I am pressed for time. I don’t even have time to write this post. Bye!

Fixing A WordPress Theme to Work with WP-E-Commerce 3.8.9 (or whatever)

I was contacted to fix a WP theme I did not design called Kassyopea – a premium theme that costs $55 for a regular license, $2750 for an extended license.

Error number 1: clicking the add to cart button with Fancy Notifications turned on showed the item in the fancy notification message overlay but didn’t actually add the item to the cart (going to check out you got the message “oops cart is empty”).With Fancy Nootifications turned off all you saw when clicking add to cart was “..Updating” and a little spinner icon but that’s it.Updating never went away and the items were never added to the cart.

So off I went to getshopped.org to check out the user forums and saw this exact same issue was marked Resolved, a rare thing if you’ve ever visited a forum for help with your exact issue. A user suggested de activating all the plugins except the shopping cart and switching over to TwentyEleven ( or any other “proven” WP theme) then go to Settings > Store and then to Presentation and click Flush Theme Cache a few times. I also turned off Fancy Notifications in Settings > store > Presentation. After I did that I went back to the shop and added something to the cart, now the add to cart button worked. I re activated the plugins and switched back to Kassyopea and then went back to Settings > Store and then to Presentation and clicked Flush Theme Cache a few times and then a few more times just to be safe.
The add to cart button worked with Fancy Notifications turned back on – one issue fixed!

Now we just had to deal with the fact that after the normal product listing – about 4 or 5 un-styled, duplicated products were also appearing on the page.
I had fixed this before – it’s always a matter of placing wp_reset_query(); in the right place…

Being too lazy to get an FTP login set up I went right over to Appearance > Editor > page.php and experimentally – just to see what would happen – clicked save without editing anything. Big oops now the page displayed with a big PHP error – somehow just saving the page did something bad!

Oh fab, can I please debug code I didn’t write? That’s what I like to do in my spare time, yay. Unfortunately I didn’t save the original but here is the corrected code in page.php:

if( is_front_page() || is_home() ) {
	add_filter( 'body_class', create_function( '$classes ="", "$classes[] = wpsc;" return $classes;' ) );
	get_template_part( 'home', 'store' ); 
	die;
}

After the last curly brace I added wp_reset_query(); now the code looks like this:

if( is_front_page() || is_home() ) {
	add_filter( 'body_class', create_function( '$classes ="", "$classes[] = wpsc;" return $classes;' ) );
	get_template_part( 'home', 'store' ); 
	die;
}
wp_reset_query();

No more duplicated products on the Shop using WP theme Kassyopea.

So there you have it. If you are having the problem where your add to cart button doesn’t work try switching to a different theme and in Presentation flushing the theme cache 2 or 3 times.Most plugin authors will say it’s another plugin and that is true some of the time but the other part of the time it’s usually the theme you’re using.

And you’re seeing duplicated products it’s probably because there is something like this in the theme:

if( is_front_page() || is_home() ) {

//special code 

}

Update

After I wrote this the site owner wrote me to tell me that the add to cart button wasn’t working. I did everything all over again and tested the button. It worked.
Then I cleared the cart items and it didn’t work. The add to cart button always worked with TwentyEleven and TwentyTen even after I cleared cookies. I poked and prodded and changed settings and etc, etc, etc nothing helped. The add to cart button just didn’t work.

Unfortunately I ended up giving up on fixing it.

The weirdest part of this whole thing was the site owner had the almost exact same site set up using the exact same theme with almost exact same domain (other domain ended in .com, this one ended in .com.au). On this set up the Home page contained the productspage shortcode and also had a products Page that also had the products page shortcode. On this site, the add to cart button worked all the time! What a head scratcher.

LightSpeed Webstore Customization Tip: change default button value, CSS class

Hey there customizers,

here’s a small trick I figured out about changing button values ( the text of a button, e.g., “Submit” ). A trick I turned up when I was stressing about having to edit a core file in order to deliver the same copy as was indicated in the mockup.

If you’re working as much as me, you can’t possibly keep track of every line you edited in core of every site you hand off when prepping for webstore version upgrades ( for every site you maintain). Not that you should ever edit core – but, unfortunately there’s a lot of plain text in LightSpeed Webstore that’s sequestered in core files and sometimes you have to.

Most clients have no idea that most of this stuff is in core – they see “Shipping is the same as Billing address” and they want it to read “My Billing & Shipping Address are the Same for This Order”. While I can go into /where-webstore-is-installed/xlsws_includes, find the file that contains the line “Shipping is the same as Billing address” and edit it, I’m not supposed to. Not that it will break stuff (editing plain text rarely breaks anything) but imminent upgrades will possibly overwrite the edit and I might not remember to add it back.

Because of this issue I’m always looking for ways to edit stuff without touching core so when I saw this line in /templates/deluxe/promo_code.tpl.php which renders the submit button for the Promo Code input field:

<?php $this->btnPromoVerify->Render('Text='._sp("Apply Promo Code")) ?>

I tried it out on other render hooks and found out I could use it practically anywhere I wanted to. I could also use this other handy line I’d seen sprinkled about in template files which generates the CSS class for a HTML element such as for the Login/Register buttons in
/templates/deluxe/checkout_login_register.tpl.php:

 
<?php $this->butLogin->Render('CssClass=button rounded') ?> 
<?php $this->butRegister->Render('CssClass=button rounded') ?>

I combined the lines in one render hook and was real (stupidly pleased) with myself. Example:

<?php $this->whatEver->Render('CssClass=awesome',
'Text='._sp("Awesome")) ?>

Keep your eyes peeled for $this->something->Render() in your templates and try it out for yourself.

Update!

I just wrote this post about getting the minicart from Webstore to show (with cart content intact). Now I’m thinking, using similar methods, what other features of Webstore can I bring into a WordPress theme? For instance, to get the Webstore menu – can I just copy menu.tpl.php into a WordPress theme file named menu.php and then call it with get_template_part(‘menu’);? Would surely be a lot easier than how I currently do it using code I wrote relying on Simple HTML Dom to get the menu! And I wouldn’t get chastised by snotty programmers about SHD using file_get_contents! Ha.

Anyway, I’ll let you know how it goes. But to me, this is very exciting. No doubt if the experiments work out super fast & easy Webstore & WordPress customizations will be possible for practically every project.

Update For the Update:

Sooo, experimenting didn’t go very far. Seems requiring prepend.inc.php is able to get the cart
– probably because at the top of minicart.tpl.php there’s this neat code:

 $cart = Cart::get_cart();
$items = $cart->GetCartItemArray();  

but if you need more you’d have to require webstore index.php. Because it loads the functions for the category menu. I think. Experimenting doing just that however led to an error that read: Template file is missing. Because of course webstore’s index.php was trying to find various template files (like index.tpl.php) in WordPress which I’ve got installed in the root. Webstore is installed in /shop. When I have more time to fool around with this I’ll have time to move WordPress into a sub-directory of the webstore location – like /shop/wordpress… The good news about all of this is that it seems as if the outlook is good. I couldn’t successfully get the webstore menu to show up in my WordPress theme by using get_template_part(‘webstore-menu’); which of course was just a copy of menu.tpl.php…
But I also didn’t run into any PHP errors. Makes me think that if everything is in the right order and place t might work out. One day. I’ll beat this one day!
Happy coding.

Legacy Code Notice

Don’t use:

 $cart = Cart::get_cart();

Do use:

 $cart = Cart::GetCart();

get_cart(); can get the cart but it will fill your error logs with statements about using legacy code.