Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $url = 'https://service.tradesoft.ru/3/';
- $user = 'victormek';
- $password = 'MEKSTER11';
- $eurotradeUrl = 'shop_eurotradeplus_pl';
- $eurotradeLogin = 'NORDIC';
- $eurotradePassword = 'NORDIC11';
- $request = getRequest('GetPriceList', getContainer('1069','A.B.S.'));
- function getContainer($code, $producer, $itemHash = null) {
- return array(
- 'container' => array(
- array(
- 'provider' => $GLOBALS['eurotradeUrl'],
- 'login' => $GLOBALS['eurotradeLogin'],
- 'password' => $GLOBALS['eurotradePassword'],
- 'code' => $code,
- 'producer' => $producer,
- 'itemHash' => $itemHash
- )
- ));
- }
- function getRequest($action, $extra = array()) {
- $params = array(
- 'service' => 'provider',
- 'action' => $action,
- 'user' => $GLOBALS['user'],
- 'password' => $GLOBALS['password'],
- ) + $extra;
- return $params;
- }
- $response = getResponse($request);
- $response = current($response['container']);
- $response = $response['data'];
- $responce = parseResponseByProducer($response, 'A.B.S.');
- $chepestKey = findCheapestByPrice($responce);
- $itemHash = $responce[$chepestKey]['itemHash'];
- print_r($responce[$chepestKey]);
- $preOrderSearch = getRequest('PreOrderSearch', getContainer('1069','A.B.S.','e0c99bf30838b1a742c62aaafdf60446'));
- $preOrderSearch1 = array(
- 'service' => 'provider',
- 'user' => $GLOBALS['user'],
- 'password' => $GLOBALS['password'],
- 'timeLimit' => '10',
- 'action' => 'PreOrderSearch',
- 'container' => array(
- array(
- 'provider' => $GLOBALS['eurotradeUrl'],
- 'login' => $GLOBALS['eurotradeLogin'],
- 'password' => $GLOBALS['eurotradePassword'],
- 'code' => '1069',
- 'producer' => 'A.B.S.',
- 'itemHash' => 'e0c99bf30838b1a742c62aaafdf60446'
- )
- )
- );
- print_r(getResponse($preOrderSearch));
- die;
- function findCheapestByPrice($big) {
- $lowest = array();
- foreach($big as $id => $array) {
- $low = false;
- $prev = false;
- foreach($array as $k => $a) {
- if(!$low) {
- $low = $k;
- $prev = $a['price'];
- } else {
- if($a['price'] < $prev) {
- $prev = $a['price'];
- $low = $k;
- }
- }
- }
- $lowest[$id] = array( $low => $array[$low]);
- }
- return key(array_column($lowest, 'price'));
- }
- function parseResponseByProducer($responce, $producer) {
- return array_filter($responce, function ($var) use ($producer) {
- return ($var['producer'] == $producer);
- });
- }
- function getResponse($request) {
- try {
- $post = json_encode($request);
- $ch = curl_init($GLOBALS['url']);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
- $data = curl_exec($ch);
- curl_close($ch);
- $responce = json_decode($data,true);
- return $responce;
- } catch (Exception $e) {
- return $e->getMessage();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement