how can I redirect the customers after logout to default store view in magento?
In logout I redirect them another store view.
I know it's not elegant, but the easiest method I have found is to copy and modify the template file at app/design/frontend/base/default/template/customer/logout.phtml to your own theme directory.
Specifically this line:
<p><?php echo Mage::helper('customer')->__('You have logged out and will be redirected to our homepage in 5 seconds.') ?></p>
<script type="text/javascript">
//<![CDATA[
setTimeout(function(){ location.href = '<?php echo $this->getUrl() ?>'},5000);
//]]>
</script>
By modifying location.href url and even the timeout you can point the user to anywhere just after logout. E.g.:
<script type="text/javascript">
//<![CDATA[
setTimeout(function(){ location.href = '<?php echo $this->getUrl('*/*/login') ?>'},500);
//]]>
</script>
Again, it's not elegant, but it should be a quick enough redirect that the quick hop on the page will then shove them to another url, in the above example, back to the login screen.
Unfortunately there's not a convenient event hook to manipulate the logout redirect location.
Mage_Customer_AccountController::logoutAction() sets a redirect to ::logoutSuccessAction() on the response object after the customer_logout event is dispatched, and it's the rendering of the customer/logout.phtml template which uses PHP to set echo a javascript param to redirect to the homepage with no OOB possibility to pass an arg for an alternate JS-based redirect.
I think the cleanest solution would be to observe controller_action_postdispatch_customer_account_logout, grab the controller object, and overwrite the location header using the response object's setRedirectWithCookieCheck() method:
public function logoutRedirect($obs)
{
$obs->getControllerAction()
->setRedirectWithCookieCheck(/* your URL param(s) */);
}
Write the following method in Your Model > Observer .
public function customerLoggedOut(Varien_Event_Observer $observer)
{
$observer->getControllerAction()
->setRedirectWithCookieCheck(CustomUrl);
}
Customurl is a url on which you want to redirect after Logged Out.
If you want complete solution for custom url redirection for your ecommerce website after logged In, Logged Out and Registration. Custom Redirection extension can help you. Click on link to get extension. http://www.magentocommerce.com/magento-connect/custom-redirection.html
Related
I have a custom template file. There i am displaying a message. So after 10 second from the page load, i need to redirect to the admin login page automatically. I tried $this->_redirect('');. But that did not work.
Can anyone help me please. Thank You.
<script type="text/javascript">
setTimeout(function(){
window.location='<?php echo Mage::getBaseUrl().(string)Mage::getConfig()->getNode('admin/routers/adminhtml/args/frontName')?>';
}, 10000);
</script>
Put this script in your file it will works for you
The snippet below will resolve your question. If your site uses jquery, you may just paste this in your template. Otherwise, you need to include jquery in your Magento header.
<script>
jQuery(document).ready(function(){
setTimeout(function() { document.location = '<?php echo Mage::getUrl('adminhtml'); ?>'; }, 10000);
});
</script>
I building a very simple app with Laravel4 and so far i have managed to set up PHPMailer to work with a contact form, the users fill in their details and send me an email, normal stuff, everything works fine.
After the user sent the email successfully, he is redirected to the home page via
if($m->send()) {
header('Location: /path/to/home/');
die();
}
Now what i need is a success message that appears at the top of the homepage if the user has been redirected after a successfully sent email.
I have a div with .success class sitting on top of my home page, absolutely positioned out of view, with a negative Y value.
I tried pulling it down after on $m->send() like so:
if($m->send()) {
header('Location: /path/to/home/');
echo "<script type='text/javascript'>
$('.success').animate({
top: 0
}, 2000);
</script>";
die();
}
but it didnt work. In fact, nothing i echo after the header() has any effect.
What can I do?
Thank you guys!
This is simple HTTP - when you set the Location header, it's telling the browser to leave the page you're on and go somewhere else - anything that happens afterwards (like that little JS snippet) will never reach the browser. You need to put that snippet on the page you're redirecting to, not on this one.
I solved the problem after realizing that you can't use jquery on the document before you actually link the jquery lib in.
So, in my phpmailer config file, I set $_SESSION['success'] = true before i redirect with the header('Location: /path/to/home/'); , and then, on the Homepage, the page I wanted the success message to be displayed on, I added this bit of code (AFTER linking the jQuery library):
<?php
if(isset($_SESSION['success']) && $_SESSION['success'] == true ) {
?>
<script type='text/javascript'> $('.success').animate({top : 0}, 'normal').delay(3000).animate({top : -57}, 'normal');</script>
<?php
} else {
$_SESSION['success'] = false;
}
?>
I don't know if this is a good practice but it does work.
I also had to session_start(); on my Homepage (obviously).
Hope this helps anyone in the same situation!
I want to redirect user to home page if shopping cart is empty, is this possible to do from admin panel, if yes please guide, otherwise I have to redirect by controller overloading.
I don't think you can do this from the admin, but you could try
In app/design/frontend/default/your-theme/template/checkout/cart/noItems.phtml add (this may not be the best solution but does work)
<?php Mage::app()->getResponse()->setRedirect($this->getContinueShoppingUrl()); ?>
Create an observer (try controller_action_predispatch_checkout_cart_delete) that check if your cart is empty then redirect see to the home page
(for redirecting from observer see)
Using javascript and timer so that the user will see that there cart is empty before redirecting to home page (see time delayed redirect?) Add code below to noItems.phtml see solution #1
<script>
setTimeout(function () {
window.location.href = "<?php echo $this->getContinueShoppingUrl() ?>"; //will redirect to your blog page (an ex: blog.html)
}, 2000); //will call the function after 2 secs.
</script>
Add this to your functions.php
function cart_empty_redirect_to_shop() {
global $woocommerce;
if ( is_page('cart') and !sizeof($woocommerce->cart->cart_contents) ) {
wp_redirect( get_permalink( wc_get_page_id( 'shop' ) ) ); exit;
}
}
add_action( 'wp_head', 'cart_empty_redirect_to_shop' );
The above will redirect an empty cart to the shop page.
I have tried window.location.href without doing any submission it works
window.location.href="http://www.google.com";
But how about if I have to do a post submission, then if the data is valid, I would like to perform a redirect using window.location.href Can somebody explain to me how this can be done? Thanks!
If you're using PHP you can simply use a header.
<?php header("Location: http://google.com"); ?>
As for doing the redirect with just JavaScript...
<script> window.location = 'http://google.com'; </script>
can anyone help with the following issue.
Once a customer in onepagecheckout clicks the „order now“ button I would like to show a custom page for 2-3seconds and the forward to either payment provider or thankyou page.
Currently I have an observer on
"checkout_type_onepage_save_order_after"
calling my custom model/method.
In this model/method I do a...
$this->_forward($url); //with $url being a custom controller/method
$res->sendResponse();
exit;
In this custom controller/method I load and render my layout the show my *.phtml – file and then...
$url = Mage::getUrl("???");
$this->_forward($url);<
$res = Mage::app()->getResponse();
$res->sendResponse();
And this is where I am lost (or maybe I am totally wrong on the whole thing).
First of all, the controller does not forward at all (whatever url or controller is given).
Second how do I know where to redirect to (if its payment provider or thank you page)
Is there a better way to „simply“ load a *.phtml after user clicks „order now“ and before he is redirected to either thank-you-page or payment-provider.
The phtml is user to load tracking code which must be placed and loaded in html.
I suggest instead that you consider doing the following:
Adding a javascript action to the place order button in the order review which will effectively issue an in-screen modal or popup
The click issuing the modal will set a timeout of 3000ms (3 seconds) which will then fire the order submit Ajax that Magento uses. This is important as the order submit and the redirect are dependent on AJAX.
This example jQuery script (requires adding jQuery to your Magento site, which is not standard) would set the timeout, issue the modal / popup I would add this code to the following file:
/app/design/frontend/[your theme]/template/checkout/onepage/review/button.phtml
Add a class to this line and remove the onclick event so you can capture the click and interject your timeout:
<button type="submit" title="<?php echo $this->__('Place Order') ?>" class="btn-place-order button btn-checkout"><span><span><?php echo $this->__('Place Order') ?></span></span></button>
<script>
$('#myform').submit(function(event) {
event.preventDefault();
//issue the popup - put your html in here:
var html = '<div style="position:absolute; top:0; left:0; min-height: 100%; width: 100%; background-color:white;"><h1>I am a popup</h1></div>';
$('body').append(html);
var self = this;
window.setTimeout(function() {
review.save();
}, 3000);
});
</script>