Remontée des paniers et affichage du jeu

Etapes et exemples d'utilisation dans le langage de la technologie choisie pour remonter les paniers et afficher un jeu.

Intégration en PHP

Description et emplacement des fichiers à utiliser

php/luckycart.php : la librairie php
php/lc_plugin_sample.php : un exemple d’utilisation

Etapes d'intégration

1. Installation de la librairie

Placez la librairie luckycart.php sur le serveur à un endroit accessible depuis la page de confirmation de commande.

2. Inclusion de la librairie

Modifiez la page de confirmation de commande pour inclure la librairie

// Include LC library
require_once('path/to/luckycart.php');

3. Initialisation de la librairie et envoi des données

Toujours dans le code de la page de confirmation de commande.


// Use exception to catch error
try {
  // Create a Lucky Cart object with your key and secret
  $lucky = new LuckyCart('key','secret');

  // Create an array of data to send to associate with the token.
  // Assuming data from the site are store in $customer and $cart data.
     $postdata = array(
  // mandatory data
    'customerId' => $customer->id,
    'cartId' => $cart->id,
    'ttc' => $cart->ttc,
    'ht' => $cart->ht,
    'country' => $customer->country,
    'email' => $customer->email,
    'payment' => $cart->payment,
    'firstName' => $customer->firstname,
    'lastName' => $customer->lastname,
    'codePromo' => $cart->code,
    'currency' => $cart->currency,
    'lang'    => $customer->language,
    'shopId' => $cart->shopId,
    'optin' => $customer->optin,
    'products' => array(
     array('id' => $cart->products[0]->id, 'ttc' => $cart->products[0]->ttc,
           'ht' => $cart->products[0]->ht, 'qty' => $cart->products[0]->quantity,
           'cat' => $cart->products[0]->category, 'brand' => $cart->products[0]->brand),
     array('id' => $cart->products[1]->id, 'ttc' => $cart->products[1]->ttc,
           'ht' => $cart->products[1]->ht, 'qty' => $cart->products[1]->quantity,
           'cat' => $cart->products[1]->category, 'brand' => $cart->products[1]->brand),
     array('id' => $cart->products[2]->id, 'ttc' => $cart->products[2]->ttc,
           'ht' => $cart->products[2]->ht, 'qty' => $cart->products[2]->quantity,
           'cat' => $cart->products[2]->category, 'brand' => $cart->products[2]->brand),
    ),

  // add here any other specific data
  );
  // Sends the request to LC servers
  $plugin = $lucky->plugin($postdata);
}
  catch (LuckyException $e)
{
  // Do something with the error... retry or log
  // the error message for example... ($e->getMessage())
}

4. Affichage du jeu

Il s’effectue en positionnant les containers suivants sur la page de confirmation de commande :

<body>
<!-- Add this div tag anywhere in the order confirmation page to render the game plugin -->
<?php echo $plugin->gamediv; ?>
...
<!-- Add this script tag at the bottom of the page (in order not to interfere with page loading) -->
<?php echo $plugin->script; ?>
</body>