看了radnows和Jack老大的帖没看懂,关于新进商品按上传时间排序

Zen Cart的安装、设置、升级讨论和使用技巧交流

版主: shaning

zencart 发帖图标 看了radnows和Jack老大的帖没看懂,关于新进商品按上传时间排序

帖子dksczr » 2009-10-22 17:51

翻遍整个论坛没看懂,关于新进商品按上传时间排序
参考了2个帖
一个是
post37853.html
:
修改首页上新进商品:
/includes/modules/new_products.php
$new_products_query 添加一个限制条件 order by p.products_date_added DESC
这个怎么添加?在哪个位置添加?

一个是
post1474.html

Jack 老大写的:

还是我来吧...

复制文件/includes/modules/new_products.php到目录
/includes/modules/你的模板名/
然后修改/includes/modules/你的模板名/new_products.php
从原来的47行开始,修改为

.......................代码段..................
也就是加上了排序:
" order by p.products_date_added desc"
你可以自己定义排序的规则

然后将文件中的:
$db->ExecuteRandomMulti
改为
$db->Execute

MoveNextRandom()
改为
MoveNext()



但是这个貌似和我的文件完全不一样,JACK老大的例子应该是以前的老版本的.




我该怎么改?
dksczr
高级会员
高级会员
 
帖子: 235
注册: 2009-01-07 9:05

Re: 看了radnows和Jack老大的帖没看懂,关于新进商品按上传时间排序

帖子dksczr » 2009-10-22 17:53

我的ZEN CART 版本是 1.38

new_products.php代码为:
代码: 全选
<?php
/**
 * new_products.php module
 *
 * @package modules
 * @copyright Copyright 2003-2007 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: new_products.php 6424 2007-05-31 05:59:21Z ajeh $
 */
if (!defined('IS_ADMIN_FLAG')) {
  die('Illegal Access');
}

// initialize vars
$categories_products_id_list = '';
$list_of_products = '';
$new_products_query = '';

$display_limit = zen_get_new_date_range();

if ( (($manufacturers_id > 0 && $_GET['filter_id'] == 0) || $_GET['music_genre_id'] > 0 || $_GET['record_company_id'] > 0) || (!isset($new_products_category_id) ||

$new_products_category_id == '0') ) {
  $new_products_query = "select distinct p.products_id, p.products_image, p.products_tax_class_id, pd.products_name,
                                p.products_date_added, p.products_price, p.products_type, p.master_categories_id
                           from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd
                           where p.products_id = pd.products_id
                           and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
                           and   p.products_status = 1 " . $display_limit;
} else {
  // get all products and cPaths in this subcat tree
  $productsInCategory = zen_get_categories_products_list( (($manufacturers_id > 0 && $_GET['filter_id'] > 0) ? zen_get_generated_category_path_rev($_GET['filter_id']) : $cPath),

false, true, 0, $display_limit);

  if (is_array($productsInCategory) && sizeof($productsInCategory) > 0) {
    // build products-list string to insert into SQL query
    foreach($productsInCategory as $key => $value) {
      $list_of_products .= $key . ', ';
    }
    $list_of_products = substr($list_of_products, 0, -2); // remove trailing comma

    $new_products_query = "select distinct p.products_id, p.products_image, p.products_tax_class_id, pd.products_name,
                                  p.products_date_added, p.products_price, p.products_type, p.master_categories_id
                           from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd
                           where p.products_id = pd.products_id
                           and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
                           and p.products_id in (" . $list_of_products . ")";
  }
}

if ($new_products_query != '') $new_products = $db->ExecuteRandomMulti($new_products_query, MAX_DISPLAY_NEW_PRODUCTS);

$row = 0;
$col = 0;
$list_box_contents = array();
$title = '';

$num_products_count = ($new_products_query == '') ? 0 : $new_products->RecordCount();

// show only when 1 or more
if ($num_products_count > 0) {
  if ($num_products_count < SHOW_PRODUCT_INFO_COLUMNS_NEW_PRODUCTS || SHOW_PRODUCT_INFO_COLUMNS_NEW_PRODUCTS == 0 ) {
    $col_width = floor(100/$num_products_count);
  } else {
    $col_width = floor(100/SHOW_PRODUCT_INFO_COLUMNS_NEW_PRODUCTS);
  }

  while (!$new_products->EOF) {
    $products_price = zen_get_products_display_price($new_products->fields['products_id']);
    if (!isset($productsInCategory[$new_products->fields['products_id']])) $productsInCategory[$new_products->fields['products_id']] = zen_get_generated_category_path_rev

($new_products->fields['master_categories_id']);

    $list_box_contents[$row][$col] = array('params' => 'class="centerBoxContentsNew centeredContent back"' . ' ' . 'style="width:' . $col_width . '%;"',
    'text' => (($new_products->fields['products_image'] == '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS == 0) ? '' : '<a href="' . zen_href_link(zen_get_info_page($new_products-

>fields['products_id']), 'cPath=' . $productsInCategory[$new_products->fields['products_id']] . '&products_id=' . $new_products->fields['products_id']) . '">' . zen_image

(DIR_WS_IMAGES . $new_products->fields['products_image'], $new_products->fields['products_name'], IMAGE_PRODUCT_NEW_WIDTH, IMAGE_PRODUCT_NEW_HEIGHT) .

'</a><br />') . '<a href="' . zen_href_link(zen_get_info_page($new_products->fields['products_id']), 'cPath=' . $productsInCategory[$new_products->fields['products_id']] . '&products_id='

. $new_products->fields['products_id']) . '">' . $new_products->fields['products_name'] . '</a><br />' . $products_price);

    $col ++;
    if ($col > (SHOW_PRODUCT_INFO_COLUMNS_NEW_PRODUCTS - 1)) {
      $col = 0;
      $row ++;
    }
    $new_products->MoveNextRandom();
  }

  if ($new_products->RecordCount() > 0) {
    if (isset($new_products_category_id) && $new_products_category_id != 0) {
      $category_title = zen_get_categories_name((int)$new_products_category_id);
      $title = '<h2 class="centerBoxHeading">' . sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')) . ($category_title != '' ? ' - ' . $category_title : '' ) . '</h2>';
    } else {
      $title = '<h2 class="centerBoxHeading">' . sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')) . '</h2>';
    }
    $zc_show_new_products = true;
  }
}
?>
dksczr
高级会员
高级会员
 
帖子: 235
注册: 2009-01-07 9:05

Re: 看了radnows和Jack老大的帖没看懂,关于新进商品按上传时间排序

帖子dksczr » 2009-10-23 16:53

请求帮助......每一小时关注一次......睡觉时间除外......
dksczr
高级会员
高级会员
 
帖子: 235
注册: 2009-01-07 9:05

Re: 看了radnows和Jack老大的帖没看懂,关于新进商品按上传时间排序

帖子shaning » 2009-10-24 15:08

代码: 全选
    <?php
    /**
    * new_products.php module
    *
    * @package modules
    * @copyright Copyright 2003-2007 Zen Cart Development Team
    * @copyright Portions Copyright 2003 osCommerce
    * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
    * @version $Id: new_products.php 6424 2007-05-31 05:59:21Z ajeh $
    */
    if (!defined('IS_ADMIN_FLAG')) {
      die('Illegal Access');
    }

    // initialize vars
    $categories_products_id_list = '';
    $list_of_products = '';
    $new_products_query = '';

    $display_limit = zen_get_new_date_range();

    if ( (($manufacturers_id > 0 && $_GET['filter_id'] == 0) || $_GET['music_genre_id'] > 0 || $_GET['record_company_id'] > 0) || (!isset($new_products_category_id) ||

    $new_products_category_id == '0') ) {
      $new_products_query = "select distinct p.products_id, p.products_image, p.products_tax_class_id, pd.products_name,
                                    p.products_date_added, p.products_price, p.products_type, p.master_categories_id
                               from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd
                               where p.products_id = pd.products_id
                               and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
                               and   p.products_status = 1 " . $display_limit." order by p.products_date_added DESC";
    } else {
      // get all products and cPaths in this subcat tree
      $productsInCategory = zen_get_categories_products_list( (($manufacturers_id > 0 && $_GET['filter_id'] > 0) ? zen_get_generated_category_path_rev($_GET['filter_id']) : $cPath),

    false, true, 0, $display_limit);

      if (is_array($productsInCategory) && sizeof($productsInCategory) > 0) {
        // build products-list string to insert into SQL query
        foreach($productsInCategory as $key => $value) {
          $list_of_products .= $key . ', ';
        }
        $list_of_products = substr($list_of_products, 0, -2); // remove trailing comma

        $new_products_query = "select distinct p.products_id, p.products_image, p.products_tax_class_id, pd.products_name,
                                      p.products_date_added, p.products_price, p.products_type, p.master_categories_id
                               from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd
                               where p.products_id = pd.products_id
                               and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
                               and p.products_id in (" . $list_of_products . ") order by p.products_date_added DESC";
      }
    }

    if ($new_products_query != '') $new_products = $db->ExecuteRandomMulti($new_products_query, MAX_DISPLAY_NEW_PRODUCTS);

    $row = 0;
    $col = 0;
    $list_box_contents = array();
    $title = '';

    $num_products_count = ($new_products_query == '') ? 0 : $new_products->RecordCount();

    // show only when 1 or more
    if ($num_products_count > 0) {
      if ($num_products_count < SHOW_PRODUCT_INFO_COLUMNS_NEW_PRODUCTS || SHOW_PRODUCT_INFO_COLUMNS_NEW_PRODUCTS == 0 ) {
        $col_width = floor(100/$num_products_count);
      } else {
        $col_width = floor(100/SHOW_PRODUCT_INFO_COLUMNS_NEW_PRODUCTS);
      }

      while (!$new_products->EOF) {
        $products_price = zen_get_products_display_price($new_products->fields['products_id']);
        if (!isset($productsInCategory[$new_products->fields['products_id']])) $productsInCategory[$new_products->fields['products_id']] = zen_get_generated_category_path_rev

    ($new_products->fields['master_categories_id']);

        $list_box_contents[$row][$col] = array('params' => 'class="centerBoxContentsNew centeredContent back"' . ' ' . 'style="width:' . $col_width . '%;"',
        'text' => (($new_products->fields['products_image'] == '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS == 0) ? '' : '<a href="' . zen_href_link(zen_get_info_page($new_products-

    >fields['products_id']), 'cPath=' . $productsInCategory[$new_products->fields['products_id']] . '&products_id=' . $new_products->fields['products_id']) . '">' . zen_image

    (DIR_WS_IMAGES . $new_products->fields['products_image'], $new_products->fields['products_name'], IMAGE_PRODUCT_NEW_WIDTH, IMAGE_PRODUCT_NEW_HEIGHT) .

    '</a><br />') . '<a href="' . zen_href_link(zen_get_info_page($new_products->fields['products_id']), 'cPath=' . $productsInCategory[$new_products->fields['products_id']] . '&products_id='

    . $new_products->fields['products_id']) . '">' . $new_products->fields['products_name'] . '</a><br />' . $products_price);

        $col ++;
        if ($col > (SHOW_PRODUCT_INFO_COLUMNS_NEW_PRODUCTS - 1)) {
          $col = 0;
          $row ++;
        }
        $new_products->MoveNextRandom();
      }

      if ($new_products->RecordCount() > 0) {
        if (isset($new_products_category_id) && $new_products_category_id != 0) {
          $category_title = zen_get_categories_name((int)$new_products_category_id);
          $title = '<h2 class="centerBoxHeading">' . sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')) . ($category_title != '' ? ' - ' . $category_title : '' ) . '</h2>';
        } else {
          $title = '<h2 class="centerBoxHeading">' . sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')) . '</h2>';
        }
        $zc_show_new_products = true;
      }
    }
    ?>
QQ:1 9 2 3 6 1 1 3 WX:miaomang zencart定制深度修改等
头像
shaning
论坛版主
论坛版主
 
帖子: 1372
注册: 2005-10-29 17:22
地址: zencart定制深度修改等
QQ 帐号: 1 9 2 3 6 1 1 3

Re: 看了radnows和Jack老大的帖没看懂,关于新进商品按上传时间排序

帖子dksczr » 2009-10-25 8:51

shaning 老大
非常感谢你的帮助
但奇怪的是,COPY你写的代码替换后,出现一个奇怪的现象:
首页的新进商品栏没了,并且右边的所有栏目也没了。
我将文件中的:
$db->ExecuteRandomMulti
改为
$db->Execute

MoveNextRandom()
改为
MoveNext()
效果还是一样,不显示,连带右边侧边栏目也没有了
请求帮助。。。。。。,谢谢。
dksczr
高级会员
高级会员
 
帖子: 235
注册: 2009-01-07 9:05

Re: 看了radnows和Jack老大的帖没看懂,关于新进商品按上传时间排序

帖子Jack » 2009-10-25 12:12

如果页脚也不显示,那么代码出错了。参考新手上路栏目置顶贴子打开错误提示。
Zen Cart - 让每个人拥有自己生意的梦想成真
加入Zen Cart地图 | 恕不回复站内短信提问 | QQ: 3171061
头像
Jack
论坛版主
论坛版主
 
帖子: 12265
注册: 2004-12-16 10:04

Re: 看了radnows和Jack老大的帖没看懂,关于新进商品按上传时间排序

帖子dksczr » 2009-10-25 21:37

JACK老大
错误提示为:
Parse error: syntax error, unexpected '>' in ... .../includes/modules/new_products.php on line 79
dksczr
高级会员
高级会员
 
帖子: 235
注册: 2009-01-07 9:05

Re: 看了radnows和Jack老大的帖没看懂,关于新进商品按上传时间排序

帖子dksczr » 2009-10-25 21:38

代码: 全选
  >fields['products_id']), 'cPath=' . $productsInCategory[$new_products->fields['products_id']] . '&products_id=' . $new_products->fields['products_id']) . '">' . zen_image
dksczr
高级会员
高级会员
 
帖子: 235
注册: 2009-01-07 9:05

Re: 看了radnows和Jack老大的帖没看懂,关于新进商品按上传时间排序

帖子dksczr » 2009-10-25 22:09

76-79行为
$list_box_contents[$row][$col] = array('params' => 'class="centerBoxContentsNew centeredContent back"' . ' ' . 'style="width:' . $col_width . '%;"',
'text' => (($new_products->fields['products_image'] == '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS == 0) ? '' : '<a href="' . zen_href_link(zen_get_info_page($new_products-

>fields['products_id']), 'cPath=' . $productsInCategory[$new_products->fields['products_id']] . '&products_id=' . $new_products->fields['products_id']) . '">' . zen_image

我将79行前空格去掉后连起来
不出错了
但是产品依旧不按照时间排列
dksczr
高级会员
高级会员
 
帖子: 235
注册: 2009-01-07 9:05

Re: 看了radnows和Jack老大的帖没看懂,关于新进商品按上传时间排序

帖子dksczr » 2009-10-25 22:16

再将文件中的:
$db->ExecuteRandomMulti
改为
$db->Execute

MoveNextRandom()
改为
MoveNext()
修改后
成功按照时间排列顺序。。。。。。。。。。。。
太开心了。。。。。。。。


感谢:shaning
感谢:Jack
感谢:radnows
感谢:shaning
感谢:ZEN CART
dksczr
高级会员
高级会员
 
帖子: 235
注册: 2009-01-07 9:05


  • 相关话题
    回复总数
    阅读次数
    最新文章

回到 安装设置



在线用户

正在浏览此版面的用户:没有注册用户 和 2 位游客