Well I’ve started making addons out of old mods that have been on the forum and I need some help with one.
I am making the Random Products mod by Teksigns into an addon. The mod can be seen at [url]http://forum.cs-cart.com/showthread.php?t=13382[/url]
I have the addon working great, but I don’t know how to do a couple of steps of the addon instead of having to do them manually.
The first part I need help with is adding a language variable.
The sql code is:
INSERT INTO cscart_language_values (`lang_code`, `name`, `value`) VALUES ('EN', 'random_order', 'Random');
I believe it can be added into the addon.xml file, but I’m not exactly sure how to do it.
Here is my addon.xml file:
Part of this mod modifies the core/fn.catalog.php file. I was able to figure out how to do a .post for my other files, but I just don’t know how to do the core/fn.catalog.php
Here is what needs to be done:
After:
if ($params['type'] != 'extended' && $params['sort_by'] == 'price') {
$params['sort_by'] = 'product';
}
$default_sorting = fn_get_products_sorting(false);
Add:
if ($params['sort_order'] != 'random') {
And after:
// Reverse sorting (for usage in view)
$params['sort_order'] = $params['sort_order'] == 'asc' ? 'desc' : 'asc';
Add:
}
Also Replace:
$products = db_get_array('SELECT SQL_CALC_FOUND_ROWS ' . implode(', ', $fields) . " FROM ?:products as products $join WHERE 1 $condition GROUP BY $group_by ORDER BY $sorting $limit");
With:
if ($params['sort_order'] != 'random') {
$products = db_get_array('SELECT SQL_CALC_FOUND_ROWS ' . implode(', ', $fields) . " FROM ?:products as products $join WHERE 1 $condition GROUP BY $group_by ORDER BY $sorting $limit");
} else {
$products = db_get_array('SELECT SQL_CALC_FOUND_ROWS ' . implode(', ', $fields) . " FROM ?:products as products $join WHERE 1 $condition GROUP BY $group_by ORDER BY rand() $limit");
}
I have attached my addon to this post. The addon will totally work, but because of the above questions I’d wait to install it until after the solutions are found and the file is updated.
I’ll post the completed addon once it is done.
I really appreciate anyone’s help on this. It’s a cool addon and I’d like to learn how to do it the right way.
Thanks,
Brandon