PHP code example of protechstudio / laravel-prestashop-webservice

1. Go to this page and download the library: Download protechstudio/laravel-prestashop-webservice library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

protechstudio / laravel-prestashop-webservice example snippets


Protechstudio\PrestashopWebService\PrestashopWebServiceProvider::class,

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

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

...
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);
    }
}

...
use Prestashop;

...

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


$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()]);


$putXml=Prestashop::fillSchema($xmlSchema,$data,false); 

$putXml=Prestashop::fillSchema($xmlSchema,$data,false,['manufacturer_name','quantity']);
//manufacturer_name and quantity only will be removed from the XML

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

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

$data => [
    ...
    'associations' => [
        'categories' =>[
            [ 'category' => ['id' => 4] ],
            [ 'category' => ['id' => 5] ],
            [ 'category' => ['id' => 11] ],
        ],
        'product_features' => [
            [
                'product_feature' => [
                    'id' => 5,
                    'id_feature_value' => 94
                ]
            ],
            [
                'product_feature' => [
                    'id' => 1,
                    'id_feature_value' => 2
                ]
            ]
        ]
    ]
]
shell
php artisan vendor:publish --provider="Protechstudio\PrestashopWebService\PrestashopWebServiceProvider"