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

Загрузка архива на страниэто товара кнопкой


Recommended Posts

Здравствуйте. Есть модуль "Загрузка файла"  на страниэто product.tpl, при усиновке которого в отгдельной вкладке появляется файл загрузки. Я его "досил" из вкладки и сгделал кнопкой, всивив код ниже в кнопку.

<a href="<?php echo $download['href']; ?>" title="<?php echo $download['name']; ?>" target="_blank"><?php echo $download['name']; ?><?php echo ($download['size'])?" (". $download['size'] .")":'';?></a>

 

Все ок, но при обновлении модификаторов, в  product.tpl снова прописывается вкладка:

 

<?php if ($downloads) { ?>
            <li><a href="#tab-documentation" data-toggle="tab"><?php echo $tab_documentation; ?></a></li>
            <?php } ?>


И согдержимое вкладки:

          

 <div class="tab-pane tab-content" id="tab-documentation">
              <?php if ($downloads){ ?>
                <ul style="list-style:none;">
                  <?php foreach($downloads as $download){ ?>
                    <li><i class="<?php echo $download['icon']; ?>"></i> <a href="<?php echo $download['href']; ?>" title="<?php echo $download['name']; ?>" target="_blank"><?php echo $download['name']; ?><?php echo ($download['size'])?" (". $download['size'] .")":'';?></a></li>
                  <?php } ?>
                </ul>
              <?php } ?>    
            </div>

Что из файла install.xml нужно убрать, чтобы вкладка и ее согдержимое снова не прописывались в product.tpl?

 

<?xml version="1.0" encoding="utf-8"?>
<modification>
  <name>Загружаемые файлы во вкладке</name>
  <code>downloadable_files</code>
  <version>1.3</version>
  <author>https://ocmod.net</author>
  <link>https://ocmod.net</link>

  <file path="admin/controller/catalog/download.php">
		<operation>
		  <search index="0"><![CDATA[128]]></search>
		  <add position="replace"><![CDATA[255]]></add>
		</operation>  
		<operation>
		  <search trim="true"><![CDATA[if (!is_file(DIR_DOWNLOAD . $this->request->post['filename'])) {]]></search>
		  <add position="replace"><![CDATA[     if (!is_file(DIR_DOWNLOAD . $this->request->post['filename']) AND !preg_match('/^http/',$this->request->post['filename'])) {]]></add>
		</operation>
  </file>  

  <file path="catalog/language/*/product/product.php">
		<operation>
		  <search index="0"><![CDATA[$_['tab_description']]]></search>
		  <add position="before"><![CDATA[$_['tab_documentation'] = 'Файлы для скаливания';]]></add>
		</operation>
  </file>
  
  <file path="catalog/model/catalog/product.php">
		<operation>
      <search index="0" trim="true"><![CDATA[public function getTotalProductSpecials() {]]></search>
      <add position="before"><![CDATA[  
	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;
   }  ]]></add>
    </operation>
  </file>

  <file path="catalog/controller/product/product.php">
		<operation error="skip">
		  <search index="0" trim="true"><![CDATA[$data['tab_description'] = $this->language->get('tab_description');]]></search>
		  <add position="before"><![CDATA[			$data['tab_documentation'] = $this->language->get('tab_documentation');]]></add>
		</operation>	
		<operation>
			<search index="0" trim="true"><![CDATA[public function review() {]]></search>
		  	<add position="before"><![CDATA[
				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)) { 
	      //$finfo = new finfo(FILEINFO_MIME);
	      //$mime_type = $finfo->file($file);         
	      $mime_type = 'application/octet-stream';         
	      
				header('Content-Description: File Transfer');
				header('Content-Type: '.$mime_type); //application/octet-stream
				header('Content-Disposition: inline; filename="' . ($mask ? $mask : basename($file)) . '"');   //attachment
				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');

				//$this->model_account_download->updateRemaining($this->request->get['download_id']);

				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');
				}
				}
			]]>
		  </add>
		</operation>
		<operation>
			<search index="0" trim="true"><![CDATA[$this->model_catalog_product->updateViewed($this->request->get['product_id']);]]></search>
		  	<add position="before"><![CDATA[
	        $data['downloads'] = array();

	        $results = $this->model_catalog_product->getDownloads($this->request->get['product_id']);

	        foreach ($results as $result) {  
			  $size = false;
	          $file_exists = file_exists(DIR_DOWNLOAD . $result['filename']);
	          $http = preg_match('/^http/',$result['filename']);
	          if ($file_exists OR $http) {
	            if ($file_exists) {
	              $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' => ($size)?round(substr($size, 0, strpos($size, '.') + 4), 2) . $suffix[$i]:false,
	            'href' => ($http)?$result['filename']:$this->url->link('product/product/download', 'product_id='. $this->request->get['product_id']. '&download_id=' . $result['download_id']),
	            'icon' => ($http)?'fa fa-external-link-square text-primary':'fa fa-download text-success'
	            );
	          }
	        }
			]]>
		  </add>
		</operation>	
  </file> 

  <file path="catalog/view/theme/*/template/product/product.tpl">
  	<operation error="skip">
		<search index="0" trim="true"><![CDATA[<?php if ($review_status) { ?>]]></search>
	  	<add position="before"><![CDATA[
            <?php if ($downloads) { ?>
            <li><a href="#tab-documentation" data-toggle="tab"><?php echo $tab_documentation; ?></a></li>
            <?php } ?>		
		]]>
	  	</add>
		</operation>
  	<operation error="skip">
		<search index="1" trim="true"><![CDATA[<?php if ($review_status) { ?>]]></search>
	  	<add position="before"><![CDATA[
			<div class="tab-pane tab-content" id="tab-documentation">
			  <?php if ($downloads){ ?>
				<ul style="list-style:none;">
				  <?php foreach($downloads as $download){ ?>
					<li><i class="<?php echo $download['icon']; ?>"></i> <a href="<?php echo $download['href']; ?>" title="<?php echo $download['name']; ?>" target="_blank"><?php echo $download['name']; ?><?php echo ($download['size'])?" (". $download['size'] .")":'';?></a></li>
				  <?php } ?>
				</ul>
			  <?php } ?>	
			</div>
		]]>
	  	</add>
		</operation>	
  </file>

  <!-- For SEO PRO:  -->
  <file path="catalog/controller/*/seo_pro.php">
		<operation error="skip">
			<search><![CDATA[case 'information_id':]]></search>
 			<add position="after"><![CDATA[
				case 'download_id':
			]]></add>
		</operation>
	</file> 

  <file path="system/library/seopro.php">
		<operation error="skip">
			<search><![CDATA[case 'information_id':]]></search>
 			<add position="after"><![CDATA[
				case 'download_id':
			]]></add>
		</operation>
	</file>  
	
</modification>

 

Link to comment
Share on other sites


30.03.2022 в 14:55, hostup сказал:

 

  Что из файла install.xml нужно убрать, чтобы вкладка и ее согдержимое снова не прописывались в product.tpl

 

 

Участок который добавляется в карточку товара

 

Скрытый текст
  <file path="catalog/view/theme/*/template/product/product.tpl">
  	<operation error="skip">
		<search index="0" trim="true"><![CDATA[<?php if ($review_status) { ?>]]></search>
	  	<add position="before"><![CDATA[
            <?php if ($downloads) { ?>
            <li><a href="#tab-documentation" data-toggle="tab"><?php echo $tab_documentation; ?></a></li>
            <?php } ?>		
		]]>
	  	</add>
		</operation>
  	<operation error="skip">
		<search index="1" trim="true"><![CDATA[<?php if ($review_status) { ?>]]></search>
	  	<add position="before"><![CDATA[
			<div class="tab-pane tab-content" id="tab-documentation">
			  <?php if ($downloads){ ?>
				<ul style="list-style:none;">
				  <?php foreach($downloads as $download){ ?>
					<li><i class="<?php echo $download['icon']; ?>"></i> <a href="<?php echo $download['href']; ?>" title="<?php echo $download['name']; ?>" target="_blank"><?php echo $download['name']; ?><?php echo ($download['size'])?" (". $download['size'] .")":'';?></a></li>
				  <?php } ?>
				</ul>
			  <?php } ?>	
			</div>
		]]>
	  	</add>
		</operation>	
  </file>

 

 

Поправленный

 

Скрытый текст
<?xml version="1.0" encoding="utf-8"?>
<modification>
  <name>Загружаемые файлы во вкладке</name>
  <code>downloadable_files</code>
  <version>1.3</version>
  <author>https://ocmod.net</author>
  <link>https://ocmod.net</link>

  <file path="admin/controller/catalog/download.php">
		<operation>
		  <search index="0"><![CDATA[128]]></search>
		  <add position="replace"><![CDATA[255]]></add>
		</operation>  
		<operation>
		  <search trim="true"><![CDATA[if (!is_file(DIR_DOWNLOAD . $this->request->post['filename'])) {]]></search>
		  <add position="replace"><![CDATA[     if (!is_file(DIR_DOWNLOAD . $this->request->post['filename']) AND !preg_match('/^http/',$this->request->post['filename'])) {]]></add>
		</operation>
  </file>  

  <file path="catalog/language/*/product/product.php">
		<operation>
		  <search index="0"><![CDATA[$_['tab_description']]]></search>
		  <add position="before"><![CDATA[$_['tab_documentation'] = 'Файлы для скаливания';]]></add>
		</operation>
  </file>
  
  <file path="catalog/model/catalog/product.php">
		<operation>
      <search index="0" trim="true"><![CDATA[public function getTotalProductSpecials() {]]></search>
      <add position="before"><![CDATA[  
	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;
   }  ]]></add>
    </operation>
  </file>

  <file path="catalog/controller/product/product.php">
		<operation error="skip">
		  <search index="0" trim="true"><![CDATA[$data['tab_description'] = $this->language->get('tab_description');]]></search>
		  <add position="before"><![CDATA[			$data['tab_documentation'] = $this->language->get('tab_documentation');]]></add>
		</operation>	
		<operation>
			<search index="0" trim="true"><![CDATA[public function review() {]]></search>
		  	<add position="before"><![CDATA[
				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)) { 
	      //$finfo = new finfo(FILEINFO_MIME);
	      //$mime_type = $finfo->file($file);         
	      $mime_type = 'application/octet-stream';         
	      
				header('Content-Description: File Transfer');
				header('Content-Type: '.$mime_type); //application/octet-stream
				header('Content-Disposition: inline; filename="' . ($mask ? $mask : basename($file)) . '"');   //attachment
				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');

				//$this->model_account_download->updateRemaining($this->request->get['download_id']);

				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');
				}
				}
			]]>
		  </add>
		</operation>
		<operation>
			<search index="0" trim="true"><![CDATA[$this->model_catalog_product->updateViewed($this->request->get['product_id']);]]></search>
		  	<add position="before"><![CDATA[
	        $data['downloads'] = array();

	        $results = $this->model_catalog_product->getDownloads($this->request->get['product_id']);

	        foreach ($results as $result) {  
			  $size = false;
	          $file_exists = file_exists(DIR_DOWNLOAD . $result['filename']);
	          $http = preg_match('/^http/',$result['filename']);
	          if ($file_exists OR $http) {
	            if ($file_exists) {
	              $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' => ($size)?round(substr($size, 0, strpos($size, '.') + 4), 2) . $suffix[$i]:false,
	            'href' => ($http)?$result['filename']:$this->url->link('product/product/download', 'product_id='. $this->request->get['product_id']. '&download_id=' . $result['download_id']),
	            'icon' => ($http)?'fa fa-external-link-square text-primary':'fa fa-download text-success'
	            );
	          }
	        }
			]]>
		  </add>
		</operation>	
  </file> 

  <!-- For SEO PRO:  -->
  <file path="catalog/controller/*/seo_pro.php">
		<operation error="skip">
			<search><![CDATA[case 'information_id':]]></search>
 			<add position="after"><![CDATA[
				case 'download_id':
			]]></add>
		</operation>
	</file> 

  <file path="system/library/seopro.php">
		<operation error="skip">
			<search><![CDATA[case 'information_id':]]></search>
 			<add position="after"><![CDATA[
				case 'download_id':
			]]></add>
		</operation>
	</file>  
	
</modification>

 

 

Edited by 3DO
  • +1 1
Link to comment
Share on other sites


3DO, по сути нужно было вырезать код между тегами <operation>, включая эти теги тоже, для вкладки и согдержимого! Я ик гделал, но у меня product.tpl обновлял product.tpl из modification и получался кавардак. В итоге я запуился, отчаялся и обратился сюда за помощью. 3DO, спасипотому что за помощь, настроение мое улучшилось!

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.