Getting current Prestashop user in external site - codeigniter-2

In order for me to get a Prestashop user's cart, I first need to know who the user is in my external CodeIgniter application.
I have tried various attempts like the following: http://www.prestashop.com/forums/topic/204227-webservice-and-check-if-user-is-logged-in/ and http://www.prestashop.com/forums/topic/156218-solvedish-integrating-prestashop-into-a-pre-developed-website/ and even Prestashop: Session cookies & login and http://webilyst.com/prestashop-cookie-structure/
But I could not get it working. For some reason, the moment I include config.inc.php, it redirects to the shop - instead of allowing me to get the ID required.
My question: Any idea how to get this current user ID from PrestaShop in external epplication?
Edit 1
I am using CI 2.1.4 and PrestaShop 1.5.6.x.
Edit 2 Seems like the articles I have read is for an older version of PS. That code actually gets to a point where the Shop is being initialized, and once that is done, in Shop.php, the user is redirected to the shop. I do not want this to happen - I just want to find out who the current logged in user is.

You can get the current customer ID with the following code:
include($prestashopBasePath . '/config/config.inc.php');
$context = Context::getContext();
$customerId = $context->customer->id;
The reason why you are redirected is that you execute the script from a URL that is different from the shop URL defined in back-office -> Preferences -> Set shop URL. For example the shop URL is example.com/presta and your script is in example.com/other/script.php.
The solution is to move your script to the PrestaShop directory.

Related

Registered user cant login in joomla2.5 front end

While user logs-in in joomla2.5 site , it sets sessions for the user and in user.php it prints current user id,name and all. But after redirection everything lost and it shows as guest visiting page.
while user logs-in 4 sessions are created one for user and remaining 3 as guest.
We had this case before, and the login page had no www in the URL, but it was redirect to a page that had www. Could that be the reason?
If that isn't the reason, then worst case scenario you can just download Joomla (the version of the downloaded version of Joomla should match yours), and then extract it onto your website, and then remove the installation folder.

Magento link to admin area - edit customer profile

In Magento, when trying to generate a link from the front end to edit a customer, the link I generate is always redirecting me back to the dashboard of the admin area even though it looks correct.
I've tried it on multiple versions of Magento (and on both community and Enterprise), with the same result.
$adminUrl = Mage::helper('adminhtml')->getUrl('adminhtml/customer/edit/index',array('id'=>7));
$adminUrl2 = Mage::helper("adminhtml")->getUrl("adminhtml/customer/edit/id/".'7'."/");
This produces a url such as: /admin/customer/edit/id/7/key/f126e6cd7af2eb8cd068ff80fb512d4a/
Which appears to be right, but when it's clicked it sends me back to the dashboard of the admin area.
However, the following code works and does not redirect me to the dashboard:
$adminUrl = Mage::helper('adminhtml')->getUrl('adminhtml/catalog_product/edit', array('id' => 157990));
If I manually copy the url minus the key, and replace the key with a key that was generated by navigating through the admin area (i.e. by copying a working key from the navigation bar in my browser), it works - so I'm thinking it must be related to that somehow.
When you generate an admin URL from the frontend, Magento uses the form key from the frontend session. Then, when you click that link, Magento regenerates the admin URL key to compare against the key in the link, only this time, it uses the adminhtml form key. Since the form keys don't match, the hashed URL key doesn't match, and your link will not work. Magento's behavior at this point is to kick you back to the admin dashboard (or to the admin login page).
Any controller that inherits from Mage_Adminhtml_Controller_Action can allow certain actions to not require a admin URL key by adding them to the $_publicActions array.
For example, add into Mage_Adminhtml_CustomerController
public $_publicActions = array('edit');

How to set the default store (___store) with Magento, excluding front/home page

My current Magento website is requesting a store (via lightbox) when the user first arrives on the home page. The user will continue navigating the website and content will appear properly without any issues.
The problem is when they arrive on a sub-page of the website and the store has not been set previously by the user. This also impacts SEO.
Question: How do I set the default store, without affecting the lightbox that is appearing on the home page.
From the comments traded back and forth, it sounds like your default store isn't set properly. If you aren't using any index.php hacks to do with store view setting, you should be able to follow the following steps to resolve this:
Magento: Setting the default homepage / store when you have multiple stores

Magento migration from single store to multistore. Redirects

I have 1 website for now. Its URL is www.test.com, for example.
I want to create second website on the same domain adding store codes to URLs. So my URLs will be
www.test.com/first/
www.test.com/second/
But as I can see all my previous URLs will show 404 on their open. So if I open
www.test.com/product.html
it will show 404. It is not good because I loose my SEO.
How can I create redirects so if user opens
www.test.com/product.html
he will be automatically redirected to default website, like
www.test.com/first/product.html
Shall I have any issues with such redirects? (Like API will not work)
Or is it possible for URL
www.test.com/product.html
to show product from default website, if exists?
Magento has a very good system for SEO.
For Rewrite Management these are the steps:
1.Loginto Admin.
2.Move mouse over Catalog and you will find a drop down.
3 Select URL Rewrite management.
Catalog >> UrlRewrite Management
4.Then click on ADD URL Rewrite Button.
5.Then on next screen select custom from option provided
Create URL Rewrite : Select Custom
Now following important fields and values that should go:
Request Path (Old URL ) Target Path ( New URL ) redirect (Permanent 301).
Note : This approach will be good if you have few products but if you have too many product then some .htaccess rule is recommended.

Getting Magento user session values in joomla

In my site i have joomla 1.6 and magento 1.5, i would like to get the magento logged user session values in joomla to show as logged in .....
i have tried the following code :
'frontend'));
$session = Mage::getSingleton('customer/session', array('name'=>'frontend'));
print_r($session);
echo Mage::getSingleton('customer/session')->getCustomer()->getEmail();
echo Mage::helper('customer')->getCustomerName();
?>
But im getting empty values
Note : Sometimes i may get the customer details , if i tried to test the answer like delete the browser cookies and delete cache in magento ,again log in , it results as empty array
It's not that simple. Being logged in implies that there is an associated user account that you are logging in to. You will have all kinds of problems is you have a user register for an account in one system but not the other. What you need is a bridge that syncs the user account across both systems and provides a unified login.
http://extensions.joomla.org/extensions/e-commerce/e-commerce-bridges/9440

Resources