Доброго времени суток! В catalog/model/catalog/product.php
public function getDownloads($product_id) {
$query = $this->db->query('SELECT * FROM '.DB_PREFIX.'product_to_download pd LEFT JOIN '.DB_PREFIX.'download d ON(pd.download_id=d.download_id) LEFT JOIN '.DB_PREFIX.'download_description dd ON(pd.download_id=dd.download_id) WHERE product_id = "'.(int)$product_id.'" AND dd.language_id = "'.(int)$this->config->get("config_language_id").'"');
return $query->rows;
}
public function getDownload($product_id, $download_id) {
$download = '';
if ($download_id!=0) $download = " AND d.download_id=".(int)$download_id;
$query = $this->db->query('SELECT * FROM '.DB_PREFIX.'product_to_download pd LEFT JOIN '.DB_PREFIX.'download d ON(pd.download_id=d.download_id) LEFT JOIN '.DB_PREFIX.'download_description dd ON(pd.download_id=dd.download_id) WHERE product_id = "'.(int)$product_id.'" '.$download.' AND dd.language_id = "'.(int)$this->config->get("config_language_id").'"');
return $query->row;
}
Далее добавлено в catalog/controller/product/product.php
$data['downloads'] = array();
$results = $this->model_catalog_product->getDownloads($this->request->get['product_id']);
foreach ($results as $result) {
if (file_exists(DIR_DOWNLOAD . $result['filename'])) {
$size = filesize(DIR_DOWNLOAD . $result['filename']);
$i = 0;
$suffix = array(
'B',
'KB',
'MB',
'GB',
'TB',
'PB',
'EB',
'ZB',
'YB'
);
while (($size / 1024) > 1) {
$size = $size / 1024;
$i++;
}
$data['downloads'][] = array(
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
'name' => $result['name'],
'size' => round(substr($size, 0, strpos($size, '.') + 4), 2) . $suffix[$i],
'href' => $this->url->link('product/product/download', 'product_id='. $this->request->get['product_id']. '&download_id=' . $result['download_id'])
);
}
}
В этом же файле:
public function download() {
$this->load->model('catalog/product');
if (isset($this->request->get['download_id'])) {
$download_id = $this->request->get['download_id'];
} else {
$download_id = 0;
}
if (isset($this->request->get['product_id'])) {
$product_id = $this->request->get['product_id'];
} else {
$product_id = 0;
}
$download_info = $this->model_catalog_product->getDownload($product_id, $download_id);
if ($download_info) {
$file = DIR_DOWNLOAD . $download_info['filename'];
$mask = basename($download_info['mask']);
if (!headers_sent()) {
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . ($mask ? $mask : basename($file)) . '"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file, 'rb');
exit;
} else {
exit('Error: Could not find file ' . $file . '!');
}
} else {
exit('Error: Headers already sent out!');
}
} else {
$this->redirect(HTTP_SERVER . 'index.php?route=account/download');
}
}
Не хватат мозгов как в твиг это всё реализовать Естесно правлю файл product.twig, пытаюсь вызвать перед ценой.