Skip to content

Instantly share code, notes, and snippets.

@gerswin
Created December 4, 2015 18:21
Show Gist options
  • Save gerswin/18639540361bc05568e4 to your computer and use it in GitHub Desktop.
Save gerswin/18639540361bc05568e4 to your computer and use it in GitHub Desktop.
productos y categorias mlv
$categories = [];
$count = count($it);
for ($i = 0; $i < $count ; $i++) {
$item = $meli->get("/items/" . $it[$i]);
$category = $meli->get("/categories/" . $item['body']->category_id);
$cats = [];
try {
foreach ($category['body']->path_from_root as $value) {
$cats[] = $value->id;
$categories[$value->id] = ["ml_id" => $value->id, "name" => $value->name];
}
}
catch(Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
try {
$productos = ['ml_id' => $item['body']->id, 'title' => $item['body']->title, 'categories' => rtrim(implode(',', $cats), ','), 'price' => $item['body']->price, 'image' => $item['body']->pictures[0]->url];
$database->insert("productos", $productos);
}
catch(Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
}
foreach ($categories as $value) {
$database->insert("categorias", $value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment