GithubHelp home page GithubHelp logo

jorgerrubio / laravel-prestashop-webservice Goto Github PK

View Code? Open in Web Editor NEW

This project forked from silentscripter/laravel-prestashop-webservice

0.0 1.0 0.0 9 KB

Laravel 5 wrapper for Prestashop Web Service Library

License: MIT License

PHP 100.00%

laravel-prestashop-webservice's Introduction

Laravel Prestashop Web Service

Laravel 5 wrapper for Prestashop Web Service Library

Installation

Require this package with composer using the following command:

composer require protechstudio/laravel-prestashop-webservice

After updating composer, add the service provider to the providers array in config/app.php

Protechstudio\PrestashopWebService\PrestashopWebServiceProvider::class,

You may also add the Facade in the aliases array in config/app.php

'Prestashop' => Protechstudio\PrestashopWebService\PrestashopWebServiceFacade::class,

Finally publish the configuration file using the artisan command

php artisan vendor:publish --provider="Protechstudio\PrestashopWebService\PrestashopWebServiceProvider"

Configuration

Open the published configuration file at config/prestashop-webservice.php:

return [
    'url' => 'http://domain.com',
    'token' => '',
    'debug' => env('APP_DEBUG', false)
];

Then populate the url field with the root url of the targeted Prestashop installation and token field with the API token obtained from Prestashop control panel in Web Service section. If debug is true Prestashop will return debug information when responding to API requests.

Usage

You may use the Prestashop Web Service wrapper in two ways:

Using the dependency or method injection

...
use Protechstudio\PrestashopWebService\PrestashopWebService;

class FooController extends Controller
{
    private $prestashop;
    
    public function __construct(PrestashopWebService $prestashop)
    {
        $this->prestashop = $prestashop;
    }
    
    public function bar()
    {
        $opt['resource'] = 'customers';
        $xml=$this->prestashop->get($opt);
    }
}

Using the Facade

...
use Prestashop;

...

public function bar()
{   
    $opt['resource'] = 'customers';
    $xml=Prestashop::get($opt);
}

Prestashop Underlying library usage

You may find complete documentation and tutorials regarding Prestashop Web Service Library in the Prestashop Documentation.

Helper methods

I've added some helper methods to reduce development time:

Retrieving resource schema and filling data for posting

You may call getSchema() method to retrieve the requested resource schema. You may then fill the schema with an associative array of data with fillSchema() method.

$xmlSchema=Prestashop::getSchema('categories'); //returns a SimpleXMLElement instance with the desired schema

$data=[
    'name'=>'Clothes',
    'link_rewrite'=>'clothes',
    'active'=>true
];

$postXml=Prestashop::fillSchema($xmlSchema,$data); 

//The xml is now ready for being sent back to the web service to create a new category

$response=Prestashop::add(['resource'=>'categories','postXml'=>$postXml->asXml()]);

Note for language value handling

If the node has a language child you may use a simple string for the value if your shop has only one language installed.

/*
    xml node with one language child example
    ...
    <name>
    <language id="1"/>
    </name>
    ...
*/
$data= ['name'=>Clothes'];

If your shops has more than one language installed you may pass the node value as an array where the key is the language ID.

/*
    xml node with n language children example 
    ...
    <name>
    <language id="1"/>
    <language id="2"/>
    </name>
    ... 
*/
$data= [
    'name'=>[
        1 => 'Clothes',
        2 => 'Abbigliamento
    ]
];

Please note that if you don't provide an array of values keyed by the language ID all language values will have the same value.

laravel-prestashop-webservice's People

Contributors

silentscripter avatar maronzu avatar

Watchers

Jorge Rubio avatar

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.