Jump to content

Lenteur webservice est ce que je fais ce qu'il faut


Recommended Posts

Bonjour,

J'essai de faire un tableau avec la liste des paniers comme sur l'image
id_cart, nom du client, n° de commande si panier validé, date_add, action a faire

Avec un requete SQL y en a pour 1 sec pour afficher 444 résultats et avec les webservices cela met 54 sec

<?php
try
{
    $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
    $opt = [
                'resource' => 'carts',
                'display'  => '[id,id_customer,date_add]',
                'filter[id_shop]' => '['.PS_ID_SHOP.']',
                'sort'  => '[id_DESC]'
            ];
    $xml = $webService->get($opt);
    $carts = $xml->carts->children();
}
catch (PrestaShopWebserviceException $e)
{
    // Here we are dealing with errors
    $trace = $e->getTrace();
    if ($trace[0]['args'][0] == 404) echo 'Bad ID';
    else if ($trace[0]['args'][0] == 401) echo 'Bad auth key';
    else echo 'Other error';
}
?>
<table id="tabletricart" class="table table-striped table-hover">
    <thead class='table-primary'>
        <tr>
            <th>#</th>
            <th>CLIENT</th>
            <th>COMMANDE</th>
            <th>DATE</th>
            <th class="text-end">ACTION</th>
        </tr>
    </thead>
    <tbody>
<?php
if (isset($carts))
{
    //var_dump($carts);
    foreach ($carts as $cart)
    {        
        $bt_panier="<button type='button' id='stock_commandes_modification' name='".$cart->id."' class='btn btn-dark btn-sm' id_cart='".$cart->id."'>
                        <span class='material-icons'>shopping_cart_checkout</span>
                    </button>";
        $bt_delete="<button type='button' id='websevice_delete_cart' name='".$cart->id."' class='btn btn-dark btn-sm'>
                        <span class='material-icons'>delete_forever</span>
                    </button>";
        echo'<tr>
                <td>'.$cart->id.'</td>
                <td>'.getCustomerNameById($cart->id_customer).'</td>
                <td>'.getIdOrderByIdCart($cart->id_cart).'</td>
                <td>'.$cart->date_add.'</td>
                <td class="text-end">'.$bt_panier.' '.$bt_delete.'</td>
            </tr>';
    }
}
?>
    </tbody>
</table>
function getIdOrderByIdCart($id_cart){
    global $webService;
    try
        {
            $opt = [
                'resource' => 'orders',
                'display'  => '[id_order,reference]',
                'filter[id_cart]'  => '['.$id_cart.']'
            ];
            $xmlo = $webService->get($opt);
            $orders = $xmlo->orders[0];
        }
        catch (PrestaShopWebserviceException $e)
        {
            // Here we are dealing with errors
            $trace = $e->getTrace();
            if ($trace[0]['args'][0] == 404) echo 'Bad ID';
            else if ($trace[0]['args'][0] == 401) echo 'Bad auth key';
            else echo 'Other error';
        }
        return $orders->order->id_order.' '.$orders->order->reference;
}

 

Voila en gros a quoi ressemble mon code cela fonctionne mais c'est d'une lenteur ...

Est ce que j'ai mal fait qqu chose ?

image.thumb.png.6b609f9f22c190ebcb3819897a810f1d.png

Edited by jcandres (see edit history)
Link to comment
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...