1

Ok i cant figure this out at all. I have searched and i cant find anything either. Whats the best way to add a new page to the account section. I am trying to integrate a support ticket system into a magento account page i.e. so the user must be logged in and registered to use this feature. i can get this to work using a cms page and custom page layout. but then how do i set this custom cms page to only work for logged in users?

Also doing it this way this is showing the category menu and not the account menu. How can i get the my account menu to show instead? or is there a better way of doing this? Im new to magento and im really stuck and cant figure this out so any help would be appreciated.

Im running magento 1.7.0.2 community edition.

JSweete
  • 269
  • 1
  • 7
  • 17

3 Answers3

1

If I understand you correctly, just check to see if the customer is logged in, but in order to use PHP you're going to have to use the teplating system and create a module, or generate your own "stand alone page" If you go the module route:

if ($this->helper('customer')->isLoggedIn()){
   //show page contents or do whatever  .. 
}
else{
header( 'Location: http://www.yoursite.com/customer/account/login/' ) ;
}

is all you'll need. IF you go the stand alone route:

//LOAD MAGENTO
require_once 'YOUR_PATH_TO_MAGENTO/app/Mage.php';
umask(0);
Mage::app('YOUR_WEBSITE_CODE', 'website');

//GET SESSION DATA
Mage::getSingleton('core/session', array('name'=>'frontend'));
$session = Mage::getSingleton('customer/session', array('name'=>'frontend'));
$customer_data = Mage::getModel('customer/customer')->$session->id);

//CHECK IF LOGGED IN
if($session->isLoggedIn()){
echo 'Welcome ' . $customer_data->firstname . " " . $customer_data->lastname;
} else {
echo "Access Denied: Sorry, but this page is for registered members only.";
exit;
}

Hope that helps

Zak
  • 6,976
  • 2
  • 26
  • 48
  • thanks, yes thats part of it how do i set it to show the my account menu also? is there some way of just saying this is an account page to set both features? – JSweete Mar 19 '13 at 02:09
  • I believe you are going to have to call the my account NAV block in rather than calling the page a "my account" page if that makes any sense. It should be as straight forward as calling the left nav on any other page – Zak Mar 19 '13 at 13:20
-1

For any action there is a controller and action function.

So for your new feature you define an action.Make sure this action value is in URL.

Now within your controller add this action function

myAction()
{
    if ($this->helper('customer')->isLoggedIn()){
   //show page contents or do whatever  .. 
    }
    else{
    header( 'Location: http://www.yoursite.com/customer/account/login/' ) ;
    }
}  
Oscprofessionals
  • 2,161
  • 2
  • 15
  • 17
  • Funny ... Looks exactly like the top portion of my answer but with a function wrapped around it ... Maybe mention that next time? Copying and pasting an answer that's already on the page and wrapping it in a function is hardly original, and is somewhat scandalous. Furthermore, there is no need for the "action", and said "action" doesn't make any sense given the scope ie `//show page contents or do whatever ..`. – Zak Mar 19 '13 at 13:15
  • well I explained that a need to have in URL My aswell so this function is called.Thats the reason I pasted code within that function.So original person who has requested can easily move further.Its not just a copy paste. – Oscprofessionals Mar 19 '13 at 17:18
  • For any action there is a controller and action function. So for your new feature you define an action.Make sure this action value is in URL. Now within your controller add this action function. read what additional explanation was posted along with code. – Oscprofessionals Mar 19 '13 at 17:21
-1

Although both of the answers above might have sufficed for the question posted, just for a note, it is surely not the correct way to work with Magento, a better understanding of how this can be achieved in the way according to magento practices, I think this tutorial from Alan Stormis a great place, however there is some problem with the preDispatch method in that blog, for which I think it might be better alternative:

public function preDispatch() {
        parent::preDispatch();
        if (!Mage::getSingleton('customer/session')->authenticate($this)) {
                $this->setFlag('', 'no-dispatch', true);
        }
    }

Which I got from here. In Alan's blog, If a customer is already logged in and try to go the custom account page, he is redirected to the homepage(It did in my case.)

Prateek
  • 274
  • 1
  • 4
  • 18
  • Dear "downvoter", please add a comment as to why the answer deserves a downvote, so that I can improve that next time I post something. – Prateek Oct 13 '15 at 06:12