Beispiel #1
0
<?php 
foreach ($countryCl->country as $c => $country) {
    ?>
		<li><?php 
    echo $country["label"];
    ?>
</li>
<?php 
}
?>
	</ul>
</p>

<?php 
/* Préparation, envoi de la requête à l'API et reception de la réponse */
$lpCl = new Env_ListPoints(array("user" => $userData["login"], "pass" => $userData["password"], "key" => $userData["api_key"]));
$lpCl->setEnv('test');
$params = array('srv_code' => 'RelaisColis', "collecte" => "exp", 'pays' => 'FR', 'cp' => '13002', 'ville' => 'MARSEILLE');
$lpCl->getListPoints("SOGP", $params);
/* If there is no errors, we display the datas */
if (!$lpCl->curlError && !$lpCl->respError) {
    ?>
<style type="text/css">
	table tr td {border:1px solid #000000; padding:5px; }
</style>
<?php 
    $jourSemaine = array(1 => 'Lundi', 2 => 'Mardi', 3 => 'Mercredi', 4 => 'Jeudi', 5 => 'Vendredi', 6 => 'Samedi', 7 => 'Dimanche');
    ?>
<h3>Liste points relais (file: get_listpoints.php)</h3>
<p>Exemple points relais <?php 
    echo $params['ville'];
<?php

include_once 'config.api.php';
$city = $_GET['city'];
$zip = $_GET['zip'];
$lpCl = new Env_ListPoints(array("user" => $userData["login"], "pass" => $userData["password"], "key" => $userData["api_key"]));
$lpCl->setEnv('test');
$params = array('srv_code' => 'RelaisColis', "collecte" => "exp", 'pays' => 'FR', 'cp' => $zip, 'ville' => $city);
$lpCl->getListPoints("SOGP", $params);
echo json_encode($lpCl);
Beispiel #3
0
function test_Env_ListPoints($userData)
{
    $result = default_value();
    $start = microtime_float();
    /* Initialisation */
    $env = new Env_ListPoints(array("user" => $userData["login"], "pass" => $userData["password"], "key" => $userData["api_key"]));
    $env->setEnv('test');
    $params = array('srv_code' => 'RelaisColis', 'pays' => 'FR', 'cp' => '75011', 'ville' => 'PARIS');
    $env->getListPoints("SOGP", $params);
    /* Reception test */
    if ($env->curlError) {
        $result['reception'] = max($result['reception'], ERROR);
        $result['reception_info'][count($result['reception_info'])] = 'Error while sending the query';
    } else {
        if ($env->respError) {
            $result['reception'] = max($result['reception'], ERROR);
            $result['reception_info'][count($result['reception_info'])] = 'Invalid query : ' . $userData["api_key"];
            foreach ($env->respErrorsList as $message) {
                $result['reception_info'][count($result['reception_info'])] = $message['message'];
            }
        } else {
            $result['reception'] = max($result['reception'], OK);
            $result['reception_info'][count($result['reception_info'])] = 'Reception time : ' . (microtime_float() - $start) . 's';
        }
    }
    /* Additionals test */
    /* Test for the result structure */
    $result['additionals'][0]['name'] = 'Structure';
    $result['additionals'][0]['state'] = OK;
    if (count($env->listPoints) == 0) {
        $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING);
        $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '$listPoints array is empty';
    } else {
        foreach ($env->listPoints as $x => $content) {
            if (!isset($env->listPoints[$x]['code'])) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"code" not defined in $listPoints[' . $x . '] array';
            }
            if (!isset($env->listPoints[$x]['name'])) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"name" not defined in $listPoints[' . $x . '] array';
            }
            if (!isset($env->listPoints[$x]['address'])) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"address" not defined in $listPoints[' . $x . '] array';
            }
            if (!isset($env->listPoints[$x]['city'])) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"city" not defined in $listPoints[' . $x . '] array';
            }
            if (!isset($env->listPoints[$x]['zipcode'])) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"zipcode" not defined in $listPoints[' . $x . '] array';
            }
            if (!isset($env->listPoints[$x]['country'])) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"country" not defined in $listPoints[' . $x . '] array';
            }
            if (!isset($env->listPoints[$x]['description'])) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"description" not defined in $listPoints[' . $x . '] array';
            }
            if (!isset($env->listPoints[$x]['days'])) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"days" not defined in $listPoints[' . $x . '] array';
            } else {
                if (count($env->listPoints[$x]['days']) != 7) {
                    $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING);
                    $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"days" should contains 7 days info, but contains ' . count($env->contents[$x]['days']) . ' instead';
                }
            }
            if (isset($env->listPoints[$x]['days'])) {
                foreach ($env->listPoints[$x]['days'] as $j => $day) {
                    if (!isset($env->listPoints[$x]['days'][$j]['weekday'])) {
                        $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING);
                        $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"weekday" not defined in $listPoints[' . $x . ']["days"][' . $j . '] array';
                    }
                    if (!isset($env->listPoints[$x]['days'][$j]['open_am'])) {
                        $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING);
                        $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"open_am" not defined in $listPoints[' . $x . ']["days"][' . $j . '] array';
                    }
                    if (!isset($env->listPoints[$x]['days'][$j]['close_am'])) {
                        $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING);
                        $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"close_am" not defined in $listPoints[' . $x . ']["days"][' . $j . '] array';
                    }
                    if (!isset($env->listPoints[$x]['days'][$j]['open_pm'])) {
                        $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING);
                        $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"open_pm" not defined in $listPoints[' . $x . ']["days"][' . $j . '] array';
                    }
                    if (!isset($env->listPoints[$x]['days'][$j]['close_pm'])) {
                        $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING);
                        $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"close_pm" not defined in $listPoints[' . $x . ']["days"][' . $j . '] array';
                    }
                }
            }
        }
    }
    $result['duration'] = microtime_float() - $start;
    return $result;
}
 /**
  *
  */
 function onShippingConfigurationSave(&$element)
 {
     parent::onShippingConfigurationSave($element);
     if (!$this->init()) {
         return false;
     }
     $app = JFactory::getApplication();
     $db = JFactory::getDBO();
     $methods = array();
     if (empty($element->shipping_params->emc_login) || empty($element->shipping_params->emc_password) || empty($element->shipping_params->api_key) || empty($element->shipping_params->sender_lastname) || empty($element->shipping_params->sender_firstname) || empty($element->shipping_params->sender_email) || empty($element->shipping_params->sender_company) || empty($element->shipping_params->sender_phone) || empty($element->shipping_params->sender_address) || empty($element->shipping_params->sender_city) || empty($element->shipping_params->sender_postcode) || empty($element->shipping_params->sender_country)) {
         $app->enqueueMessage(JText::sprintf('ENTER_INFO', 'Envoimoinscher', JText::_('SENDER_INFORMATIONS') . ' (' . JText::_('HIKA_LOGIN') . ', ' . JText::_('HIKA_PASSWORD') . ', ' . JText::_('FEDEX_API_KEY') . ', ' . JText::_('LASTNAME') . ', ' . JText::_('FIRSTNAME') . ', ' . JText::_('HIKA_EMAIL') . ', ' . JText::_('COMPANY') . ', ' . JText::_('TELEPHONE') . ', ' . JText::_('ADDRESS') . ', ' . JText::_('CITY') . ', ' . JText::_('POST_CODE') . ', ' . JText::_('COUNTRY') . ')'));
     }
     // TODO : Refactor ! (use JRequest...)
     if (isset($_REQUEST['data']['shipping_methods'])) {
         foreach ($_REQUEST['data']['shipping_methods'] as $method) {
             foreach ($this->envoimoinscher_methods as $envoimoinscherMethod) {
                 $name = $envoimoinscherMethod['name'];
                 if ($name == $method['name']) {
                     $obj = new stdClass();
                     $methods[strip_tags($method['name'])] = strip_tags($envoimoinscherMethod['code']);
                 }
             }
         }
     } else {
         $app->enqueueMessage(JText::sprintf('CHOOSE_SHIPPING_SERVICE'));
     }
     $element->shipping_params->methodsList = serialize($methods);
     // we call the function of the library to get all the product categories and we display
     //
     if (!empty($element->shipping_params->emc_login) && !empty($element->shipping_params->emc_password) && !empty($element->shipping_params->api_key)) {
         $contentCl = new Env_ContentCategory(array('user' => @$element->shipping_params->emc_login, 'pass' => @$element->shipping_params->emc_password, 'key' => @$element->shipping_params->api_key));
         $config = hikashop_config();
         $contentCl->setPlatformParams('hikashop', $config->get('version'), $config->get('version'));
         $contentCl->setEnv($element->shipping_params->environment);
         $contentCl->getCategories();
         @$contentCl->getContents();
         $element->shipping_params->contentCl = array('categories' => $contentCl->categories, 'contents' => $contentCl->contents);
         if (!empty($contentCl->curlErrorText)) {
             $app->enqueueMessage($contentCl->curlErrorText, 'error');
         }
         if (!empty($contentCl->respErrorsList)) {
             foreach ($contentCl->respErrorsList as $err) {
                 $app->enqueueMessage('[ ' . $err['code'] . ' ] ' . $err['message'], 'error');
             }
         }
     }
     $czone_code = @$element->shipping_params->sender_country;
     if (!empty($czone_code)) {
         $query = 'SELECT zone_id, zone_code_2 FROM ' . hikashop_table('zone') . ' WHERE zone_namekey = ' . $db->Quote($czone_code);
         $db->setQuery($query);
         $czone = $db->loadObject();
         $country = $czone->zone_code_2;
         if ($country == 'FX') {
             $country = 'FR';
         }
         // To display the drop off points for each service in the config
         $lpCl = new Env_ListPoints(array('user' => $element->shipping_params->emc_login, 'pass' => $element->shipping_params->emc_password, 'key' => $element->shipping_params->api_key));
         $config = hikashop_config();
         $lpCl->setPlatformParams('hikashop', $config->get('version'), $config->get('version'));
         // environment 'test' or 'prod'
         $lpCl->setEnv($element->shipping_params->environment);
         foreach ($methods as $name => $code) {
             $params = array('srv_code' => $name, 'collecte' => 'exp', 'pays' => $country, 'cp' => $element->shipping_params->sender_postcode, 'ville' => $element->shipping_params->sender_city);
             $lpCl->getListPoints($code, $params);
             if (!$lpCl->curlError && !$lpCl->respError) {
                 $element->shipping_params->envoimoinscher_dropoff[$code] = $lpCl->listPoints;
                 unset($lpCl->listPoints);
                 $lpCl->listPoints = array();
             }
         }
         if (!empty($lpCl->curlErrorText)) {
             $app->enqueueMessage($lpCl->curlErrorText, 'error');
         }
         if (!empty($lpCl->respErrorsList)) {
             foreach ($lpCl->respErrorsList as $err) {
                 $app->enqueueMessage('[ ' . $err['code'] . ' ] ' . $err['message'], 'error');
             }
         }
     }
     return true;
 }