Zen Cart Logo
Forums / General Questions / Linking directly to product with zen_href_link

Linking directly to product with zen_href_link

Views: 1,534

Results 1 to 8 of 8
28 May 2013, 12:32 AM
#1
kgeoffrey avatar

kgeoffrey

New Zenner

Join Date:
Mar 2007
Posts:
22
Plugin Contributions:
0

Linking directly to product with zen_href_link

Hi there. Does anyone know how to link directly to a product from /store/includes/languages/english/html_includes/classic/define_main_page.php such that the link includes the zenid?

I have used <a href="' . zen_href_link(FILENAME_DEFAULT, 'cPath=2') . '"> in a customization I did as part of a define in /store/includes/languages/english/checkout_payment.php but I can't figure out how to make it work on the main page.

Thanks!

28 May 2013, 12:41 AM
#2
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Linking directly to product with zen_href_link

such that the link includes the zenid
The zenid is a security item and should NEVER be included in any link

If you are referencing "zen_href_link " then on the main page you do not have any product information loaded as of yet

Just use the standard linking format for your define_main_page.php file

28 May 2013, 4:42 PM
#3
kgeoffrey avatar

kgeoffrey

New Zenner

Join Date:
Mar 2007
Posts:
22
Plugin Contributions:
0

Re: Linking directly to product with zen_href_link

Thanks for the reply. Just to be clear, I'm just trying to put a link in define_main_page.php that has the form /store/index.php?main_page=product_info&cPath=xx&products_id=xx&zenid=generatedbythestore like the links in the Featured Products section.

28 May 2013, 5:44 PM
#4
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Linking directly to product with zen_href_link

/store/index.php?main_page=product_info&cPath=xx&products_id=xx&zenid

To be clear NEVER include the zenid in any link

Enter as such

http://your_domain.xxx/store/index.php?main_page=product_info&cPath=xx&products_id=xx
29 May 2013, 12:20 AM
#5
kgeoffrey avatar

kgeoffrey

New Zenner

Join Date:
Mar 2007
Posts:
22
Plugin Contributions:
0

Re: Linking directly to product with zen_href_link

I totally admit that I may have no clue what I'm talking about, but I'm going to try one more time. :) The zenid is generated by the store during each session, correct? So, I can't (nor would I want to) hard code some random zenid into the link. I get that. I'm just trying to add a link to the front page of the site, such that the site will automatically append the zenid session to the link, just as it does for all other links in the store. Does that make sense? Thanks!

29 May 2013, 12:52 AM
#6
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Linking directly to product with zen_href_link

Let ZenCart handle sessions - as it does a good job of doing so

29 May 2013, 4:12 AM
#7
kgeoffrey avatar

kgeoffrey

New Zenner

Join Date:
Mar 2007
Posts:
22
Plugin Contributions:
0

Re: Linking directly to product with zen_href_link

Ok, I figured it out. In define_main_page.php before my html

<? define('NEW_VARIABLE_1', '<a href="' . zen_href_link(FILENAME_DEFAULT, 'cPath=xx') . '">'); ?>

Where "xx" is the category id desired.

Then, before the image I want to link

<? echo NEW_VARIABLE_1; ?>

following the image or link with </a>, of course.

There's nothing insecure about this, is there?

29 May 2013, 3:08 PM
#8
lhungil avatar

lhungil

Totally Zenned

Join Date:
Feb 2012
Location:
mostly harmless
Posts:
1,818
Plugin Contributions:
4

Re: Linking directly to product with zen_href_link

kgeoffrey:

Ok, I figured it out. In define_main_page.php before my html

<? define('NEW_VARIABLE_1', '<a href="' . zen_href_link(FILENAME_DEFAULT, 'cPath=xx') . '">'); ?>
> 
> Where "xx" is the category id desired.
> 
> Then, before the image I want to link
> 
> ```php
<? echo NEW_VARIABLE_1; ?>

following the image or link with </a>, of course.

There's nothing insecure about this, is there?
This should work (although it would be better to get the full cPath - for nested categories). You can directly use the output as well - skipping the define statement.

Categories (xx = category_id):

<?php
// Get the cPath
$cPath = zen_get_path($id);

// Strip out 0_ from top level cats
$cPath = str_replace('=0_', '=', $cPath); ?>
<a href="<?php echo zen_href_link(FILENAME_DEFAULT, $cPath); ?>" title="category link tooltip"><?php echo zen_get_categories_name(xx); ?></a>

Products (yy = product_id):

<a href="<?php echo zen_href_link(zen_get_info_page(yy), 'cPath=' . zen_get_generated_category_path_rev(zen_get_products_category_id(yy)) . '&products_id=yy'); ?>" title="product link tooltip"><?php echo zen_get_products_name(yy); ?></a>

You can of course substitute direct information for some of the functions calls if you have more than just the category_id / product_id available. You may also want to escape the returned product and category name just to be on the safe side.