90 lines
2.6 KiB
PHP
Executable File
90 lines
2.6 KiB
PHP
Executable File
<?php
|
|
require_once '../app/bootstrap.php';
|
|
|
|
use Magento\Framework\App\Bootstrap;
|
|
use GuzzleHttp\Client;
|
|
|
|
//require 'app/bootstrap.php';
|
|
$bootstrap = Bootstrap::create(BP, $_SERVER);
|
|
$objectManager = $bootstrap->getObjectManager();
|
|
$state = $objectManager->get('\Magento\Framework\App\State');
|
|
$state->setAreaCode('frontend');
|
|
|
|
|
|
$storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
|
|
$storeId = $storeManager->getStore()->getId();
|
|
|
|
$websiteId = $storeManager->getStore($storeId)->getWebsiteId();
|
|
|
|
$objectManager->get('Magento\Framework\Registry')->register('isSecureArea', true);
|
|
|
|
|
|
function getProductFromMag3ByCateId($catId) {
|
|
$client = new Client(['http_errors' => false]);
|
|
$headers = [];
|
|
$request = new \GuzzleHttp\Psr7\Request('GET', 'https://mag3.nswteam.net/rest/all/V1/client/get-product-by-category?category_id='.$catId, $headers);
|
|
$res = $client->sendAsync($request)->wait();
|
|
return $res;
|
|
}
|
|
|
|
$mag3_mag2 = array(
|
|
"37" => [1806],
|
|
"4" => [1807],
|
|
"143" => [1808],
|
|
"174" => [1809],
|
|
"118" => [1809],
|
|
"46" => [1810],
|
|
"180" => [1811],
|
|
"753" => [1812],
|
|
"291" => [1813],
|
|
"84" => [1814],
|
|
"105" => [1814],
|
|
"113" => [1814],
|
|
"129" => [1814],
|
|
"34" => [1815],
|
|
"130" => [1816],
|
|
"109" => [1817],
|
|
"114" => [1818],
|
|
"115" => [1819,1820],
|
|
"123" => [1821],
|
|
"128" => [1822,1830],
|
|
"152" => [1823],
|
|
"160" => [1824],
|
|
"221" => [1825],
|
|
"262" => [1826],
|
|
"495" => [1827],
|
|
"706" => [1828],
|
|
"719" => [1829]
|
|
);
|
|
$productHelper = $objectManager->create('\IpSupply\Prology\Helper\ProductHelper');
|
|
function run($productHelper, $mag3_mag2){
|
|
foreach ($mag3_mag2 as $mag3CatId => $mag2Cats) {
|
|
echo "get category ".$mag3CatId ."\n";
|
|
$res = getProductFromMag3ByCateId($mag3CatId);
|
|
if ($res->getStatusCode() == 200) {
|
|
$items = json_decode($res->getBody()->getContents(), true);
|
|
echo count($items)."\n";
|
|
foreach ($items as $item) {
|
|
try {
|
|
$productHelper->createProductFromPrology($item, $mag2Cats);
|
|
} catch (Throwable $t) {
|
|
echo "Throwable createProductFromPrology \n";
|
|
echo json_encode($item)."\n";
|
|
} catch (Exception $e) {
|
|
echo "Exception createProductFromPrology \n";
|
|
echo json_encode($item)."\n";
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
run($productHelper, $mag3_mag2);
|
|
// //
|
|
// $res = getProductFromMag3ByCateId(719);
|
|
// if ($res->getStatusCode() == 200) {
|
|
// $arr = json_decode($res->getBody()->getContents(), true);
|
|
// echo count($arr);
|
|
// }
|