Created
December 4, 2015 18:21
-
-
Save gerswin/18639540361bc05568e4 to your computer and use it in GitHub Desktop.
productos y categorias mlv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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