Jump to content
  • разработка интернет магазинов на opencart
  • доработка интернет магазинов на opencart

Вывод в списке заказов клиени ссылку на скаливание купленного файла


Recommended Posts

Добрый гдень!

 

Прошу подсказку. Задача в /catalog/view/theme/mstore/template/account/order_list.tpl добавить вывод ссылки (или ссылок, купленных клиентом). Сейчас неудобно то, что файлы для скаливания и заказы в личном кабинете развегдены по разным страницам. А я хочу сгделать рядом с кнопкой просмотра заказа кнопку скаливания купленного файла.

 

Что гделаю, в контроллер /catalog/controller/account/order.php добавляю:

$this->load->model('account/download');

$data['downloads'] = array(); 

$downloads = $this->model_account_download->getDownloads($result['order_id']);

        foreach ($downloads as $download) {
            if (file_exists(DIR_DOWNLOAD . $download['filename'])) {
                $size = filesize(DIR_DOWNLOAD . $download['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(
                    'order_id'   => $download['order_id'],
                    'date_added' => date($this->language->get('date_format_short'), strtotime($download['date_added'])),
                    'time_added' => date($this->language->get('time_format'), strtotime($download['date_added'])),
                    'name'       => $download['name'],
                    'size'       => round(substr($size, 0, strpos($size, '.') + 4), 2) . $suffix[$i],
                    'href'       => $this->url->link('account/download/download', 'download_id=' . $download['download_id'], true)
                );
            }
        }

 

 

Ниже функцию download

 

 

    public function download() {
        if (!$this->customer->isLogged()) {
            $this->session->data['redirect'] = $this->url->link('account/download', '', true);

            $this->response->redirect($this->url->link('account/login', '', true));
        }

        $this->load->model('account/download');

        if (isset($this->request->get['download_id'])) {
            $download_id = $this->request->get['download_id'];
        } else {
            $download_id = 0;
        }

        $this->load->model('account/order');

        if (isset($this->request->get['order_id'])) {
            $order_id = $this->request->get['order_id'];
        } else {
            $order_id = 0;
        }

        $download_info = $this->model_account_download->getDownload($order_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-Type: application/octet-stream');
                    header('Content-Disposition: attachment; filename="' . ($mask ? $mask : basename($file)) . '"');
                    header('Expires: 0');
                    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                    header('Pragma: public');
                    header('Content-Length: ' . filesize($file));

                    if (ob_get_level()) {
                        ob_end_clean();
                    }

                    readfile($file, 'rb');

                    exit();
                } else {
                    exit('Error: Could not find file ' . $file . '!');
                }
            } else {
                exit('Error: Headers already sent out!');
            }
        } else {
            $this->response->redirect($this->url->link('account/download', '', true));
        }
    }

 

Вывод в шабе

 

<?php if($downloads){ ?>
<?php foreach($downloads as $download){ ?>
<a href="<?php echo $download['href']; ?>" title=""><?php echo $download['name']; ?><?php echo " (". $download['size'] .")";?></a>
<?php } ?>
<?php } ?> 

 

На выхогде имею ссылки на скаливание, однако ссылки зациклены и в заказах выводятся те ссылки, которые, собственно, не имеют к заказам отношения.

 

 

Готов полулить решение на платной основе. Спасипотому что.

Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.