Questions about making an addon

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:




random
Random Products
1
300
active





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

Ok, I figured out how to change the language file using the addon and re-uploaded the zip file to reflect that. Now I don’t have to do the sql thing.



I still don’t know how to make the core.php file into a post instead of just overwriting the file.



If anyone can help I would really appreciate it.



Thanks,



Brandon

Hi Brandon, the language file would be added in the XML like this:


```php




random

Random Products

1

300

active



[COLOR=Red]



Random

[/COLOR]





```I don’t have time to figure out the rest as I’m working on getting the Knowledge Base, Helpdesk and Support Points/Period Addons ready for release in the next day or so, Thanks - Sno

Thanks Sno, I always appreciate your help.



That was exactly what I added into the updated files that I posted above. I actually beat you to the solution by about 20 hours or so.



Now if I could just figure out the second part about the core file I’ll be all set.



Thanks,



Brandon