Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Nov 2012
    Posts
    1
    Plugin Contributions
    0

    Default New products on index-page in reverse order

    Hello guys, I searched quite a while and found nothing. It would be great if you could help me, please..

    first, my site is www.fimofun.cz

    I changed the new_products.php site from if ($new_products_query != '') $new_products = $db->ExecuteRandomMulti($new_products_query, MAX_DISPLAY_NEW_PRODUCTS);

    to if ($new_products_query != '') $new_products = $db->Execute($new_products_query, MAX_DISPLAY_NEW_PRODUCTS);
    and the

    $new_products->MoveNextRandom(); to $new_products->MoveNext();
    that solved my problem just partially (the randomness was gone)...

    Now as you can see on the index page, the products are ordered by product_id (from 275 to 283).. but I want it to be REVERSED, so that it starts with the highest id (the newest product)... please help :-(((

    Here the new_products.php:

    <?php
    /**
    * new_products.php module
    *
    * @package modules
    * @copyright Copyright 2003-2008 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 8730 2008-06-28 01:31:22Z drbyte $
    */
    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, pd.products_description,
    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, pd.products_name";
    } 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, pd.products_description,
    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, pd.products_name";
    }
    }

    if ($new_products_query != '') $new_products = $db->Execute($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) {

    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']);


    $products_img = (($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>');

    $products_name = '<a class="name" 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>';

    $products_desc = substr(strip_tags($new_products->fields['products_description']), 0, 20) . '...';

    $products_price = '<strong>' . zen_get_products_display_price($new_products->fields['products_id']) . '</strong>';

    $products_######## = '<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_button(BUTTON_IMAGE_GOTO_PROD_DETAILS, BUTTON_GOTO_PROD_DETAILS_ALT) . '</a>';
    $products_butt2 = '<a href="' . zen_href_link(FILENAME_PRODUCTS_NEW, zen_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $new_products->fields["products_id"]) . '">' . zen_image_button(BUTTON_IMAGE_ADD_TO_CART, BUTTON_IN_CART_ALT) . '</a>';

    $img_col_w = IMAGE_PRODUCT_NEW_WIDTH + 43;




    if (SHOW_PRODUCT_INFO_COLUMNS_NEW_PRODUCTS > 1 && $num_products_count > 1) {

    if ($col > 1 && $col < SHOW_PRODUCT_INFO_COLUMNS_NEW_PRODUCTS) {
    $tm_param = 'style="margin-left:45px;"';

    } elseif ($col > 0 && $col < SHOW_PRODUCT_INFO_COLUMNS_NEW_PRODUCTS){
    $tm_param = 'style="margin-left:23px; margin-right:10px;"';
    }
    else {
    $tm_param = '';
    }

    $list_box_contents[$row][$col] = array('params' => 'class="centerBoxContentsNew centeredContent back"' . ' ' . 'style="width:' . $col_width . '%;"',
    'text' =>

    '<div class="product-col" ' . $tm_param . '>
    <div class="img">
    ' . $products_img . '
    </div>
    <div class="prod-info">
    ' . $products_name . '

    <div class="text">
    ' . $products_desc . '
    </div>
    <div class="wrapper">
    <div class="price">
    ' . str_replace('&nbsp;', '', $products_price) . '
    </div>
    <div class="button">' . $products_######## . '</div>
    </div>
    </div>
    </div>'


    );

    } else {

    $list_box_contents[$row][$col] = array('params' =>'class="centerBoxContentsNew centeredContent back"' . ' ' . 'style="width:' . $col_width . '%;"',
    'text' =>

    '<div class="product-col" ' . $tm_param . '>
    <div class="img">
    ' . $products_img . '
    </div>
    <div class="prod-info">
    ' . $products_name . '

    <div class="text">
    ' . $products_desc . '
    </div>
    <div class="wrapper">
    <div class="price">
    ' . str_replace('&nbsp;', '', $products_price) . '
    </div>
    <div class="button">' . $products_######## . '</div>
    </div>
    </div>
    </div>'

    );

    }





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

    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;
    }
    }
    ?>

  2. #2
    Join Date
    Jan 2004
    Location
    N of San Antonio TX
    Posts
    9,684
    Plugin Contributions
    11

    Default Re: New products on index-page in reverse order

    You'll need to an an order similar to http://www.zen-cart.com/showthread.p...03#post1161403
    A little help with colors.
    myZenCartHost.com - Zen Cart Certified, PCI Compatible Hosting by JEANDRET
    Free SSL & Domain with semi-annual and longer hosting. Updating 1.5.2 and Up.

 

 

Similar Threads

  1. Replies: 0
    Last Post: 14 Sep 2011, 11:54 AM
  2. New Products Sort Order on Index Page, Question.
    By blackcap76 in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 5 May 2011, 02:52 AM
  3. Change sort order in new products box on index.php page
    By jolewin in forum Customization from the Admin
    Replies: 2
    Last Post: 28 Mar 2011, 05:11 AM
  4. Reverse sort order of products
    By TecBrat in forum Templates, Stylesheets, Page Layout
    Replies: 5
    Last Post: 11 Mar 2011, 09:39 PM
  5. EZ Page Links are in Reverse Order...
    By audradh in forum General Questions
    Replies: 0
    Last Post: 22 Sep 2008, 08:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg