Jump to content
Joubinho

Webservice : ajout d'un groupe à un client

Recommended Posts

Posted (edited)

Bonjour à tous,

Auriez-vous un exemple de script utilisant "PSWebServiceLibrary" afin ajouter un groupe (déjà existant) à un client ?

Par exemple, mon customer ayant l'id 2 appartient au groupe id3 et id4.
Et j'aimerai qu'il soit en plus dans le groupe id7.

Comment faire cela ?

Cordialement.

 

 

Edited by Joubinho
Résolu (see edit history)

Share this post


Link to post
Share on other sites
function add_to_group($customer_id, $group_id) {

    require __DIR__.'/PSWebServiceLibrary.php';

    $url = 'xxxxxxxx';
    $key  = 'xxxxxxxxxx';
    $debug = true;

    $webService = new PrestaShopWebservice($url, $key, $debug);

    $xml = $webService->get(['resource'=>'customers', 'id'=>$customer_id]);

    $new_group = $xml->customer->associations->groups->addchild('group', '');
    $new_group->addchild('id', $group_id);

    $updatedXml = $webService->edit([
        'resource' => 'customers',
        'id' => (int) $customer_id,
        'putXml' => $xml->asXML(),
    ]);
    
    return;
}

Voici la réponse si vous aviez le même problème.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More