Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Вывод товаров на другом сайте!


Recommended Posts

Подскажите пожалуйста как отделить основной PHP код от шаблона Вывода и раскидать его по отдельным файлам?

 

код взят на форуме opencartforum.com

 

    <?php
    /// DB
    define('DB_HOSTNAME', 'localhost');
    define('DB_USERNAME', 'open');
    define('DB_PASSWORD', 'pass');
    define('DB_DATABASE', 'open');
    define('DB_PREFIX', '');
     
    $db = mysql_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD);
    mysql_select_db(DB_DATABASE ,$db);
     
    $query = "SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, wcd.unit AS weight_class FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "weight_class_description wcd ON (p.weight_class_id = wcd.weight_class_id) WHERE p.date_available <= NOW() AND p.status = '1' ORDER BY RAND() LIMIT 12";
     
    $products = getArray(query($query, $db));
     
    echo '<table width="915">';
       for ($j = 0; $j < sizeof($products); $j++) {
     
       echo '<tr>';
       $i=$j+3;
       for(;$j<$i;$j++){
          if($i<sizeof($products)){
       echo '
            <td width="305">
            <table width="300">
           <tr>
                    <td colspan="2" align="right" style="padding: 30px 5px 0 5px;"><a style="text-decoration: none;  color: #006; font-size: 16px; font-weight: bold;" href="' . $products[$j]['href'] . '">'.  $products[$j]['name'] .'</a></td>
           </tr>
           <tr>
               <td width="30%">
               <img src="image/'.  $products[$j]['thumb'] .'" title="'.  $products[$j]['name'] .'" alt="'.  $products[$j]['name'] .'" width="150" height="150" />
                    </td>
                    <td width="70%">
               <span style="color: #fff; font-size: 13px; font-weight: bold;">?™?¦????: </span><a href="'.  $products[$j]['manufacturer_link'] .'" style="text-decoration: none;">'.  $products[$j]['manufacturer'] .'</a><br />
               <span style="color: #fff; font-size: 13px; font-weight: bold;">?“?’??: </span>'.  $products[$j]['model'] .'<br /><br />
               
               <span style="color: #fff; font-size: 13px;"><a href="'. $products[$j]['href'] .'" style="text-decoration: none;">[ ???•?“ ... ]</a</span><br />
                    </td>
           </tr>
                    <tr>
               <td>
               <span style="color: #900; font-weight: bold;">'.  $products[$j]['price'] .'</span>
               <br />
               <br />
               </td>
             </tr>
             </table>
            </td>
      ';
                    }else{
          echo '<td></td>';
          }
       }
       echo '</tr>';
      }
     
      echo '</table>';
     
     
     
     
    mysql_close($db);
     
       function query($sql, $db) {
          $resource = mysql_query($sql, $db);
     
          if ($resource) {
                    if (is_resource($resource)) {
                $i = 0;
           
                $data = array();
         
                while ($result = mysql_fetch_assoc($resource)) {
                    $data[$i] = $result;
           
                    $i++;
                }
               
                mysql_free_result($resource);
               
                return $data;  
              } else {
                return TRUE;
                    }
          } else {
                exit('Error!');
            }
            }
       
       
       function getArray ($results) {
       $products = array();
       foreach ($results as $result) {
                    if ($result['image']) {
                $image = $result['image'];
                    } else {
                $image = 'no_image.jpg';
                    }
                   
                    $price = $result['price'];
                   
         
                    $products[] = array(
                'name'    => $result['name'],
                'model'   => $result['model'],
                'shortdescription'  => mb_substr(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'), 0, 180),
                'manufacturer'   => $result['manufacturer'],
                'manufacturer_link' => 'index.php?route=product/manufacturer&manufacturer_id=' . $result['manufacturer_id'],
                'thumb'   => $image,
                'price'   => $price,
                'href'    => 'index.php?route=product/product&product_id=' . $result['product_id']
                    );
          }
          return $products;
       }
       
       
     
    ?>

Или может есть возможность вивода товаров на другом сайте через модуль WEB API https://github.com/ethernet1/opencart-webapi

Link to comment
Share on other sites


Подскажите пожалуйста как отделить основной PHP код от шаблона Вывода

"Основный" php код в папках controller, modal и system, а шаблоны вывода в папке view.

Link to comment
Share on other sites

В данном формате этот код выводит рандомно вроде 10 товаров! Мне нужно отделить PHP код и шаблон оформления, чтобы задать свой шаблон на другом сайте (DLE)!

 

Я так понял что к этому коду чтобы задать шаблон вывода нужно прикрутить шаблонизатор?

 

 Извините меня наверное очень тяжело понять?)

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.