Last active
October 21, 2015 10:35
-
-
Save vgrish/a82dd144388ea830462b to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Update Prices an CRlist | |
*/ | |
class modCRlistsUpdatePricesProcessor extends modProcessor | |
{ | |
public $classKey = 'CRlist'; | |
public $message = array(); | |
public $total = 0; | |
protected $valutes = array( | |
'price_eur' => 'EUR', | |
'price_usd' => 'USD' | |
); | |
public function process() | |
{ | |
/** @var currencyrate $currencyrate */ | |
if (!$currencyrate = $this->modx->getService('currencyrate', 'currencyrate', $this->modx->getOption('currencyrate_core_path', null, $this->modx->getOption('core_path') . 'components/currencyrate/') . 'model/currencyrate/', array())) { | |
return 'Could not load currencyrate class!'; | |
} | |
foreach ($this->valutes as $field => $valute) { | |
if (!$valute = $this->modx->getObject('CRlist', array('charcode' => $valute, 'active' => 1))) { | |
continue; | |
} | |
$valuerate = $valute->get('valuerate'); | |
if (empty($valuerate)) { | |
continue; | |
} | |
$sql = "UPDATE {$this->modx->getTableName('msProductData')} SET `price` = Ceil({$field} * {$valuerate}) WHERE {$field} > 0"; | |
$q = $this->modx->prepare($sql); | |
$q->execute(); | |
++$this->total; | |
} | |
if ($this->total > 0) { | |
$this->message[] = "Выполнено обновление для {$this->total} валют."; | |
$this->modx->cacheManager->refresh(); | |
} | |
return $this->success(implode('<br>', $this->message)); | |
} | |
} | |
return 'modCRlistsUpdatePricesProcessor'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment