Hello everyone,
I need help to sort the product list under “Manage Products” to be sorted in decending order by CODE.
I tried changing it under Settings>Appareance>Product list default sorting but it does not gives the option by CODE.
My client needs this with great urgency. I would appreciate anything you can do to help me. Thank you!
You can try the following solution. Replace the code in the [cscart_dir]/include/commmon/search_products.php file:
$avail_sortings = array(
'product' => 'descr1.product',
'position' => ($settings['General']['improved_product_search'] == 'Y') ? 'avail_products.position' : 'products_categories.position',
'price' => 'prices.price',
'weight' => 'products.weight',
'amount' => 'products.amount'
);
$avail_directions = array (
'ASC' => 'DESC',
'DESC' => 'ASC'
);
$search_condition = ' 1 ';
$join = '';
if (empty($search_data['sort_by'])) {
$search_data['sort_by'] = $settings['Appearance']['default_products_sorting'];
}
if (empty($avail_sortings[$search_data['sort_by']]) || $search_data['search_type'] == 'simple') {
$search_data['sort_by'] = 'product';
}
with this
$avail_sortings = array(
'product' => 'descr1.product',
'position' => ($settings['General']['improved_product_search'] == 'Y') ? 'avail_products.position' : 'products_categories.position',
'price' => 'prices.price',
'weight' => 'products.weight',
'amount' => 'products.amount',
'code' => 'products.product_code'
);
$avail_directions = array (
'ASC' => 'DESC',
'DESC' => 'ASC'
);
$search_condition = ' 1 ';
$join = '';
if (empty($search_data['sort_by'])) {
$search_data['sort_by'] = $settings['Appearance']['default_products_sorting'];
}
if (empty($avail_sortings[$search_data['sort_by']]) || $search_data['search_type'] == 'simple') {
$search_data['sort_by'] = 'product';
}
if (AREA == 'A') {
$search_data['sort_by'] = 'code';
}
I tried this, but it didn’t seem to work.
[quote name=‘imac’]
[/QUOTE]I changed the default behavior to sort on “product_code” by changing it to this:
$avail_sortings = array(
'product' => 'descr1.product',
'position' => ($settings['General']['improved_product_search'] == 'Y') ? 'avail_products.position' : 'products_categories.position',
'price' => 'prices.price',
'weight' => 'products.weight',
'amount' => 'products.amount',
'code' => 'products.product_code'
);
$avail_directions = array (
'ASC' => 'DESC',
'DESC' => 'ASC'
);
$search_condition = ' 1 ';
$join = '';
if (empty($search_data['sort_by'])) {
$search_data['sort_by'] = $settings['Appearance']['default_products_sorting'];
}
if (empty($avail_sortings[$search_data['sort_by']]) || $search_data['search_type'] == 'simple') {
$search_data['sort_by'] = 'product';
}
if (AREA == 'A') {
$search_data['sort_by'] = 'code';
}
```php
$avail_sortings = array(
‘product’ => ‘descr1.product’,
‘position’ => ($settings[‘General’][‘improved_product_search’] == ‘Y’) ? ‘avail_products.position’ : ‘products_categories.position’,
‘price’ => ‘prices.price’,
‘weight’ => ‘products.weight’,
‘amount’ => ‘products.amount’,
‘code’ => ‘products.product_code’
);
$avail_directions = array (
‘ASC’ => ‘DESC’,
‘DESC’ => ‘ASC’
);
$search_condition = ’ 1 ';
$join = ‘’;
if (empty($search_data[‘sort_by’])) {
$search_data[‘sort_by’] = $settings[‘Appearance’][‘default_products_sorting’];
}
if (empty($avail_sortings[$search_data[‘sort_by’]]) || $search_data[‘search_type’] == ‘simple’) {
$search_data[‘sort_by’] = ‘code’;
}
```See if it works for you by leaving Settings > Appearance > Product listing default sorting to “Default”.
Thank you so much iMac. Your code worked perfectly when I left it as DEFAULT. sculptingstudio, I tried yours as well, it seemed like a ‘cleaner’ code but unfortunatelly it did not work in my cart.
Thank you both for your time… By the way if you want to take a look at the cart (before it is password protected) it is at www.willbethinc.com/shop
Please don’t post any orders as it is live already.
[quote name=‘imac’]You can try the following solution. Replace the code in the [cscart_dir]/include/commmon/search_products.php file:
$avail_sortings = array(
'product' => 'descr1.product',
'position' => ($settings['General']['improved_product_search'] == 'Y') ? 'avail_products.position' : 'products_categories.position',
'price' => 'prices.price',
'weight' => 'products.weight',
'amount' => 'products.amount'
);
$avail_directions = array (
'ASC' => 'DESC',
'DESC' => 'ASC'
);
$search_condition = ' 1 ';
$join = '';
if (empty($search_data['sort_by'])) {
$search_data['sort_by'] = $settings['Appearance']['default_products_sorting'];
}
if (empty($avail_sortings[$search_data['sort_by']]) || $search_data['search_type'] == 'simple') {
$search_data['sort_by'] = 'product';
}
with this
[/QUOTE]
$avail_sortings = array(
'product' => 'descr1.product',
'position' => ($settings['General']['improved_product_search'] == 'Y') ? 'avail_products.position' : 'products_categories.position',
'price' => 'prices.price',
'weight' => 'products.weight',
'amount' => 'products.amount',
'code' => 'products.product_code'
);
$avail_directions = array (
'ASC' => 'DESC',
'DESC' => 'ASC'
);
$search_condition = ' 1 ';
$join = '';
if (empty($search_data['sort_by'])) {
$search_data['sort_by'] = $settings['Appearance']['default_products_sorting'];
}
if (empty($avail_sortings[$search_data['sort_by']]) || $search_data['search_type'] == 'simple') {
$search_data['sort_by'] = 'product';
}
if (AREA == 'A') {
$search_data['sort_by'] = 'code';
}