Forums / Setting Up Categories, Products, Attributes / Showing a specific category if the shopping cart is empty.

Showing a specific category if the shopping cart is empty.

Views: 4,078

Results 1 to 20 of 41
16 Jun 2014, 3:48 PM
#1
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Showing a specific category if the shopping cart is empty.

I have a customer that wants to display a specific category when a customer goes to an empty shopping cart.

I've identified the file "tpl_shopping_cart_default.php" as the logical place to add the code to do this, but I'm having a bit of a hard time figuring out what include/require (or whatever) I need to use to make this function.

The existing code to have it display new products, featured products and specials looks quite simple

<?php require($template->get_template_dir('tpl_modules_whats_new.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_whats_new.php'); ?>

but I need it to display the same as I'd get when loading
mystore/index.php?main_page=index&cPath=258_260

Does any have any ideas or suggestions? (is this even possible?)

Thanks in advance
RodG

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.

16 Jun 2014, 7:01 PM
#2
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,802
Plugin Contributions:
22

Re: Showing a specific category if the shopping cart is empty.

Hm... I understand it's not exactly what you're asking for, but would you settle for a simple alternative until you get this figured out?

EDIT: Basically, a centerbox just like what's new, featured etc... Hope it helps...

My site - Pro ZC Help
My portfolio | My plugins

19 Jun 2014, 1:24 AM
#3
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Showing a specific category if the shopping cart is empty.

RodG:

I have a customer that wants to display a specific category when a customer goes to an empty shopping cart.

I've identified the file "tpl_shopping_cart_default.php" as the logical place to add the code to do this, but I'm having a bit of a hard time figuring out what include/require (or whatever) I need to use to make this function.

The existing code to have it display new products, featured products and specials looks quite simple

<?php require($template->get_template_dir('tpl_modules_whats_new.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_whats_new.php'); ?>
> 
> but I need it to display the same as I'd get when loading 
> mystore/index.php?main_page=index&cPath=258_260
> 
> Does any have any ideas or suggestions?  (is this even possible?) 
> 
> Thanks in advance
> RodG

When you say "go to a specific" category, you do mean that there should be a redirect/load of the categories page that is desired, not just to keep the current page, but add the content of the category's page into some sort of tab, correct?

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

19 Jun 2014, 8:01 AM
#4
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: Showing a specific category if the shopping cart is empty.

balihr:

Hm... I understand it's not exactly what you're asking for, but would you settle for a simple alternative until you get this figured out?

EDIT: Basically, a centerbox just like what's new, featured etc... Hope it helps...

Thanks for this. I think I might find it useful for another site I've been working on, but it doesn't suit this customers needs.

Cheers
RodG

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.

19 Jun 2014, 8:01 AM
#5
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: Showing a specific category if the shopping cart is empty.

mc12345678:

When you say "go to a specific" category, you do mean that there should be a redirect/load of the categories page that is desired, not just to keep the current page, but add the content of the category's page into some sort of tab, correct?

Either solution would be acceptable.

Cheers
RodG

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.

19 Jun 2014, 9:35 AM
#6
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Showing a specific category if the shopping cart is empty.

RodG:

Either solution would be acceptable.

Cheers
RodG

I would add a switch in to the configuration panel to fill in the number. Then do a test where the redirect is It's of redirect is empty then normal page is shown.If it is not empty then check or use the number and redirect with the below.

zen_redirect(zen_href_link( FILENAME_DEFAULT, zen_get_path(cat#)));

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

19 Jun 2014, 9:52 AM
#7
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Showing a specific category if the shopping cart is empty.

Forgot to mention that if need to also through a redirect code (wasn't sure which would be appropriate), then before the last closing parenthesis, add , "redirect code'

Where redirect code would be substituted with the applicable # such as 302, 400, etc. (Pick one number though. :)

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

19 Jun 2014, 10:08 AM
#8
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: Showing a specific category if the shopping cart is empty.

mc12345678:

I would add a switch in to the configuration panel to fill in the number. Then do a test where the redirect is It's of redirect is empty then normal page is shown.If it is not empty then check or use the number and redirect with the below.

zen_redirect(zen_href_link( FILENAME_DEFAULT, zen_get_path(cat#)));

That's good in theory, but in practice it doesn't work due to the headers already being sent


Cannot modify header information - headers already sent by (output started at /home/www/mysite/includes/templates/mytemplate/common/html_header.php:41)

Cheers
RodG

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.

19 Jun 2014, 10:15 AM
#9
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Showing a specific category if the shopping cart is empty.

Okay, so the next thought would be wherever the link to the shopping cart is generated, to use a test of the quantity of items in the cart, if zero, then the link should be as identified in the redirect (everything in that line except the zen_redirect() portion. If there are items, then goto the cart. That's the "dirty" approach I would take at that point.

Though I would think that there was a better approach knowing that the headers had already been pushed. :/

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

19 Jun 2014, 10:19 AM
#10
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Showing a specific category if the shopping cart is empty.

But, the approach I just described doesn't handle the condition of everything being deleted from the cart when viewing the cart. Wouldn't putting the previous code in the shopping_cart header_php.php file make it possible to do the redirect without error? (Sorry I'm somewhat guessing now.)

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

19 Jun 2014, 11:08 AM
#11
frank18 avatar

frank18

Deceased

Join Date:
Nov 2007
Location:
Sunny Coast, Australia
Posts:
3,427
Plugin Contributions:
2

Re: Showing a specific category if the shopping cart is empty.

The quick and (VERY) dirty solution:

In the file yoursite.com/includes/templates/YOUR_TEMPLATE/templates/tpl_shopping_cart_default.php

find around line 211

while (!$show_display_shopping_cart_empty->EOF) { 
?> 

Directly below insert

<?php 
zen_redirect('http://yoursite.com/index.php?main_page=index&cPath=0'); 
?> 

Replace cPath=0 with the category of your choice - eg 64 or 73_3

Works, but it is (as said before) a quick and dirty way.

Cheers / Frank

NOTE: We are sorry that Frank is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

19 Jun 2014, 11:20 AM
#12
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Showing a specific category if the shopping cart is empty.

mc12345678:

I would add a switch in to the configuration panel to fill in the number. Then do a test where the redirect is It's of redirect is empty then normal page is shown.If it is not empty then check or use the number and redirect with the below.

zen_redirect(zen_href_link( FILENAME_DEFAULT, zen_get_path(cat#)));

frank18:

The quick and (VERY) dirty solution:

In the file yoursite.com/includes/templates/YOUR_TEMPLATE/templates/tpl_shopping_cart_default.php

find around line 211

while (!$show_display_shopping_cart_empty->EOF) {
?>

> 
> Directly below insert
>  
> ```php
<?php 
zen_redirect('http://yoursite.com/index.php?main_page=index&cPath=0'); 
?> 

Replace cPath=0 with the category of your choice - eg 64 or 73_3

Works, but it is (as said before) a quick and dirty way.

Cheers / Frank

Combine these two and tada then it sounds like. :)
The switch add in makes the solution a little more robust and universal, but is not necessary. I would however, go with the implementation of using the zC functions over the hard coded link. Like frank said, truly dirty version in that regards.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

19 Jun 2014, 12:07 PM
#13
frank18 avatar

frank18

Deceased

Join Date:
Nov 2007
Location:
Sunny Coast, Australia
Posts:
3,427
Plugin Contributions:
2

Re: Showing a specific category if the shopping cart is empty.

mc12345678:

Combine these two and tada then it sounds like. :)
The switch add in makes the solution a little more robust and universal, but is not necessary. I would however, go with the implementation of using the zC functions over the hard coded link. Like frank said, truly dirty version in that regards.

That would be my approach, not more 'robust' but certainly more flexible and elegant.

BUT: I don't have the time to get this up as a mod - so leave it to someone else to make it CLEAN (as opposed to quick and dirty :P)

At least RodG can satisfy his customer's needs - and work on it from here ..... in the background.

Cheers / Frank

NOTE: We are sorry that Frank is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

19 Jun 2014, 12:17 PM
#14
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Showing a specific category if the shopping cart is empty.

Btw, took a look at the tpl_shopping_cart_default.php file and the location suggested. I'd put the new code above the while loop, and probably right in line with the TEXT_CART_EMPTY section of code. That would be the default action, and this new redirect would be the alternate direction. Also, if in the while loop and there are no keys returned from the SQL, then the redirect would not occur.As for generating a plugin for all to use? Isn't that what this thread is for? :) found problem, found solution, use it? :)

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

19 Jun 2014, 1:14 PM
#15
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: Showing a specific category if the shopping cart is empty.

frank18:

The quick and (VERY) dirty solution:

In the file yoursite.com/includes/templates/YOUR_TEMPLATE/templates/tpl_shopping_cart_default.php

find around line 211

while (!$show_display_shopping_cart_empty->EOF) {
?>

> 
> Directly below insert
>  
> ```php
<?php 
zen_redirect('http://yoursite.com/index.php?main_page=index&cPath=0'); 
?> 

Replace cPath=0 with the category of your choice - eg 64 or 73_3

Works, but it is (as said before) a quick and dirty way.

Cheers / Frank

Doesn't work. Headers already sent.

Cheers
RodG

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.

19 Jun 2014, 1:34 PM
#16
frank18 avatar

frank18

Deceased

Join Date:
Nov 2007
Location:
Sunny Coast, Australia
Posts:
3,427
Plugin Contributions:
2

Re: Showing a specific category if the shopping cart is empty.

RodG:

Doesn't work. Headers already sent.

Cheers
RodG

Worked fine on my local dev site

NOTE: We are sorry that Frank is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

19 Jun 2014, 1:34 PM
#17
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Showing a specific category if the shopping cart is empty.

This worked for me... Same file: includes/templates/YOUR_TEMPLATE/templates/tpl_shopping_cart_default.php
No error message generated...

?>
<h2 id="cartEmptyText"><?php echo TEXT_CART_EMPTY; 
zen_redirect(zen_href_link(FILENAME_DEFAULT, zen_get_path('2'))); ?></h2>
<?php
$show_display_shopping_cart_empty = $db->Execute(SQL_SHOW_SHOPPING_CART_EMPTY);
while (!$show_display_shopping_cart_empty->EOF) {
?>
 

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

19 Jun 2014, 1:56 PM
#18
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Showing a specific category if the shopping cart is empty.

mc12345678:

Forgot to mention that if need to also through a redirect code (wasn't sure which would be appropriate), then before the last closing parenthesis, add , "redirect code'

Where redirect code would be substituted with the applicable # such as 302, 400, etc. (Pick one number though. :)

For anyone else that has read this or is following it, there is no reason to throw a redirect code for this situation as far as I can think. I'm not 100% sure what I was thinking other than trying to finish off the redirect statement and for some reason I was thinking of the situation where a product is not found instead of the goal to show a category when the cart is empty and the guest goes to the cart.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

19 Jun 2014, 1:58 PM
#19
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Showing a specific category if the shopping cart is empty.

What's happening downstream? Ie, regarding the particular category to which the guest is being sent? Is there yet another redirect somewhere there? Can you enter in the browser the path to the category without getting the error?

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

19 Jun 2014, 2:02 PM
#20
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: Showing a specific category if the shopping cart is empty.

mc12345678:

This worked for me... Same file: includes/templates/YOUR_TEMPLATE/templates/tpl_shopping_cart_default.php
No error message generated...

?>

<h2 id="cartEmptyText"><?php echo TEXT_CART_EMPTY; zen_redirect(zen_href_link(FILENAME_DEFAULT, zen_get_path('2'))); ?></h2> <?php $show_display_shopping_cart_empty = $db->Execute(SQL_SHOW_SHOPPING_CART_EMPTY); while (!$show_display_shopping_cart_empty->EOF) { ?>


Still got me fcked.
------------------------------------------------------------------------------------------------- 
[19-Jun-2014 13:46:16 UTC] PHP Warning:  Cannot modify header information - headers already sent by (output started at /home/www/xxxxxxx/includes/templates/xxxxxxxxxxx/common/html_header.php:41) in /home/www/xxxxxxxxxxx/includes/functions/functions_general.php on line 46
---------------------------------------------------------------------------------------------------------

Here's a step by step of whats going on. 


Customer clicks on the shopping cart link. 


ZenCart loads and outputs from 
/common/html_header.php 
which then loads 
shopping_cart_header.php
which in turn loads 
tpl_shopping_cart_default.php 


tpl_shopping_cart_default.php performs a check for shopping cart contents, and displays them if available. If none are available it executes
$show_display_shopping_cart_empty = $db->Execute(SQL_SHOW_SHOPPING_CART_EMPTY); to determine what should be displayed instead. 


It then runs through the loop to output new products, specials, featured products, etc. 


All quite simple, and yes, it seems like it should be a no brainer to just add a redirect (conditional or otherwise) to call/load/display any other page, as per the suggestions, but this doesn't work because the headers have already been sent by /common/html_header.php 


It makes no difference where in tpl_shopping_cart_default.php I add the redirects, it's always going to be sent too late to avoid the 'headers already sent' error. 


This suggests/implies two viable solutions that I can think of. 


1) As suggested by balihr, call a custom module to output the data needed, or 
2) create/add code to the tpl_shopping_cart_default.php code itself to output the data needed. 


or 
3) I don't know. Any ideas? 


At the moment I've gone with #2. It doesn't do exactly what the customer is after, but its the next best thing (so far). The data being output is the categories list. ...

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.