Beispiel #1
0
function sync_products($vid = NULL, $cid = NULL)
{
    global $conn;
    connect_to_db();
    $sql = "\nSELECT c.channel_id, c.channel, c.products_api, s.store_id, s.store_name, s.api_key, s.api_password, s.access_token, v.vendor\n  FROM store AS s\n  JOIN vendor AS v ON s.vendor_id = v.vendor_id\n  JOIN channel AS c ON s.channel_id = c.channel_id\n  WHERE 1\n";
    if ($vid && preg_match('/^\\d+$/', $vid)) {
        $sql .= ' AND s.vendor_id=' . $vid;
    }
    if ($cid && preg_match('/^\\d+$/', $cid)) {
        $sql .= ' AND s.channel_id=' . $cid;
    }
    // actually, Vend's API can be accessed using a private access-token without expiration!
    $query = mysqli_query($conn, $sql);
    while ($row = mysqli_fetch_assoc($query)) {
        extract($row);
        $api_url = str_replace(['{STORE_NAME}', '{API_KEY}', '{API_PASSWORD}', '{ACCESS_TOKEN}'], [$store_name, $api_key, $api_password, $access_token], $products_api);
        $store = new stdClass();
        $store->store_name = $store_name;
        $store->vendor = $vendor;
        $store->channel = $channel;
        $store->api_url = $api_url;
        $stores[$store_id] = $store;
    }
    $stores_apis = array_combine(array_keys($stores), array_map(function ($x) {
        return $x->api_url;
    }, $stores));
    $api_results = fetch_products($stores_apis);
    $results = [];
    foreach ($stores as $store_id => $store) {
        $result = new stdClass();
        $result->store_name = $store->store_name;
        $result->vendor = $store->vendor;
        $result->channel = $store->channel;
        if (!empty($api_results[$store_id])) {
            $channel_products = json_decode($api_results[$store_id]);
            $products = translate_channel_products($store->channel, $channel_products);
            save_products($store_id, $products);
            $result->status = 'succeeded';
        } else {
            $result->status = 'failed';
        }
        $results[$store_id] = $result;
    }
    return $results;
}
Beispiel #2
0
		<div class="row">
			<div class="col-sm-12">
				<table class="table table-hover table-striped">
  					<thead>
  						<tr>
  							<th>Image</th>
  							<th>Name</th>
  							<th>Description</th>
  							<th>Stock</th>
  							<th>Price</th>
  							<th></th>
  						</tr>
  					</thead>
  					<tbody>
						<?php 
$result = fetch_products($pdo);
foreach ($result as $row) {
    ?>
								<tr>
									<td><img src="images/<?php 
    echo $row['image'];
    ?>
" style="max-height: 100px; max-width: 100px;"></td>
									<td><?php 
    echo $row['productname'];
    ?>
</td>
									<td><?php 
    echo $row['description'];
    ?>
</td>