It's OK. That's works 😊
<?php
if (!defined('MODX_BASE_PATH')) {
die("Get out!");
}
$e = &$modx->Event;
if($e->name == 'OnDocFormSave') {
if($id == 3) {
$idTVoperator = 36;
$idTVPizzas = array(
"price_s" => 33,
"price_m" => 34,
"price_xl" => 35
);
$tb_site_tmplvar_contentvalues = $modx->getFullTableName("site_tmplvar_contentvalues");
$tvParamsOperator = [
$tb_site_tmplvar_contentvalues,
'tmplvarid=' . $idTVoperator . ' and contentid=' . $id
];
$operator = $modx->db->getValue($modx->db->select('value', ...$tvParamsOperator));
if( $operator != '0' ) {
foreach($idTVPizzas as $nameTableValue => $idTVValue) {
$tvParams = [
$tb_site_tmplvar_contentvalues,
'tmplvarid=' . $idTVValue . ' and contentid=' . $id
];
$tvValue = $modx->db->getValue($modx->db->select('value', ...$tvParams));
$tvValue = str_replace(",", ".", $tvValue);
$tvValue = floatval($tvValue);
if ( $tvValue != '0' ) {
$tvValue = $modx->db->escape($tvValue);
$tb_pizzas = $modx->getFullTableName("pizzas");
$updatePrices = "UPDATE $tb_pizzas SET $nameTableValue = REPLACE($nameTableValue, ',', '.') $operator $tvValue";
$modx->db->query($updatePrices);
$updatePrices = "UPDATE $tb_pizzas SET $nameTableValue = REPLACE($nameTableValue, '.', ',')";
$modx->db->query($updatePrices);
$resetValue = $modx->db->escape(0);
$modx->db->save([
'tmplvarid' => $idTVValue,
'contentid' => $id,
'value' => $resetValue
], ...$tvParams);
}
}
$modx->db->save([
'tmplvarid' => $idTVoperator,
'contentid' => $id,
'value' => $resetValue
], ...$tvParamsOperator);
}
}
}
TV operator 36
is a Dropdown List Menu with this values: No action==0||Increase the price==+||Reduce the price==-
TVs 33
, 34
and 35
are just a Text
TV. I wanted to pick Number
but I cannot put decimal number.
If you see an improvement in my code, don't hesitate to tell me, I will make the changes.