Follow along with the video below to see how to install our site as a web app on your home screen.
Примечание: This feature may not be available in some browsers.
Меня интересует как сделать сортировку товаров по дате добавления, помогите решить эту проблему.
Аразве так вообще можно сортировать?Где именно интересует сортировка
(в каком разделе Админ|Пользователь, в каком подрязделе)
define('STRING_PRODUCT_SORT', 'Сортировать по: наименованию ({ASC_NAME} | {DESC_NAME}), цене ({ASC_PRICE} | {DESC_PRICE}), рейтингу ({ASC_RATING} | {DESC_RATING})');
// NOT ORIGINGAL: SORTING BY DATE ADDED
define('STRING_PRODUCT_SORT', 'Сортировать по: наименованию ({ASC_NAME} | {DESC_NAME}), цене ({ASC_PRICE} | {DESC_PRICE}), рейтингу ({ASC_RATING} | {DESC_RATING}), дате ({ASC_DATE} | {DESC_DATE})');
function _sortSetting( &$smarty, $urlToSort )
{
$sort_string = STRING_PRODUCT_SORT;
$sort_string = str_replace( "{ASC_NAME}", "<a href='".$urlToSort."&sort=name&direction=ASC'>".STRING_ASC."</a>", $sort_string );
$sort_string = str_replace( "{DESC_NAME}", "<a href='".$urlToSort."&sort=name&direction=DESC'>".STRING_DESC."</a>", $sort_string );
$sort_string = str_replace( "{ASC_PRICE}", "<a href='".$urlToSort."&sort=Price&direction=ASC'>".STRING_ASC."</a>", $sort_string );
$sort_string = str_replace( "{DESC_PRICE}", "<a href='".$urlToSort."&sort=Price&direction=DESC'>".STRING_DESC."</a>", $sort_string );
$sort_string = str_replace( "{ASC_RATING}", "<a href='".$urlToSort."&sort=customers_rating&direction=ASC'>".STRING_ASC."</a>", $sort_string );
$sort_string = str_replace( "{DESC_RATING}", "<a href='".$urlToSort."&sort=customers_rating&direction=DESC'>".STRING_DESC."</a>", $sort_string );
$smarty->assign( "string_product_sort", $sort_string );
}
function _sortSetting( &$smarty, $urlToSort )
{
$sort_string = STRING_PRODUCT_SORT;
$sort_string = str_replace( "{ASC_NAME}", "<a href='".$urlToSort."&sort=name&direction=ASC'>".STRING_ASC."</a>", $sort_string );
$sort_string = str_replace( "{DESC_NAME}", "<a href='".$urlToSort."&sort=name&direction=DESC'>".STRING_DESC."</a>", $sort_string );
$sort_string = str_replace( "{ASC_PRICE}", "<a href='".$urlToSort."&sort=Price&direction=ASC'>".STRING_ASC."</a>", $sort_string );
$sort_string = str_replace( "{DESC_PRICE}", "<a href='".$urlToSort."&sort=Price&direction=DESC'>".STRING_DESC."</a>", $sort_string );
$sort_string = str_replace( "{ASC_RATING}", "<a href='".$urlToSort."&sort=customers_rating&direction=ASC'>".STRING_ASC."</a>", $sort_string );
$sort_string = str_replace( "{DESC_RATING}", "<a href='".$urlToSort."&sort=customers_rating&direction=DESC'>".STRING_DESC."</a>", $sort_string );
// NOT ORIGINAL: SORT BY DATE ADDED
$sort_string = str_replace( "{ASC_DATE}", "<a href='".$urlToSort."&sort=date_added&direction=ASC'>".STRING_ASC."</a>", $sort_string );
$sort_string = str_replace( "{DESC_DATE}", "<a href='".$urlToSort."&sort=date_added&direction=DESC'>".STRING_DESC."</a>", $sort_string );
$smarty->assign( "string_product_sort", $sort_string );
}
if ( $callBackParam["sort"] == "categoryID" ||
$callBackParam["sort"] == "name" ||
$callBackParam["sort"] == "brief_description" ||
$callBackParam["sort"] == "in_stock" ||
$callBackParam["sort"] == "Price" ||
$callBackParam["sort"] == "customer_votes" ||
$callBackParam["sort"] == "customers_rating" ||
$callBackParam["sort"] == "list_price" ||
$callBackParam["sort"] == "sort_order" ||
$callBackParam["sort"] == "items_sold" ||
$callBackParam["sort"] == "product_code" ||
$callBackParam["sort"] == "shipping_freight" )
if ( $callBackParam["sort"] == "categoryID" ||
$callBackParam["sort"] == "name" ||
$callBackParam["sort"] == "brief_description" ||
$callBackParam["sort"] == "in_stock" ||
$callBackParam["sort"] == "Price" ||
$callBackParam["sort"] == "customer_votes" ||
$callBackParam["sort"] == "customers_rating" ||
$callBackParam["sort"] == "list_price" ||
$callBackParam["sort"] == "sort_order" ||
$callBackParam["sort"] == "items_sold" ||
$callBackParam["sort"] == "product_code" ||
// NOT ORIGINAL: SORT BY DATE ADDED
$callBackParam["sort"] == "date_added" ||
$callBackParam["sort"] == "shipping_freight" )
Сортировка товаров в категории по дате добавления
ВНИМАНИЕ: Не забывайте делать backup перед изменением файлов!
Модификация выполняется в три шага:
Шаг 1.
Файл: languages/russian.php
Найти:
PHP:define('STRING_PRODUCT_SORT', 'Сортировать по: наименованию ({ASC_NAME} | {DESC_NAME}), цене ({ASC_PRICE} | {DESC_PRICE}), рейтингу ({ASC_RATING} | {DESC_RATING})');
Заменить на:
PHP:// NOT ORIGINGAL: SORTING BY DATE ADDED define('STRING_PRODUCT_SORT', 'Сортировать по: наименованию ({ASC_NAME} | {DESC_NAME}), цене ({ASC_PRICE} | {DESC_PRICE}), рейтингу ({ASC_RATING} | {DESC_RATING}), дате ({ASC_DATE} | {DESC_DATE})');
Шаг 2.
Файл: includes/category.php
Найти:
PHP:function _sortSetting( &$smarty, $urlToSort ) { $sort_string = STRING_PRODUCT_SORT; $sort_string = str_replace( "{ASC_NAME}", "<a href='".$urlToSort."&sort=name&direction=ASC'>".STRING_ASC."</a>", $sort_string ); $sort_string = str_replace( "{DESC_NAME}", "<a href='".$urlToSort."&sort=name&direction=DESC'>".STRING_DESC."</a>", $sort_string ); $sort_string = str_replace( "{ASC_PRICE}", "<a href='".$urlToSort."&sort=Price&direction=ASC'>".STRING_ASC."</a>", $sort_string ); $sort_string = str_replace( "{DESC_PRICE}", "<a href='".$urlToSort."&sort=Price&direction=DESC'>".STRING_DESC."</a>", $sort_string ); $sort_string = str_replace( "{ASC_RATING}", "<a href='".$urlToSort."&sort=customers_rating&direction=ASC'>".STRING_ASC."</a>", $sort_string ); $sort_string = str_replace( "{DESC_RATING}", "<a href='".$urlToSort."&sort=customers_rating&direction=DESC'>".STRING_DESC."</a>", $sort_string ); $smarty->assign( "string_product_sort", $sort_string ); }
Заменить на:
PHP:function _sortSetting( &$smarty, $urlToSort ) { $sort_string = STRING_PRODUCT_SORT; $sort_string = str_replace( "{ASC_NAME}", "<a href='".$urlToSort."&sort=name&direction=ASC'>".STRING_ASC."</a>", $sort_string ); $sort_string = str_replace( "{DESC_NAME}", "<a href='".$urlToSort."&sort=name&direction=DESC'>".STRING_DESC."</a>", $sort_string ); $sort_string = str_replace( "{ASC_PRICE}", "<a href='".$urlToSort."&sort=Price&direction=ASC'>".STRING_ASC."</a>", $sort_string ); $sort_string = str_replace( "{DESC_PRICE}", "<a href='".$urlToSort."&sort=Price&direction=DESC'>".STRING_DESC."</a>", $sort_string ); $sort_string = str_replace( "{ASC_RATING}", "<a href='".$urlToSort."&sort=customers_rating&direction=ASC'>".STRING_ASC."</a>", $sort_string ); $sort_string = str_replace( "{DESC_RATING}", "<a href='".$urlToSort."&sort=customers_rating&direction=DESC'>".STRING_DESC."</a>", $sort_string ); // NOT ORIGINAL: SORT BY DATE ADDED $sort_string = str_replace( "{ASC_DATE}", "<a href='".$urlToSort."&sort=date_added&direction=ASC'>".STRING_ASC."</a>", $sort_string ); $sort_string = str_replace( "{DESC_DATE}", "<a href='".$urlToSort."&sort=date_added&direction=DESC'>".STRING_DESC."</a>", $sort_string ); $smarty->assign( "string_product_sort", $sort_string ); }
Шаг 3.
Файл: core_functions/product_functions.php
Найти (почти в самом низу файла, строка №1054
PHP:if ( $callBackParam["sort"] == "categoryID" || $callBackParam["sort"] == "name" || $callBackParam["sort"] == "brief_description" || $callBackParam["sort"] == "in_stock" || $callBackParam["sort"] == "Price" || $callBackParam["sort"] == "customer_votes" || $callBackParam["sort"] == "customers_rating" || $callBackParam["sort"] == "list_price" || $callBackParam["sort"] == "sort_order" || $callBackParam["sort"] == "items_sold" || $callBackParam["sort"] == "product_code" || $callBackParam["sort"] == "shipping_freight" )
Заменить на:
PHP:if ( $callBackParam["sort"] == "categoryID" || $callBackParam["sort"] == "name" || $callBackParam["sort"] == "brief_description" || $callBackParam["sort"] == "in_stock" || $callBackParam["sort"] == "Price" || $callBackParam["sort"] == "customer_votes" || $callBackParam["sort"] == "customers_rating" || $callBackParam["sort"] == "list_price" || $callBackParam["sort"] == "sort_order" || $callBackParam["sort"] == "items_sold" || $callBackParam["sort"] == "product_code" || // NOT ORIGINAL: SORT BY DATE ADDED $callBackParam["sort"] == "date_added" || $callBackParam["sort"] == "shipping_freight" )
Пожалуйста, сообщите о результатах тестирования, если будут какие-либо вопросы - пишите в данной ветке.
Примечание: На основе данной модификации можно проводить сортировку по любому свойства товара.
Спасибо ОГРОМНОЕ!!! все работает прекрасно!!!! не хочу казаться наглым, а как еще вывести дату добавления к товару типа чтоб под каждым товаром было "добавлено хх.хх.ххх" ?
$navigatorHtml = GetNavigatorHtml(
_getUrlToNavigate( $categoryID ), CONF_PRODUCTS_PER_PAGE,
'prdSearchProductByTemplate', $callBackParam,
$products, $offset, $count );
$navigatorHtml = GetNavigatorHtml(
_getUrlToNavigate( $categoryID ), CONF_PRODUCTS_PER_PAGE,
'prdSearchProductByTemplate', $callBackParam,
$products, $offset, $count );
// NOT ORIGINAL: DATA FORMAT + OUTPUT ADDED
for ($i=0;$i<count($products);$i++)
{
$product_date_added = (date("d/m/Y", strtotime($products[$i]["date_added"])));
$products[$i]["date_added"] = $product_date_added;
}
$sqlQuery = "
SELECT categoryID, name, brief_description, customers_rating, Price, in_stock, customer_votes, list_price, productID,
default_picture, sort_order, items_sold, enabled, product_code, description, shipping_freight FROM ".PRODUCTS_TABLE." $where_clause $order_by_clause
";
$sqlQuery = "
SELECT categoryID, name, brief_description, customers_rating, Price, in_stock, customer_votes, list_price, productID,
default_picture, sort_order, items_sold, enabled, product_code, description, shipping_freight, date_added FROM ".PRODUCTS_TABLE." $where_clause $order_by_clause
";
<!-- NOT ORIGINAL : DATE ADDED : START -->
<strong>Добавлено:</strong> {$product_info.date_added}
<!-- NOT ORIGINAL : DATE ADDED : END -->
Как вывести дату добавления для каждого товара:
Выполняется в три шага:
Шаг 1.
Файл: includes/category.php
Найти:
PHP:$navigatorHtml = GetNavigatorHtml( _getUrlToNavigate( $categoryID ), CONF_PRODUCTS_PER_PAGE, 'prdSearchProductByTemplate', $callBackParam, $products, $offset, $count );
Заменить на:
PHP:$navigatorHtml = GetNavigatorHtml( _getUrlToNavigate( $categoryID ), CONF_PRODUCTS_PER_PAGE, 'prdSearchProductByTemplate', $callBackParam, $products, $offset, $count ); // NOT ORIGINAL: DATA FORMAT + OUTPUT ADDED for ($i=0;$i<count($products);$i++) { $product_date_added = (date("d/m/Y", strtotime($products[$i]["date_added"]))); $products[$i]["date_added"] = $product_date_added; }
Шаг 2.
Файл: core_functions/product_functions.php
Найти (почти в самом низу файла
PHP:$sqlQuery = " SELECT categoryID, name, brief_description, customers_rating, Price, in_stock, customer_votes, list_price, productID, default_picture, sort_order, items_sold, enabled, product_code, description, shipping_freight FROM ".PRODUCTS_TABLE." $where_clause $order_by_clause ";
Заменить на:
PHP:$sqlQuery = " SELECT categoryID, name, brief_description, customers_rating, Price, in_stock, customer_votes, list_price, productID, default_picture, sort_order, items_sold, enabled, product_code, description, shipping_freight, date_added FROM ".PRODUCTS_TABLE." $where_clause $order_by_clause ";
Шаг 3.
Файл: templates/frontend/tmpl_ВАШ_НОМЕР_ШАБЛОНА/product_brief.tpl.html
В нужно месте шаблона вставить:
Код:<!-- NOT ORIGINAL : DATE ADDED : START --> <strong>Добавлено:</strong> {$product_info.date_added} <!-- NOT ORIGINAL : DATE ADDED : END -->
Пожалуйста, сообщите о результатах.