Code Monkey home page Code Monkey logo

prestashopbridge's Introduction

prestashopBridge

Allow Prestashop to work nicely with your existing PHP Application (Drupal, Symfony, Joomla, Wordpress, ...).

Use your authentication mechansim of choice with prestashop (SSO, Oauth, 2-factor, ... )

Benefits:

  • customers don't have to create an account in Prestashop
  • customers authenticate only in your application

Features:

  • Login / Logout customers
  • Create customers
  • Create carts

Requirements:

  • should be installed in the same server than prestashop (because some Prestashop code is loaded with include() )
  • should be served from the same domain:port than Prestashop (because of the auth cookie)

En Français

Ce projet vous est utile si vous voulez que :

  • vos clients n'aient qu'un seul mot de passe pour votre site et pour votre boutique
  • vos que vos clients ne s'authentifient que par votre site
  • utiliser une autre méthode d'authentification (2-facteurs, OAuth, CAS, ...) que celles proposent par Prestashop.

Fonctionnalités :

  • connecter un client
  • déconnecter un client
  • créer des clients dans la base de prestashop
  • créer des commandes (optionnellement avec des références)

Contraintes :

  • Doit être installé sur le même serveur que Prestashop (car utilise quelques fonctions internes de prestashop - via include() )
  • Doit être servi depuis le même nom de domaine / port que Prestashop (à cause du cookie d'authentification)

Installation

In your composer.json:

{
	"require": {
		"hpar/prestashop-bridge": "dev-master"
	},
	"repositories": [{
		"type": "vcs",
		"url": "https://github.com/hparfr/prestashopBridge.git"
	}]
}

Example

In a symfony application:

<?php 

namespace Acme\DemoBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;

use Hpar\PrestashopBridge\PrestashopBridge;

class PrestashopBridgeExampleController extends Controller
{
	public function loginAction()
	{
		if (!$this->get('security.context')->isGranted('ROLE_USER')) {
			throw new AccessDeniedException();
		}

		$prestaBridge = new PrestashopBridge('/path/to/prestashop/', 1);

		$user = $this->getUser(); //get connected user

		if (!$prestaBridge->userExist($user->getEmail())) //if user exist in prestahop database
			$prestaBridge->createUser(
				$user->getEmail(),
				$user->getLastName(),
				$user->getFirstName()
			);

		$prestaBridge->login($user->getEmail());

		return $this->redirect('http://prestashop_url/');
	}
}

prestashopbridge's People

Contributors

hparfr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

prestashopbridge's Issues

Undefined Cache:: methods

Hi,

I'm trying out your library as it sounds exactly like what I need. However, i can't seem to get past the first instance call. This is the situation:

I have a Concrete5 installation in my root folder
My Prestashop installation resides in a /shop subfolder
I can install everything via composer no problem
Afer including the various setup lines (autoload, USE, new call to class), when i call my login function i get a series of "undefined method" php errors, specifically

  • Call to undefined method Cache::isStored() (this I can bypass by activating Prestashop Cache apparently)
  • Call to undefined method Cache::getInstance()

And that's where I'm stuck. I'd really appreciate if you would help me solve this.

Thank you

How it can be Used ?

it seems to be usefull, but is there any detailed recommendations on how it can be istalled and used !
Thanks

Can I use this without Synfony?

I have my own PHP/MySQL application, and i would know if it'a possible use your bridge, and if you can put any example how to use with pure PHP application.

Thanks,

Works in wamp but not in live server

Hello!
I have a custom php/mysql application (not symfony or any other framework)

I managed to make it work in wamp server but in live server (linux) it throws the following error:

mod_fcgid: stderr: PHP Fatal error: Class 'Hpar\ \PrestashopBridge\ \PrestashopBridge' not found in /var/www/vhosts/exaample.com/httpdocs/demo/prestaconnect.php on line 10, referer: http://demo.example.com/index.php

I think it is because for some reason in linux the slashes are duplicated. Or is it for some other reason?How can I solve it? I am desperate...

I attach the code:

`require 'Hpar/PrestashopBridge/vendor/autoload.php';
use Hpar\PrestashopBridge\PrestashopBridge;

$email = "[email protected]";
$lastname = "Doe";
$firstname = "John";
$prestaBridge = new PrestashopBridge('/var/www/vhosts/example.com/httpdocs/eshop/', 1);

if (!$prestaBridge->userExist($email))
$prestaBridge->createUser($email, $lastname, $firstname);

$prestaBridge->login($email);
return $prestaBridge->redirect('http://example.com');

?>`

thank you

Question about symfony/fosuserbundle/prestashop integration

Hello @hparfr ,

Nice to see I am not the only one to face the authentification problem with an external app than prestashop.

Please take 30s to answer my question :

Context :

  • I have a symfony app where user are registered (it handle a small social network and load all the templates).
  • Under the symfony project, we have a small prestashop shop

We want to be able to register and login (as a user) only from symfony:

  • Does you code will take in charge login/updating/registering user and then allow the user to navigate on the (presta)shop website

Thanks for you time, it would be really helpfull.

Baptiste

Integration with laravel

Hi,

I've a clean install of a laravel 5.1 app with a clean prestashop 1.6.1.0 (id_shop=1) installed into laravel public dir. Everything is running in an homestead box. I wrote a controller as following:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;

use Hpar\PrestashopBridge\PrestashopBridge;
use Auth;

class PrestashopController extends Controller
{

    public function loginAction()
    {
        if (Auth::guest())
        {
            return "Access Denied";
        }

        $prestaBridge = new PrestashopBridge('/home/vagrant/test/public/prestashop', 1);

        $user = \Auth::user(); //get connected user
        //if user exist in prestahop database
        if (!$prestaBridge->userExist($user->email))
            $prestaBridge->createUser(
                $user->email,
                $user->lastname,
                $user->firstname
            );

        $prestaBridge->login($user->email);

        return $this->redirect('http://test.dev/prestashop/');
    }
}

Then I put a sample route in routes.php:

Route:get("gopresta", 'PrestashopController@loginAction');

If I login in my laravel app and then point to gopresta route I receive this error:

ErrorException in Repository.php line 364: call_user_func_array() expects parameter 1 to be a valid callback, class 'Illuminate\Cache\FileStore' does not have a method 'isStored'

Here the call stack:

in Repository.php line 364
at HandleExceptions->handleError('2', 'call_user_func_array() expects parameter 1 to be a valid callback, class 'Illuminate\Cache\FileStore' does not have a method 'isStored'', '/home/vagrant/test/vendor/laravel/framework/src/Illuminate/Cache/Repository.php', '364', array('method' => 'isStored', 'parameters' => array('objectmodel_def_Shop')))
at call_user_func_array(array(object(FileStore), 'isStored'), array('objectmodel_def_Shop')) in Repository.php line 364
at Repository->__call('isStored', array('objectmodel_def_Shop'))
at Repository->isStored('objectmodel_def_Shop')
at call_user_func_array(array(object(Repository), 'isStored'), array('objectmodel_def_Shop')) in CacheManager.php line 310
at CacheManager->__call('isStored', array('objectmodel_def_Shop')) in /home/vagrant/test/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php line 210
at CacheManager->isStored('objectmodel_def_Shop') in /home/vagrant/test/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php line 210
at Facade::__callStatic('isStored', array('objectmodel_def_Shop')) in /home/vagrant/test/public/prestashop/classes/ObjectModel.php line 1748
at Cache::isStored('objectmodel_def_Shop') in ObjectModel.php line 1748
at ObjectModelCore::getDefinition('Shop') in ObjectModel.php line 206
at ObjectModelCore->__construct('1', null, null) in Shop.php line 131
at ShopCore->__construct('1') in Shop.php line 393
at ShopCore::initialize() in config.inc.php line 105
at include('/home/vagrant/test/public/prestashop/config/config.inc.php') in PrestashopBridge.php line 42
at PrestashopBridge->loadPrestaKernel() in PrestashopBridge.php line 21
at PrestashopBridge->__construct('/home/vagrant/test/public/prestashop', '1') in PrestashopController.php line 25
at PrestashopController->loginAction()

Any advice on the cause of this error?

Thank you in advance.

Problems with addToCurrentCart

Hi,

I`m using the function addToCurrentCart() to add aproduct, but i have an error. PHP Fatal error: Call to a member function getProductCustomization() on a non-object in /var/www/prestashop/vendor/hpar/prestashop-bridge/PrestashopBridge.php on line 140

I debbug line by line and when create the context $ctx = \Context::getContext(); in this function, i see that the cart is empty.

That's what I'm doing wrong?

This is my code where I use addToCurrentCart() function:
require 'vendor/autoload.php';
use Hpar\PrestashopBridge\PrestashopBridge;
$id_product = $_POST["product"];
$ref = $_POST["ref"];
$prestaBridge = new PrestashopBridge('/var/www/prestashop', 1);
$prestaBridge->addToCurrentCart($id_product, 1, $ref);

Thanks very much,

Integration with Joomla

Hi, this seems perfect for what I'm working but I don't know how to adapt it to my Joomla, can someone please give me some hint or trick???

Thanks in advance

Simple example needed

Hello! the bridge seems to be exactly what I need in order to connect the application with my application.
Would it be possible to provide an example on how to connect the prestashopBridge with a php application (not based in any framework)

Thanks in advance
Dimitris

Problems with Prestashop 1.7

Hi !

I'm trying to use this scrip in a Symfony 3.2 project with Prestashop 1.7 and it's currently not working.

The first issue is that if I use the whole script you made, the \CompareProduct is not found (it seems it does not exist anymore)

$ctx->cookie->id_compare = isset($ctx->cookie->id_compare) ? $ctx->cookie->id_compare : \CompareProduct::getIdCompareByIdCustomer($customer->id);

I tried commenting this code, a cookie is created but it's not login in Prestashop.

So i searched for a newer version of this and i found this function in Presta 1.7 :

https://github.com/PrestaShop/PrestaShop/blob/develop/classes/Context.php#L305

Now I'm trying to adapt your script with this new code but i'm facing 2 main errors when I test something :

UndefinedMethodException in appDevDebugProjectContainer.php line 3866:
Attempted to call an undefined method named "setDisplayOptions" of class "Symfony\Component\VarDumper\Dumper\HtmlDumper".

Or

UndefinedMethodException in UnitOfWork.php line 1131:
Attempted to call an undefined method named "hasNode" of class "Doctrine\ORM\Internal\CommitOrderCalculator".

So if you have any idea of how to make your script work with Presta 1.7, it would very nice :)

Which version of Prestashop are working with this scrip ? (1.6 maybe ?)

Thank you in advance.

Fatal Error on saving $ctx->cart->save()

I used this bridge and make library out of it in code igniter.
It getting initialized and creates user with createUser function but raising fatal error when we try to login with same email id we created previously using this bridge at cart save.

It just prints fatal error in browser with no other information related to error.

Thanx in advance.

Undefined class constant 'INTL_DOMAIN_SUFFIX' in Laravel 5.7

I have installed your plugin in Laravel 5.7.

I am getting below error.
Undefined class constant 'INTL_DOMAIN_SUFFIX'.

file path /opt/lampp/htdocs/myproject/vendor/symfony/translation/Translator.php

Do anyone have idea about it? I can identify little bit. It is regarding trans function which is also used in symfony.

FIX - Login for prestashop 1.7.7.8

Hi guys, I would like to share a login fix for the 1.7.7.8
I'm using this script for a while, it was working on prestashop 1.7.2, but on a recent update it stopped working.
I checked the Context class and I saw that there is something new. You should add this at the end of the login function in the bridge, after writing the cookies and before returning:

$ctx->cookie->registerSession(new CustomerSession());

Hope it helps! ;)

Bridge login doesn't work

Hi,

I have implemented something like your sample code :

`<?php

require_once DIR . '/vendor/autoload.php';

use Hpar\PrestashopBridge\PrestashopBridge;

$psBridge = new PrestashopBridge('/Users/greg/Workspace/test/ps_bridge/prestashop');

if (! $psBridge->userExist('[email protected]')) {
$psBridge->createUser('[email protected]', 'BRIDGE', 'test', md5('pwd_test'));
}

$psBridge->login('[email protected]');

header('Location: http://www.ps-bridge.dev');`

This is flat php, with inclusion of your library, and the HttpFoundation component of Symfony (required by your lib).

The code seems to work fine, my user is created in Prestashop DB if not exists, and I am redirect to my Prestashop site, but I'm not logged in.

If y try to log me in with my credentials ([email protected] / pwd_test), I have a login error.

I have try to set the same password to another customer in Prestashop Backoffice, I can log me in with this. But if I compare the database password fields of the two users, they are not the same.

Is their any problem with your setting password method ? Or your login method ?

PS : I'm using a Prestashop 1.6.1.5

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.