Trying to create a new addon/block

I am trying to create a new block or even a page that i can have in the site content



the data will be pulled from the cscart database and i already have the php wrote for what i need done and it works fine. now how do i get this to show up on the customer side of the website?

Did you create a controller/mode for this? The MODE will designate what the template name is. If you want it as a custom block, you will need to add the appropriate schema entries to have the block definition visible to the admin interface where you can the specify the block properties and position the block where you want it.



To help you, we really need more detail about what you've done, how you've done it and what you're really trying to accomplish.

I am also interested in creating a new page for customers (My dashboard). I want to list in this page some info from database. I know how to make the php for it, but i don't know how to integrate this page into the cs-cart system.



Can you help me with a little tutorial or some info?



Thank you




[quote name='tbirnseth' timestamp='1322612081' post='126977']

Did you create a controller/mode for this? The MODE will designate what the template name is. If you want it as a custom block, you will need to add the appropriate schema entries to have the block definition visible to the admin interface where you can the specify the block properties and position the block where you want it.



To help you, we really need more detail about what you've done, how you've done it and what you're really trying to accomplish.

[/quote]

Basic info is that there is a controller and mode for various operations.

When you call a controller.mode (such as dispatch=my_changes.my_info) then after the addons/my_changes/controllers/customer/my_changes.php file completes and you do a return array(CONTROLLER_STATUS_OK), it will then pass whatever variables you set to the file

skins//customer/addons/my_changes/views/my_changes/my_info.tpl (or whatever mode you invoked).



That's the basic flow.

Thank you for tips!



I've created

addons/my_changes/controllers/customer/my_changes.php

with a simple code

if ($mode == 'my_info')
{
$i++;
return array(CONTROLLER_STATUS_OK);
}
?>

and
skins//customer/addons/my_changes/views/my_changes/my_info.tpl
but /index.php?dispatch=my_changes.my_info returns me Page not found

What i am missing?


[quote name='tbirnseth' timestamp='1323935515' post='127888']
Basic info is that there is a controller and mode for various operations.
When you call a controller.mode (such as dispatch=my_changes.my_info) then after the addons/my_changes/controllers/customer/my_changes.php file completes and you do a return array(CONTROLLER_STATUS_OK), it will then pass whatever variables you set to the file
skins//customer/addons/my_changes/views/my_changes/my_info.tpl (or whatever mode you invoked).

That's the basic flow.
[/quote]

You don't seem to be missing anything assuming 2 things.

  1. is the actual installed and active skin name for the customer view
  2. you have cleared your page cache via ?cc



    Assuming you have something in your tpl file that will display/render.

Yes! It works! I created the wrong directory “view” instead of “views”.

Thank you! It's a very good tip to create a custom page!



One more question:

What conditions i have to put in the .php file to allow access only to authorized users to the my_info.tpl content and the rest to be redirected to login page/form?


If( empty($_SESSION['auth']['user_id']) ) {
fn_set_notification('E', $controller.$mode, "Permission denied");
return array(CONTROLLER_STATUS_REDIRECT, INDEX_SCRIPT);
}

Thanks!

I also found this solution for a redirect to login form:



if( empty($_SESSION['auth']['user_id']) ) {

return array(CONTROLLER_STATUS_REDIRECT, "auth.login_form?return_url=" . urlencode(Registry::get('config.current_url')));
}





[quote name='tbirnseth' timestamp='1324577783' post='128288']


If( empty($_SESSION['auth']['user_id']) ) {
fn_set_notification('E', $controller.$mode, "Permission denied");
return array(CONTROLLER_STATUS_REDIRECT, INDEX_SCRIPT);
}


[/quote]

I am retruning to this topic…

How can i add pagination in this new page? I have a lots of records to show in this page and i want to show them in a pagination system.



Thanks

well I certainly wasnt receiving updates to this but I manged to figure it out all on my own.



[color=#282828][font=arial, verdana, tahoma, sans-serif]I am pretty excited with how easy it was to write an addon. The biggest hurdle was learning the controllers and how different aspects all worth together. Then getting the sql query to give me the correct data in the correct order and assigning it to smarty…[/font][/color]



[color=#282828][font=arial, verdana, tahoma, sans-serif]So without rambling on too much further, here is a screenshot of what I have so far. Needs some more work for the functions I want to add. Big thanks to snorocket for inventory location idea.[/font][/color]

Untitled2.png

Take a look at other admin addons like skins/basic/admin/views/orders/details.tpl

and you see includes for common_templates/pagination.tpl

that surround what you want paged.

The url for my page is: /index.php?dispatch=activation.info



I have: addons/my_changes/controllers/customer/activation.php



[font=courier new,courier,monospace] if ( !defined('AREA') ) { die('Access denied'); }

if ($mode == 'info') {
$actcode=$_GET['note'];
$view->assign('actcode',$actcode);
return array(CONTROLLER_STATUS_OK);
}
?>
[/font]



and skins//customer/addons/my_changes/views/my_changes/info.tpl



[i][font=courier new,courier,monospace]



Note:



Show note: {$actcode}[/font][/i]


The problem is that after i enter "abcd" in the text field and i press Submit i am redirect to: [i]/index.php?note=abcd&Info=Submit instead[/i] of
[i]/[/i][i][font=courier new,courier,monospace]index.php?dispatch=activation.info[/font][/i]

I want to show (in the same page) the field which i take from the input field.
I think the problem is the action of the form.

Do you have any idea how these things work?

Thanks

You're not understanding how controllers work.

You either need to create a new addon named 'activation' or you need to use 'activation' as a mode within your 'my_changes' addon (controller).

Basically, I need a page with a form that receives a variable (a text field), processes it and shows the result in the same page or in a new page.



Can it be done with my_changes or do I need a new addon?

Sure, my_changes is just an addon…

I think I described above what you need to do.

Hello everyone…



I'm trying to create a custom search menu in the homepage of a site created by cs cart!

I created a new block on the page (html block) and now I'm trying to understand how this thing works!! :confused:



As I undestood, I must create the php file in the controllers (controllers/customer/) and a corresponding view in views (skins/basic/customer/views). Are we good so far?



Now, how do I make it work? I say the example above, jarody used this action=“index.php?dispatch=activation.info” for his activation.php file. But I don't understand the mode=='info' part… Should I choose from the ones that already exist, or should I create my own??

[quote name='openkite' timestamp='1343289454' post='141478']

Hello everyone…



I'm trying to create a custom search menu in the homepage of a site created by cs cart!

I created a new block on the page (html block) and now I'm trying to understand how this thing works!! :confused:



As I undestood, I must create the php file in the controllers (controllers/customer/) and a corresponding view in views (skins/basic/customer/views). Are we good so far?



Now, how do I make it work? I say the example above, jarody used this action=“index.php?dispatch=activation.info” for his activation.php file. But I don't understand the mode=='info' part… Should I choose from the ones that already exist, or should I create my own??

[/quote]



First off, the file locations are incorrect. Your controller should go into addons/your_addon/controllers/(customer or admin) and your view goes into stores/1/skins/basic/customer/addons/your_addon/views/your_addon/.



As for the mode part, it's really simply. When you issue a dispatch of activation.info, it looks for the activation controller and view. In the controller, the mode is the 2nd portion of the dispatch. In your case, info. For the view, it's looking for view.tpl. If your dispatch was changed to openkite.fly_away then it look for the openkite addon folder. In the controller file it will be looking for mode == 'fly_away' to perform what is contained there and it will display these results on fly_away.tpl. You can add whatever mode you want as long as your controller and your view are setup to handle them.

[quote name=‘TVKevin’ timestamp=‘1343316048’ post=‘141521’]

First off, the file locations are incorrect. Your controller should go into addons/your_addon/controllers/(customer or admin) and your view goes into stores/1/skins/basic/customer/addons/your_addon/views/your_addon/.



As for the mode part, it’s really simply. When you issue a dispatch of activation.info, it looks for the activation controller and view. In the controller, the mode is the 2nd portion of the dispatch. In your case, info. For the view, it’s looking for view.tpl. If your dispatch was changed to openkite.fly_away then it look for the openkite addon folder. In the controller file it will be looking for mode == ‘fly_away’ to perform what is contained there and it will display these results on fly_away.tpl. You can add whatever mode you want as long as your controller and your view are setup to handle them.

[/quote]



Excellent, so far! :)



So, if I get it right, if I name my controller “search_menu” it should be like this:

controller: “addons/search_menu/controllers” and into controllers “search_menu.php”

view: “skins/basic/customer/addons/search_menu/views/search_menu” and into that “my_results.tpl”

??



Also, I still don’t undestand where should I create my select list items (html) since on both, controllers and views, I see php…

And when should I create a block?

Can you guide me throught the process? What’s the first thing I should do?



EDIT: Let’s say I’ve created the search_menu … What would be the flow?

Suggest you go look in the developer forum for a tutorial I wrote on how to implement using PHP hooks. You'll find the structure of what's needed there. It's about a 4 part tutorial and is fairly complete.



When you dispatch to a controller.mode (I.e. foo.bar) when it completes it's execution in the addons/foo/controllers/customer/foo.php file it will try to find skins//customer/addons/foo/views/foo/bar.tpl,.