- Модуль: sale
- Путь к файлу: ~/bitrix/modules/sale/lib/compatible/internals/entitycompatibility.php
- Класс: BitrixSaleCompatibleInternalsEntityCompatibility
- Вызов: EntityCompatibility::saveRawFields
public function saveRawFields($entity, $entityName)
{
global $DB;
if (!static::checkEntityName($entityName))
{
throw new ArgumentOutOfRangeException('entityName');
}
if (empty($this->rawFields[$entityName]) || !is_array($this->rawFields[$entityName]))
return new SaleResult();
$tableName = null;
if ($entityName == static::ENTITY_ORDER)
{
/** @var SaleOrderBase $entity */
if (!$entity instanceof SaleOrderBase)
{
throw new ObjectNotFoundException('Entity "Order" not found');
}
$tableName = static::ENTITY_ORDER_TABLE;
}
elseif ($entityName == static::ENTITY_PAYMENT)
{
/** @var SalePayment $entity */
if (!$entity instanceof SalePayment)
{
throw new ObjectNotFoundException('Entity "Payment" not found');
}
$tableName = static::ENTITY_PAYMENT_TABLE;
}
if ($entity->getId() <= 0)
{
throw new ArgumentNullException('id');
}
if (strval(trim($tableName)) == '')
{
throw new ArgumentNullException('tableName');
}
$result = new SaleResult();
$queryValue = $DB->PrepareUpdate($tableName, $this->rawFields[$entityName]);
foreach ($this->rawFields[$entityName] as $key => $value)
{
if (mb_substr($key, 0, 1) != "=")
continue;
if (strval($queryValue) != '')
$queryValue .= ", ";
$queryValue .= mb_substr($key, 1)."=".$value." ";
}
$sql =
"UPDATE ".$tableName." SET ".
" ".$queryValue." WHERE ID = ".$entity->getId()." ";
if (!($DB->Query($sql, true, "File: ".__FILE__."
Line: ".__LINE__)))
{
$result->addError(new SaleResultError(Loc::getMessage('SALE_COMPATIBLE_'.$entityName.'_RAW_FIELD_UPDATE_ERROR'), 'SALE_'.$entityName.'_COMPATIBLE_RAW_FIELD_UPDATE_ERROR'));
return $result;
}
return $result;
}