-
-
Save crystaldaking/68c2cddae4953b810ef34c82599af6bf to your computer and use it in GitHub Desktop.
MODX 1C
This file contains 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
<?php | |
//сетапинг | |
ini_set('display_errors', 1); | |
error_reporting(E_ALL); | |
ini_set('memory_limit', '4048M'); | |
ini_set('max_execution_time', '10000000'); | |
error_reporting(E_ERROR); | |
header('Content-type: text/html; charset=utf-8'); | |
define('MODX_API_MODE', true); | |
require dirname(__FILE__).'/index.php'; | |
function pr($var) { | |
static $int=0; | |
echo '<pre><b style="background: red;padding: 1px 5px;">'.$int.'</b> '; | |
print_r($var); | |
echo '</pre>'; | |
$int++; | |
} | |
echo "Начан процесс выгрузки <br>"; | |
class UpdaterData{ | |
public $id; | |
public $name; | |
public $remains; | |
public $cost; | |
} | |
$updaterDataArray = array(); | |
$zipName = 'assets/import/horizontshop.zip'; | |
if(!file_exists($zipName)) | |
{ | |
echo "Файла выгрузки нет в каталоге <br>"; | |
die(); | |
} | |
$zip = new ZipArchive; | |
$zip->open($zipName); | |
$zip->extractTo('assets/import/'); | |
$zip->close(); | |
$offers = 'assets/import/offers.xml'; | |
if(!file_exists($offers)) | |
{ | |
echo "Пришла какая-то хуета вместо выгрузки <br>"; | |
die(); | |
} | |
$offers = file_get_contents('assets/import/offers.xml'); | |
$offers = simplexml_load_string($offers); | |
$offers = json_encode($offers); | |
$offers = json_decode($offers); | |
echo "<br>"; | |
$myoffers = $offers->ПакетПредложений->Предложения; | |
foreach($myoffers->Предложение as $offer) | |
{ | |
$model = new UpdaterData(); | |
$model->id = $offer->Ид; | |
$model->name = $offer->Наименование; | |
$model->remains = $offer->Количество; | |
$model->cost = $offer->Цены->Цена->ЦенаЗаЕдиницу; | |
array_push($updaterDataArray,$model); | |
} | |
foreach ($updaterDataArray as $model) | |
{ | |
if ($model->remains<5) | |
{ | |
$productid = $modx->getObject('msProductData',array( | |
'article'=>$model->id)); | |
if($productid) | |
{ | |
$id = $productid->get('id'); | |
$product = $modx->getObject('msProduct',$id); | |
$product->set('price',$model->cost); | |
$product->setTVValue('product_availability', 'false'); | |
$product->save(); | |
echo $product->get('pagetitle')."не в наличии <br>"; | |
} | |
} | |
else | |
{ | |
$productid = $modx->getObject('msProductData',array( | |
'article'=>$model->id)); | |
if ($productid) | |
{ | |
$id = $productid->get('id'); | |
$product = $modx->getObject('msProduct',$id); | |
$product->set('price',$model->cost); | |
$product->setTVValue('product_availability','true'); | |
$product->save(); | |
echo $product->get('pagetitle')." в наличии <br>"; | |
} | |
} | |
} | |
$modx->cacheManager->refresh(); | |
unlink($zipName); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment