Might I suggest "Keep Cart" (https://www.zen-cart.com/downloads.php?do=file&id=992) instead? That's a lot less cookie-weight and I've actually been keeping it updated!
Printable View
Might I suggest "Keep Cart" (https://www.zen-cart.com/downloads.php?do=file&id=992) instead? That's a lot less cookie-weight and I've actually been keeping it updated!
Well, I'm actually using both... keep cart to save un logged in carts, and remember me to automatically log back in if you have an account.
Lol, of corse I am. I use a LOT of your plugins.
Please consider the following scenario for a customer who has activated auto-login. They go to the store and select a product and checkout, so the checkout_success page is displayed. They close the browser or move to another site. After the zc session expires, they come back to the checkout_success page through browser history or other means. They are auto-logged in and the checkout success page is displayed. Is auto-login configured to deal with this scenario correctly? What if the customer goes back to an earlier stage of checkout?
In my case, I have an observer triggered by NOTIFY_HEADER_END_CHECKOUT_SUCCESS that gets executed when the customer comes back and the page is displayed again. The observer fails because some data is missing. So I don't need or want the observer to execute when this scenario is encountered, since the observer did its thing when the customer first checked out successfully. Five different customers have triggered this error in the last two months so it's a problem I need to fix.
Unfortunately, I can't figure out a way to detect this scenario in the observer. Any ideas would be appreciated!
What worries me in addition, is what happens if the customer comes back to other pages in the store and whether the core and custom code will work.
If auto-login is not chosen by the customer, and the scenario is followed, the "Whoops, the session has expired" page is displayed, so I feel fairly certain nothing incorrect will occur for those customers.
Thank you for any advice/help you can provide.
Dave
zc157c, php 8
I'm looking for a general solution that would detect the scenario regardless of the page returned to, and not re-execute any damaging code. I've already tested for the missing data (a custom session variable) in the observer and bypassed primary observer logic, so there are no myDEBUG messages. There is an email sent to me when the missing session data is detected with debug data. So I'm not sure what good the observer code will do.
What I was thinking of was a test on the "came from page", or a test on the current date-time relative to the order date_purchased date-time. In the case of returning to the checkout_success page, the "came from page" must be the order_confirmation page, otherwise the scenario was encountered. The time test would see if the time difference was less than say 20 minutes or else the scenario was encountered. But those are just preliminary thoughts, and I'm not sure how to get the "came from page" or even if it's possible.
Info on the observer...the observer automatically sets the order status and sends the order status update email for certain types of orders based on a custom session variable $_SESSION['order_case'] that's set elsewhere. It also tailors some text in the order status update email based on what was ordered. The idea was to relieve the admins from setting status and sending emails when they could be sent automatically at order time. The observer is too large to include as attachment to this site.
Dave
Another possible idea would be to redirect to the home page or login page on auto-login, regardless of what page was requested by the browser. This could potentially avoid all negative impacts of coming back to the site on a "bad" page. This would need to be a change (I believe) to the auto-login add-on.
Dave
Since manual login success loads the home page, I've decided to load the home page on auto-login too, even if the customer entered the store with a bookmark, browser history item, or restored a previous (browser) session. I inserted the following line after the update to the customers_info table in function checkRememberCustomer in file includes/classes/observers/class.remember_me_observer.php.
I have tested the code with and without products in the cart and all appears to work properly.Code:if (isset($_GET['main_page']) && $_GET['main_page'] !== 'index') $_GET['main_page'] = 'index'; // edit to force home page to load on auto-login
Dave
note for php 8.3:
to fix a ton of "--> PHP Deprecated: Creation of dynamic property remember_me_observer::$XXXXXX"
errors I added the following to /includes/classes/observers/class.remember_me_observer.php at about line 23:
I won't swear it's right, but it does seem to work (in zen 2.0.1 even) and made the errors stop.Code:public $enabled,
$checkbox_default,
$debug,
$logfilename,
$customer_remembered,
$customerIsLoggedIn,
$path,
$domain;
v2.1.0 of "Remember Me" is now available for download: https://www.zen-cart.com/downloads.php?do=file&id=332
This release contains changes associated with these GitHub issues:
#20: Offer "Remember Me" on OPC's guest-to-account conversion.
#23: Redirect to home-page after customer's remembered.
#24: Correct PHP deprecations.
#25: Add $_SESSION['customer_email_address'] when a customer's remembered.
#26: Drop support for Zen Cart versions prior to 1.5.8 and PHP versions prior to 7.4.
#27: Don't remember admin 'Place Order' logins.
The checkbox is not displayed (or not visible) with version 2.1.0 Remember Me, zen cart v1.5.8a, ZCA_bootstrap_template v3.7.5, and OPC v2.5.4 in every expected location. The Remember Me? label is displayed as expected. There are no error logs. I can not find any CSS that would hide the checkbox. An image from returning customer login is attached, as well as the page source html for the form (edited to remove domain and security token, and formatted (indented) for ease in understanding. Any suggestions would be appreciated.
Thank you!
Dave
The html file in the previous post is not readable for some reason. The file is reproduced below:
DaveCode:<form name="loginForm" action="https://my_domain/index.php?main_page=login&action=process" method="post" id="loginForm">
<input type="hidden" name="securityToken" value="blah-blah">
<div class="opc-label">
<label for="login-email-address">Email Address:</label>
</div>
<input class="form-control" type="email" name="email_address" value="" size="18" id="login-email-address" autofocus placeholder="*" required>
<div class="opc-label">
<label for="login-password">Password:</label>
</div>
<input class="form-control" type="password" name="password" size="18" id="login-password" autocomplete="off" placeholder="*" required>
<br>
<input class="custom-control-input" type="checkbox" name="permLogin" value="1" checked="checked" id="permLogin">
<label class="checkboxLabel" for="permLogin" title="Tick this box to be automatically logged in on your next visit. Note: This will place create a cookie in your current browser that can only be read by this website.">Remember me?</label>
<div id="opc-pwf">
<a href="https://costore-158a.local/index.php?main_page=password_forgotten">Forgot your password?</a>
</div>
<div class="text-right">
<button type="submit" class="btn button_login">Sign In</button>
</div>
</form>
Yep, checkbox type inputs require some special HTML; see this W3Schools link for additional information: https://www.w3schools.com/bootstrap4...rms_inputs.asp
Got it! I changed function create_checkbox starting on line 210 in class.remember_me_observer.php from:
to:PHP Code:
public function create_checkbox()
{
if (!$this->enabled) {
return '';
}
$return_value =
'<br>' .
zen_draw_checkbox_field ('permLogin', '1', $this->checkbox_default, 'id="permLogin"') .
'<label class="checkboxLabel" for="permLogin" title="' . TEXT_REMEMBER_ME_ALT . '">' . TEXT_REMEMBER_ME . '</label>';
return $return_value;
}
The pt-2 and pb-2 are for spacing.PHP Code:
public function create_checkbox()
{
if (!$this->enabled) {
return '';
}
$return_value =
'<div class ="custom-control custom-checkbox pt-2 pb-2">' .
zen_draw_checkbox_field ('permLogin', '1', $this->checkbox_default, 'id="permLogin"') .
'<label class="custom-control-label" for="permLogin" title="' . TEXT_REMEMBER_ME_ALT . '">' . TEXT_REMEMBER_ME . '</label>' .
'</div>';
return $return_value;
}
Dave
I'm having trouble with Remember Me restoring products in the cart when the customer comes back to the site. I'm not sure what the customer should see. For example, a customer enters their email address, password and clicks Remember Me to log in. Then a product gets added to the cart. For whatever reason, the site is left (without logging out). After the session has expired, the customer comes back to the site. The home page is displayed and the customer is logged in. I would expect the shopping cart link to be displayed in the header, and on clicking it, the product previously left in the cart would appear. But there is no way to get to the shopping cart page except by adding another product. But when doing so, only the just added product is present.
After leaving the site again, I checked the customer's basket in the database, and both products are present. The cookie expiration time is set for 400 days.
What am I missing or forgetting?
Thank you.
Dave
zc 1.5.8a, latest versions of Remember Me, Bootstrap template, and OPC.
In trying to debug restoration of cart contents, I set PERMANENT_LOGIN_DEBUG to true in class.remember_me_observer.php and added a trigger_error statement to log $this->customer_remembered in function __construct() after $this->customer_remembered is initialized to false. I also added trigger_error statements to log the same variable in function checkRememberCustomer just after $this->customer_remembered is set to true, and also at the start of function restoreRememberedCart() before any tests. I suspected a potential timing issue.
The remember me debug log showed that cartIdSet was true in the cookie when returning to the site with a product placed in the cart previously before leaving the site. It was recorded first. Next, an error log showed that $this->customer_remembered was false in function __construct(), and true in function checkRememberCustomer. Finally, a third error log was recorded about 0.3 seconds later showing that $this->customer_remembered was set back to false in function __construct(), and false in function restoreRememberedCart.
So although the processing in function checkRememberCustomer correctly set $this->customer_remembered to true, subsequent processing reinitialized it to false, preventing function restoreRememberCart from restoring the cart.
I hope this helps figuring out what needs to be fixed.
Dave
v2.1.1 of "Remember Me" is now available for download: https://www.zen-cart.com/downloads.php?do=file&id=332
This release contains changes associated with these GitHub issues:
#31: Use now-current PHP hash instead of md5 for various string hashes.
#28: Remember me? checkbox not visible when using Bootstrap template.
#32: A remembered customer's cart isn't also remembered.
#33: Correct interoperation with square_webPay (and other) payment modules when a customer is 'remembered'.
#34: Use zc158+ language-file array-format.