How can I redirect different user groups to different pages in Magento ?
what I want to do is to assign a category to each customer group to redirect the user to it on login.
Thanks a lot.
I have not tried this. I think you need to do the following on the customer_login event:
$session = Mage::getSingleton('customer/session');
$category = // A category object based on $session->getCustomerGroupId()
$session->setBeforeAuthUrl($category->getUrl());
Go to /app/code/local/MagentoPycho/Customer/controllers/AccountController.php and replace this:
$session->setBeforeAuthUrl(Mage::helper('customer')->getAccountUrl());
with this:
$groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
if($groupId == 5) {
$session->setBeforeAuthUrl('http://google.com');
} else {
// Set default URL to redirect customer to
$session->setBeforeAuthUrl(Mage::helper('customer')->getAccountUrl());
}
Be sure to put your Group ID instead of the "5" and your redirect URL instead of google.com.
I just tried it.
How about this for an approach:
Consider starting with an existing module such as:
http://www.magentocommerce.com/magento-connect/MagePsycho/extension/3763/custom_login_redirect
Then adding your own logic. For the group name of a customer you can try this:
$groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
$group = Mage::getModel ('customer/group')->load($groupId)->getCode();
If you then have your categories named as per your groups you can do a redirect to http:// + base_url + $group therfore removing the need to explicitly work out what category page to load.
In order to redirect the customer as per customer group, there is a commercial extension:
http://www.magepsycho.com/custom-login-redirect-pro.html
really worths trying. FYI many merchants are using this module for their magento sites.
Happy e-commerce!!
Regards
Related
i'm trying to get address from checkout page for a registered customer. on the checkout page I have a form that a user has to fill in with address info. Now the trick is to get that address displayed on the account dashboard.
I did try to get the address on the quote on .phtml here is my code
$quote = Mage::getSingleton('checkout/session')->getQuote();
$quote_billing = $quote->getBillingAddress();
echo $quote_billing
Is there any other possible way to get and address from a session
Try:
$customer = Mage::getSingleton('customer/session')->getCustomer();
foreach ($customer->getAddresses() as $address) {
Zend_Debug::dump($address->getData());
}
You could also do what you did and just do getData() on the $quote_billing. That should provide you with the data that you need to pull.
I have the following route
Route::get('compare/{user_id}/{compare_id}', 'CompareController#index');
Since only the owner or members of the working group should have access to this site, I need to filter it. But how can I add the user_id and the compare_id in to the filter?
There's a couple of ways you could do this. Firstly you could just use Request::segment() to fetch each of the required segments of the URI.
A second and better solution is to get the current route with Route::getCurrentRoute().
Route::filter('example', function()
{
$route = Route::getCurrentRoute();
$user_id = $route->getParameter('user_id');
$compare_id = $route->getParameter('compare_id');
});
I've got an instance of magento 1.7 CE running, and a second site that calls it via the SOAP api v2 from php.
I can't seem to find out how to add an array of products (given by productId or SKU) to a cart and then redirect to the cart page.
I've tried adding the items to the cart via shoppingCartProductAdd, which works, however I can't find out how to then open that cart back on magento.
I've also tried directly formulating a link that passes products via GET, however this only works for a single product ( checkout/cart/add?product=[id]&qty=[qty] ), for my purpose a whole array of products needs to be passed before redirecting to magento.
Any ideas?
Figured it out.
Basically one can use a link shaped like
http://example.com/checkout/cart/add?product=1&related_product=2,3,4,5
To fill the shoppingcart with products with id 1 .. 5 and then go to the cart in magento.
In my case I generated the link like this
if(!isset($session)) {
$client = new SoapClient('http://example.com/index.php/api/v2_soap?wsdl=1');
$session = $client->login('username', 'Qq314asdgUScrncfD7VMb');
}
if(!isset($cart)) {
$cart = $client->shoppingCartCreate($session);
}
$ids = array();
foreach($items as $id) {
$result = $client->catalogProductInfo($session, $id." ", null, 'sku');
$ids[] = $result->product_id;
}
$this->Session->delete('Cart');
$this->redirect('http://example.com/checkout/cart/add?product='.$ids[0].'&related_product=' . implode(array_slice($ids, 1), ','));
What is the correct way to handle generating urls in magento when urls have .html suffixes.
For example, to get the following product url:
category/product.html
You cannot simply do Mage::getUrl('mycategory/myproduct.html') or Mage::getUrl('mycategory/myproduct')
but instead
Mage::getUrl() . 'mycategory/myproduct.html'
You — dont?
The point of having a getUrl method is you provide the abstract, behind the scenes module/controller/action portions of the URL, and then the system handles generating actual HTML urls for you.
Best way to get the product url:
$productId = ***;
$productUrl = Mage::getBaseUrl().Mage::getResourceSingleton('catalog/product')->getAttributeRawValue($productId, 'url_key', Mage::app()->getStore()).Mage::helper('catalog/product')->getProductUrlSuffix();
If you want to get a product url, you should use the following
$product = Mage::getModel('catalog/product')->load($productId);
echo $url = $product->getProductUrl();
If you just have created the product from the backend, you need to get this url just after the save process, you have to get it by using the event catalog_product_save_after, creating an observer class and there you can get the product object thanks to $product = $observer->getEvent()->getProduct();
I'm attempting to check if the administrator is logged in from an observer. The problem is that while this is easy to do when viewing the admin module, viewing the frontend is another story.
There are several similar questions, but unfortunately none of them provide a working solution for Magento 1.6.2.
I wasn't able to successfully get isLoggedIn() to return true in the admin/session class. I also found out that there is a cookie for both frontend and adminhtml, which may help.
The accepted answer in this related question seems to suggest this may not be possible:
Magento - Checking if an Admin and a Customer are logged in
Another related question, with a solution that didn't help my specific case:
Magento : How to check if admin is logged in within a module controller?
It is possible. What you need to do is switch the session data. You can do this with the following code:
$switchSessionName = 'adminhtml';
if (!empty($_COOKIE[$switchSessionName])) {
$currentSessionId = Mage::getSingleton('core/session')->getSessionId();
$currentSessionName = Mage::getSingleton('core/session')->getSessionName();
if ($currentSessionId && $currentSessionName && isset($_COOKIE[$currentSessionName])) {
$switchSessionId = $_COOKIE[$switchSessionName];
$this->_switchSession($switchSessionName, $switchSessionId);
$whateverData = Mage::getModel('mymodule/session')->getWhateverData();
$this->_switchSession($currentSessionName, $currentSessionId);
}
}
protected function _switchSession($namespace, $id = null) {
session_write_close();
$GLOBALS['_SESSION'] = null;
$session = Mage::getSingleton('core/session');
if ($id) {
$session->setSessionId($id);
}
$session->start($namespace);
}
Late Answer but if as I found it on google:
This it not possible.
Why? Because the default session name in the frontend is frontend and the session name in the backend is admin. Because of this, the session data of the admin is not available in the frontend.
have you tried this :
Mage::getSingleton('admin/session', array('name' => 'adminhtml'))->isLoggedIn();
how about this ( I am not sure it will work or not )
require_once 'app/Mage.php';
umask(0);
$apps = Mage::app('default');
Mage::getSingleton('core/session', array('name'=>'adminhtml'));
$adminSession = Mage::getSingleton('admin/session');
$adminSession->start();
if ($adminSession->isLoggedIn()) {
// check admin
}