If this is your first visit, check our documentation. To post, register or login.

A strange idea

Started by ridgh on 17 Nov 2016, 10:55 AM · Views: 6,276

Results 1 to 5 of 5
17 Nov 2016, 10:55 AM
#1
ridgh avatar

ridgh

Zen Follower

Join Date:
Feb 2008
Posts:
107
Plugin Contributions:
0

Post #1 by ridgh

I think that it may be useful, and in any case, I wish to try it...
I wish to make a discount on a product from my site, and change the product every week.
However, I wish to hide the product up to logging in, and I mean that only logged customers will be able to see the product.
My idea was: placing a picture on the main page. Linking it to the "login" - this way the customer is redirected to the log in page.
This is easy, and can be done. Now, I am stuck: how can I made a condition that only customers who are logged in could see the product picture with the discount and with the coupon code?
I assume that I have to insert one, maybe more "if" or something similar - does anyone have any idea how it can be done?
Thank you in advance!

I'll never know how much I don't know...

17 Nov 2016, 2:27 PM
#2
mc12345678 avatar

mc12345678

Totally Zenned

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

Post #2 by mc12345678

Take a look at the code in the checkout_shipping page:
Includes/modules/pages/checkout_shipping/header_php.php

There is a section that verifies that the customer is logged on and redirects to the login. Portions of that could be applied where necessary.

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

17 Nov 2016, 4:48 PM
#4
ridgh avatar

ridgh

Zen Follower

Join Date:
Feb 2008
Posts:
107
Plugin Contributions:
0

Post #4 by ridgh

mc12345678:

Take a look at the code in the checkout_shipping page:
Includes/modules/pages/checkout_shipping/header_php.php

There is a section that verifies that the customer is logged on and redirects to the login. Portions of that could be applied where necessary.

Thank you very much mc12345678!!
I tried to find the best matching lines in header_php.php.
I found the following:
[QUOTE=]// if there is nothing in the customers cart, redirect them to the shopping cart page
if ($_SESSION['cart']->count_contents() <= 0) {
zen_redirect(zen_href_link(FILENAME_TIME_OUT));
}

// if the customer is not logged on, redirect them to the login page
if (!isset($_SESSION['customer_id']) || !$_SESSION['customer_id']) {
$_SESSION['navigation']->set_snapshot();
zen_redirect(zen_href_link(FILENAME_LOGIN, '', 'SSL'));
} else {
// validate customer
if (zen_get_customer_validate_session($_SESSION['customer_id']) == false) {
$_SESSION['navigation']->set_snapshot(array('mode' => 'SSL', 'page' => FILENAME_CHECKOUT_SHIPPING));
zen_redirect(zen_href_link(FILENAME_LOGIN, '', 'SSL'));
}
} /[QUOTE]
I assume that I have to use it, however as I am almost totally "ignorant", I must find how to use this text... Where should it be implanted? What changes / editing do I have to do?

My site is https://www.petrutech.com

Thank you!

I'll never know how much I don't know...

17 Nov 2016, 6:16 PM
#5
mc12345678 avatar

mc12345678

Totally Zenned

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

Post #5 by mc12345678

The code of importance there is the second if section

// if the customer is not logged on, redirect them to the login page
if (!isset($_SESSION['customer_id']) || !$_SESSION['customer_id']) {
$_SESSION['navigation']->set_snapshot();
zen_redirect(zen_href_link(FILENAME_LOGIN, '', 'SSL'));
} else {
// validate customer
if (zen_get_customer_validate_session($_SESSION['customer_id']) == false) {
$_SESSION['navigation']->set_snapshot(array('mode' => 'SSL', 'page' => FILENAME_CHECKOUT_SHIPPING));
zen_redirect(zen_href_link(FILENAME_LOGIN, '', 'SSL'));
}

Which is what validates if the user is logged in and "active" with the site.

That said, if I understand correctly, if customer is not logged in/valid display picture A with link to login. Else if logged in and valid then display special product with link to it. (mind you there are other things that need to be done to prevent someone from tripping over or getting to the product specifically.)

So yeah, I used "broken" English to describe the situation, just trying to get rid of the fluff to provide the essentials.

Anyways, could go in many of different locations, but the concept at hand is something similar to the following based on my understanding described above:

// if the customer is not logged on, redirect them to the login page
if (!isset($_SESSION['customer_id']) || !$_SESSION['customer_id'] || zen_get_customer_validate_session($_SESSION['customer_id']) == false) {
 // display "fake" image with login link.
 // here could use code taken from tpl_modules_main_product_image.php but the nuts and bolts would be like:
 echo '<a href="' . zen_href_link(FILENAME_LOGIN, '', 'SSL')  . '">' . zen_image('/* relative path to image to replace this commented out text */', 'products_name', width, height) . '</a>';

} else {
 //display product with product link.
}

With similar code from the first section put into the else area but instead to reference your special product.

Somewhat better than that is if you have a specific variable you plan to use on say your side box or category listing, then assign the above results to the variable and then echo the variable instead of having all that text in the applicable tpl_ file or similar for where you want it displayed.

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