Is there anyway to display Random products in a Listmania?
This should be a basic feature and yet it’s not available on CS-Cart…
Was anyone able to code this?
[quote name=‘gugga7’]Is there anyway to display Random products in a Listmania?
This should be a basic feature and yet it’s not available on CS-Cart…
Was anyone able to code this?[/QUOTE]
Try to do the following:
1)Replace the following part of code:
case LM_IMPULSE_BUYING: // impulse_buying
break;
}
with this one:
case LM_IMPULSE_BUYING: // impulse_buying
break;
case LM_RANDOM_PRODUCTS: // random
$resultar = array();
$arr = 0; $defaultex = 0;
while(($arr < @$item['qantity_products']) && ($defaultex < 10000)) {
$itear = rand(@$item['min_product_id'],@$item['max_product_id']);
$inventory_join = '';
$inventory_condition = '';
if ($settings['General']['show_out_of_stock_products'] == 'N' && AREA == 'C') {
$inventory_join .= " LEFT JOIN $db_tables[product_options_inventory] as inventory ON inventory.product_id=$db_tables[products].product_id";
$inventory_condition .= " AND IF($db_tables[products].tracking='O', inventory.amount>0, $db_tables[products].amount>0)";
}
$idexi = db_get_field("SELECT $db_tables[products].product_id FROM $db_tables[products] $inventory_join WHERE $db_tables[products].product_id = $itear $inventory_condition");
if (!(empty($idexi)) && !(in_array($idexi,$resultar))) {
$resultar[] = $itear;
$arr++;
}
$defaultex++;
}
$query .= " $db_tables[products].product_id IN ('".implode("','", $resultar)."')";
// Adding condition for the "Show out of stock products" setting
$objects = db_get_array("SELECT $db_tables[products].product_id, $db_tables[product_descriptions].product FROM $db_tables[products] LEFT JOIN $db_tables[product_descriptions] ON $db_tables[product_descriptions].product_id=$db_tables[products].product_id WHERE $query ORDER BY $db_tables[product_descriptions].product ASC");
if (!empty($objects)) {
$objects_list = array();
foreach ($objects as $product) {
$objects_list[$product['product_id']] = array('object_id'=>$product['product_id'], 'object' => $product['product']);
}
}
break;
}
in the “/addons/listmania/func.php” file.
2)Replace the following part of code:
define('LM_IMPULSE_BUYING', 3007);
// appearance box
with this one:
define('LM_IMPULSE_BUYING', 3007);
define('LM_RANDOM_PRODUCTS', 3008);
// appearance box
and replace this one:
$lm_type = array();
$lm_type[LM_MANUALLY_SET] = 'manually_set';
$lm_type[LM_DATE_CREATED] = 'newest';
with this one:
$lm_type = array();
$lm_type[LM_MANUALLY_SET] = 'manually_set';
$lm_type[LM_RANDOM_PRODUCTS] = 'random_set';
$lm_type[LM_DATE_CREATED] = 'newest';
in the “/addons/listmania/config.php” file.
3)Replace the following part of code:
```php
{if $lm_list.type|fn_lm_check_enabled_addons}{$lm_list.type|fn_lm_check_enabled_addons} {/if}
{if $lm_list.type == $smarty.const.LM_DATE_CREATED}
{$lang.specific_settings} »
{$lang.period}:
{$lang.any_date}
{$lang.today}
{$lang.last_n_days}
{$lang.last_days}:
{/if}
```
with this one:
```php
{$lang.type}:
{if $lm_list.type|fn_lm_check_enabled_addons}{$lm_list.type|fn_lm_check_enabled_addons} {/if}
{if $lm_list.type == $smarty.const.LM_DATE_CREATED}
{$lang.specific_settings} »
{$lang.period}:
{$lang.any_date}
{$lang.today}
{$lang.last_n_days}
{$lang.last_days}:
{else}
{if $lm_list.type == $smarty.const.LM_RANDOM_PRODUCTS}
{$lang.specific_settings} »
{$lang.qantity_products}:
{$lang.min_product_id}:
{$lang.max_product_id}:
{/if}
{/if}
```
in the "/skins/ADMINISTRATOR_ACTIVE_SKIN/admin/addons/listmania/list_update.tpl" file.
4)Log in the administrator back-end, click on the "DB Backup/Restore" link in the "Administration" sidebox, after that click on the "Upgrade center" link and after that enter the following query into the text area of the "Update database" section:
```php
ALTER TABLE `cscart_listmania_list_types` ADD `quantity_products` INT( 11 ) UNSIGNED NOT NULL DEFAULT '5';
```
click on the "Submit" button then enter the following query into the text area of the "Update database" section:
```php
ALTER TABLE `cscart_listmania_list_types` ADD `min_product_id` INT( 11 ) UNSIGNED NOT NULL DEFAULT '1';
```
click on the "Submit" button then enter the following query into the text area of the "Update database" section:
```php
ALTER TABLE `cscart_listmania_list_types` ADD `max_product_id` INT( 11 ) UNSIGNED NOT NULL DEFAULT '1';
```
click on the "Submit" button
5) Add the following language variables on the "Languages" page of your administrator panel:
quantity_products The number of products
min_product_id Minimum product id
max_product_id Maximum product id
Thank you very much for looking into this. I tried several times the steps above, checked the code again and again, but it’s not working for me, no Random list is populated in the homepage and I don’t see the “random” label when setting up Listmania (see screenshots).
Did I miss something?
[quote name=‘gugga7’]Thank you very much for looking into this. I tried several times the steps above, checked the code again and again, but it’s not working for me, no Random list is populated in the homepage
[/quote]
Sorry my mistake . Please replace the “qantity_products” variable with “quantity_products” variable in the “/addons/listmania/func.php” and “/skins/ADMINISTRATOR_ACTIVE_SKIN/admin/addons/listmania/list_update.tpl” files
[quote]
and I don’t see the “random” label when setting up Listmania (see screenshots).
Did I miss something?[/QUOTE]
Sorry I forgot to say you to add the following language variable
random_set Random set
These 2 issues were fixed
However, no Listmania appears in the homepage. Did anyone of you out there tried this successfully?
I’m attaching the 3 files I modified.
[quote name=‘gugga7’]These 2 issues were fixed
However, no Listmania appears in the homepage. Did anyone of you out there tried this successfully?
I’m attaching the 3 files I modified.[/QUOTE]
Same for me. Random items simply do not appear in home page. Something is wrong.
Pardon.
It work when I set minimum product id to 10000 and max to 50000. What are the correct numbers ?
you’re right ! Not sure about the correct numbers though…
But now it also shows the Non-available and Hidden products…
I think there is something missing in the code that allows only Available products to display instead of any product.
[quote name=‘gugga7’]you’re right ! Not sure about the correct numbers though…
But now it also shows the Non-available and Hidden products…
I think there is something missing in the code that allows only Available products to display instead of any product.[/QUOTE]
I have enabled out of stock, sold products in categories. But these products should not be shown in home page, hidden also, some “if” statement is missing …
[quote name=‘Darius’]Pardon.
It work when I set minimum product id to 10000 and max to 50000. What are the correct numbers ?[/QUOTE]
Please let me explain.
The minimum_product_id is the minimum product id from which system begins to take random products(it must not be less than the minimum product id in your store).
The maximum_product_id is the maximum product id which is limited the random products(it must not be more than the maximum product id in your store).
[quote name=‘Darius’]I have enabled out of stock, sold products in categories. But these products should not be shown in home page, hidden also, some “if” statement is missing …[/QUOTE]
In order to resolve this problem replace the following part of code:
case LM_RANDOM_PRODUCTS: // random
$resultar = array();
$arr = 0; $defaultex = 0;
while(($arr < @$item['quantity_products']) && ($defaultex < 10000)) {
$itear = rand(@$item['min_product_id'],@$item['max_product_id']);
$inventory_join = '';
$inventory_condition = '';
if ($settings['General']['show_out_of_stock_products'] == 'N' && AREA == 'C') {
$inventory_join .= " LEFT JOIN $db_tables[product_options_inventory] as inventory ON inventory.product_id=$db_tables[products].product_id";
$inventory_condition .= " AND IF($db_tables[products].tracking='O', inventory.amount>0, $db_tables[products].amount>0)";
}
$idexi = db_get_field("SELECT $db_tables[products].product_id FROM $db_tables[products] $inventory_join WHERE $db_tables[products].product_id = $itear $inventory_condition");
if (!(empty($idexi)) && !(in_array($idexi,$resultar))) {
$resultar[] = $itear;
$arr++;
}
$defaultex++;
}
$query .= " $db_tables[products].product_id IN ('".implode("','", $resultar)."')";
// Adding condition for the "Show out of stock products" setting
$objects = db_get_array("SELECT $db_tables[products].product_id, $db_tables[product_descriptions].product FROM $db_tables[products] LEFT JOIN $db_tables[product_descriptions] ON $db_tables[product_descriptions].product_id=$db_tables[products].product_id WHERE $query ORDER BY $db_tables[product_descriptions].product ASC");
if (!empty($objects)) {
$objects_list = array();
foreach ($objects as $product) {
$objects_list[$product['product_id']] = array('object_id'=>$product['product_id'], 'object' => $product['product']);
}
}
break;
}
with this one:
case LM_RANDOM_PRODUCTS: // random
$resultar = array();
$arr = 0; $defaultex = 0;
while(($arr < @$item['quantity_products']) && ($defaultex < 10000)) {
$itear = rand(@$item['min_product_id'],@$item['max_product_id']);
$inventory_join = '';
$inventory_condition = '';
$inventory_join .= " LEFT JOIN $db_tables[product_options_inventory] as inventory ON inventory.product_id=$db_tables[products].product_id";
$inventory_condition .= " AND IF($db_tables[products].tracking='O', inventory.amount>0, $db_tables[products].amount>0)";
$idexi = db_get_field("SELECT $db_tables[products].product_id FROM $db_tables[products] $inventory_join WHERE $db_tables[products].product_id = $itear AND $db_tables[products].avail = 'Y' $inventory_condition");
if (!(empty($idexi)) && !(in_array($idexi,$resultar))) {
$resultar[] = $itear;
$arr++;
}
$defaultex++;
}
$query .= " $db_tables[products].product_id IN ('".implode("','", $resultar)."')";
// Adding condition for the "Show out of stock products" setting
$objects = db_get_array("SELECT $db_tables[products].product_id, $db_tables[product_descriptions].product FROM $db_tables[products] LEFT JOIN $db_tables[product_descriptions] ON $db_tables[product_descriptions].product_id=$db_tables[products].product_id WHERE $query ORDER BY $db_tables[product_descriptions].product ASC");
if (!empty($objects)) {
$objects_list = array();
foreach ($objects as $product) {
$objects_list[$product['product_id']] = array('object_id'=>$product['product_id'], 'object' => $product['product']);
}
}
break;
}
in the “/addons/listmania/func.php” file.
Fixed !
Thanks a lot, you just made my day
[quote name=‘gugga7’]Fixed !
Thanks a lot, you just made my day ;)[/QUOTE]
You are welcome!
[quote name=‘forward’]You are welcome![/QUOTE]
Works well, thank you!
Haha!
With code changes that mr forward provided it seems like we rewrite the cs-cart from the scratch!
AhaHa!
Cheers!