Zen Cart Logo
Forums / General Questions / Product as homepage: Need URL to be generic

Product as homepage: Need URL to be generic

Views: 887

Results 1 to 5 of 5
10 Apr 2014, 6:20 PM
#1
mickyhulse avatar

mickyhulse

New Zenner

Join Date:
Mar 2014
Posts:
10
Plugin Contributions:
0

Product as homepage: Need URL to be generic

Hello,

Our shop (ZenCart v1.5.1) sells one product at a time. It's basically a weekly coupon sale where customers can buy X many coupons until they are sold out for that week.

My co-worker has setup our ZenCart install so that a single product loads when visiting the homepage of the site.

Our ZenCart admin settings:

Admin > Configuration > Layout Settings ≥ Skip 1-prod Categories = true
Always Show on Main Page and Main Page = 1
Opens With Category = 2

With the above setup, when a user visits the site:

https://foo.site.com/zencart/

… they will get redirected to:

https://foo.site.com/zencart/index.php?main_page=product_info&cPath=2&products_id=224

When it comes time to sell a new coupon, we disable the old coupon/product and create a new coupon/product.

Now, when visiting:

https://foo.site.com/zencart/

… the user gets redirected to:

https://foo.site.com/zencart/index.php?main_page=product_info&cPath=2&products_id=225

Note that the products_id has changed.

Problem:

We're concerned that users will bookmark the product url. When visiting the site again, they won't get redirected to the latest product because the product URL is specific to a single product.

Questions:

  1. Is it possible to make the product URL more generic? Optimally, I'd love to have the product detail load on the homepage url: https://foo.site.com/zencart/

  2. How would you solve this problem?

Thanks!
M

10 Apr 2014, 6:42 PM
#2
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Product as homepage: Need URL to be generic

You could setup your site to open to the Category that holds the current Product ...

Then, customize the file:
/includes/modules/pages/product_info/header_php.php

and add the code in RED:

  $res = $db->Execute($sql);

[B]// bof: if products_id is products_status = 0 redirect to home page
  if ($res->fields['total'] < 1) {
    zen_redirect(zen_href_link(FILENAME_DEFAULT));
  }
// eof: if products_id is products_status = 0 redirect to home page
[/B]  
  if ( $res->fields['total'] < 1 ) {

So now the site opens to the current product and if the customer tries to go to the products_info page for a products_id that is not enabled, they are directed to the home page and the home page takes them to the current product ...

10 Apr 2014, 6:54 PM
#3
mickyhulse avatar

mickyhulse

New Zenner

Join Date:
Mar 2014
Posts:
10
Plugin Contributions:
0

Re: Product as homepage: Need URL to be generic

Ajeh, you ROCK! That worked! :)

Thanks so much for the quick reply and example code.

At first, I tried re-creating header_php.php inside my theme's folder:

includes/templates/MY_THEME/modules/pages/product_info/header_php.php

But that did not work. Optimally, it would be nice to have this file be in my theme to make upgrades easier. But, I can always have a README at the root that warns future devs that we've made some core mods that they should be aware of. :)

Anyway, thanks so much for the help Ajeh! I owe you one!

Have a nice day!

Cheers,
M

10 Apr 2014, 9:44 PM
#4
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Product as homepage: Need URL to be generic

You are most welcome ... thanks for the update that this is working for you ... :smile:

Remember the Zen Cart Team when you are rich and famous! :cool:

4 Sep 2017, 8:12 AM
#5
able avatar

able

New Zenner

Join Date:
Dec 2012
Posts:
13
Plugin Contributions:
0

Re: Product as homepage: Need URL to be generic

Ajeh:

You could setup your site to open to the Category that holds the current Product ...

Then, customize the file:
/includes/modules/pages/product_info/header_php.php
........
//

Is there a similar way to prevent viewing categories that are set to off?

Maybe I am missing something super simple, but people are able to manually change the category ID in the URL bar, or go via bookmark, to categories that have been turned off (turned to red in the Admin).

I only even noticed this when someone recently ordered a product from an off category. I went back and turned all the products off so that solves the ordering problem, but still seems odd that surfers can jump in and view categories that are turned off. How to force them back to the main page if the category ID they enter is off?