I’m just learning cs-cart. I’m doing a side project with a shopping cart, and I’m using it because it does seem like basically good code.
The thing is, it doesn’t matter if the project is changing or not. As far as I can tell, there’s NO WAY to make a plugin that does anything meaningful without using the function hooks, and there’s no documentation.
My first modification was just a test to see if I could figure out the architecture, a way to add a paragraph of text that is associated with a category. There’s probably already a way to do that in cs-cart, but I wanted to learn the architecture.
So, I needed to add a box to the admin area for categories. I needed to know what function was called when a category was being updated in admin so I could hook into it. There’s no documentation, so I just traced back through the code till I found the function, which is ‘update_category’. Here’s the relevant part of init.php
[QUOTE]fn_register_hooks(
‘update_category’
);
[/QUOTE]
Now, according to the documentation, I’ve created a hook that is called every time that update_category is called. My addon is called “category_news” so the naming convention has me name my function ‘fn_category_news_update_category’. That function will get called with all the parameters that are passed to ‘update_category’ in the core code. Without a list of both the hook functions AND their parameters, I had to use the parameter list I found in the core source code. It is too much to ask of developers that they have to read all your source code to figure out how to develop for your platform. That’s a huge pain.
For what it’s worth, here is the code that handles the data passed in from my form in the admin view. I’m leaving out the templates, they’re simple too. All I did was add another form field in the category update area via my plugin.
[QUOTE]function fn_category_news_update_category($category_data, $category_id = 0, $lang_code = CART_LANGUAGE)
{
$data = array (
‘news_title’ => $_POST[‘category_news_headline’],
‘news_body’ => $_POST[‘category_news’],
);
$insertData = array (
‘news_title’ => $_POST[‘category_news_headline’],
‘news_body’ => $_POST[‘category_news’],
‘category_id’ => $_POST[‘category_id’]
);
#does it exist?
$checkExistingNews = db_get_row(“SELECT * from ?:category_news where category_id = ?i”, $category_id);
if (!$checkExistingNews) {
db_query(‘INSERT INTO ?:category_news ?e’, $insertData);
}
else {
db_query(‘UPDATE ?:category_news SET ?u WHERE category_id = ?i’, $data, $category_id);
}
return true;
}[/QUOTE]
This handles the process of saving the data, and it’s where the crucial piece of documentation is missing.
The part that handles the displaying of the data in the admin area (I haven’t built the customer view, as this was just an experiment) is simple. I just put a file in the addons directory that is under category_news->controllers->admin and is called “categories.post.php”. That means "run this code after the native “categories” code is called.
That code, if it matters, looks like this:
[QUOTE]if ($mode == ‘update’) {
// Assign news to categories
Registry::set(‘navigation.tabs.category_news’, array (
‘title’ => ‘Category News’,
‘js’ => true
));
$category_id = $_GET[‘category_id’];
$checkExistingNews = db_get_row(“SELECT * from ?:category_news where category_id = ?i”, $category_id);
if ($checkExistingNews) {
$view->assign(‘category_news’, str_replace(“\'”, “'”, $checkExistingNews[‘news_body’]));
$view->assign(‘category_news_headline’, str_replace(“\'”, “'”, $checkExistingNews[‘news_title’]));
}
}[/QUOTE]