database = $database; } public function isEnabled(): bool { return !empty(self::systemParam('nds_enabled')); } public function systemPercent(): string { return self::systemParam('nds'); } /** * «Значение НДС» способа доставки как ввёл мерчант; пусто — у доставки своей ставки нет. */ public function deliveryPercent(int $deliveryId): string { $table = self::deliveryTable(); if ($deliveryId <= 0 || $table === null) { return ''; } return trim((string) $this->database->fetchValue( 'SELECT ofd_nds FROM `' . $table . '` WHERE id = ? LIMIT 1', [$deliveryId], )); } /** * Включённые способы доставки (без папок): [название в cp1251, «Значение НДС»]. * * @return array */ public function enabledDeliveries(): array { $table = self::deliveryTable(); if ($table === null) { return []; } $deliveries = []; $rows = $this->database->fetchAll( 'SELECT city, ofd_nds FROM `' . $table . "` WHERE enabled = '1' AND (is_folder IS NULL OR is_folder <> '1')" . ' ORDER BY num, id', ); foreach ($rows as $row) { $deliveries[] = [ HostCharset::fromDatabase((string) ($row['city'] ?? '')), trim((string) ($row['ofd_nds'] ?? '')), ]; } return $deliveries; } private static function deliveryTable(): ?string { $table = $GLOBALS['SysValue']['base']['delivery'] ?? null; // Имя таблицы идёт в SQL: явный класс, а не \w — см. OperationRepository::table(). return (is_string($table) && preg_match('/\A[0-9A-Za-z_]+\z/', $table) === 1) ? $table : null; } private static function systemParam(string $name): string { $system = $GLOBALS['PHPShopSystem'] ?? null; if (!is_object($system) || !method_exists($system, 'getParam')) { return ''; } $value = $system->getParam($name); return is_scalar($value) ? (string) $value : ''; } }