Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Trying to create a new addon/block Rate Topic   - - - - -

 
  • openkite
  • Newbie
  • Members
  • Join Date: 17-Jan 12
  • 13 posts

Posted 13 August 2012 - 06:56 PM #21

Could you be kind enough to give a link because I don't seem to be able to find it...?

Also I was ready this excellent post of yours
http://forum.cs-cart...-controllers-1/
but I can't find the next one (about the templates)...

 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 12049 posts

Posted 13 August 2012 - 07:02 PM #22

That's the first post of the series I was talking about. Just do a search by author and restrict it to the developer's corner forum and you should bet a nice listing....

EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • openkite
  • Newbie
  • Members
  • Join Date: 17-Jan 12
  • 13 posts

Posted 14 August 2012 - 10:44 AM #23

Got it!! Thanx a lot, great job!! :)

 
  • ninthvector
  • Junior Member
  • Members
  • Join Date: 13-Jun 07
  • 17 posts

Posted 16 August 2012 - 07:47 PM #24

Hello!

First I'll say thank you to the likes of CSCart dev'ers like 'tbirnseth' and others who are active on this forming helping people new to CSCart figure out how the system works. I find the documentation on the main site quite lacking.

Secondly, please pardon my ignorance!

In trying to gain an understanding of how the model>view>controller concept works within CSC specifically regarding Addons I have done the following:

Followed example given here:
http://docs.cs-cart....add-on-tutorial

I have a functioning 'Block' in place on the homepage setup in the file structure as:
~/skins/basic/customer/addons/my_addon/blocks/static_templates/my_addon.tpl

By functioning I mean that I placed the block in the homepage section of the design GUI in the Admin Panel. And, when I go to my homepage, whatever html/text I have in my_addon.tpl get's displayed on the page.

my_addon.tpl:
{** block-description:my_addon **}
<p>some content</p>

So, onto more useful concepts. In trying to understand how the flow works I setup a my_addon.php controller file in:
~/addons/my_addon/controllers/customer/my_addon.php

I also have a func.php in:
~/addons/my_addon/func.php
Because I was going to try to create a function that returns an arbitrary value to the my_addon.php controller. But I couldn't even get that far.

So, my first question (problem), is that I can't get my controller to communicate with my template (.tpl). I have:

my_addon.php
<?php
if( !defined('AREA') ) die('Access denied');
$some_value = 'Hello';
$view->assign('passed_value', $some_value);
?>

And I updated my my_addon.tpl:
{** block-description:my_addon **}
<p>my value: {$passed_value}</p>

This does not work...

I've been reading a bunch on this forum but I just can't understand enough to get this example working. Can someone please help with what has got to be super simple? Also, if you could go one step further to explain (give example code) for how to create a simple function in func.php and how to call that function from my controller and manipulate the returned value in the controller php.

I thank you in advance!

 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 12049 posts

Posted 16 August 2012 - 10:44 PM #25

The 'mode' specifies the 'view' that will be used. So if your controller was called like:
?dispatch=my_addon.view

and your my_addon.php did something like:
if( $mode == 'view' && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
Registry::get('view')->assign('passed_value', "this is my value");
}
return array(CONTROLLER_STATUS_OK);

What will happen when this returns is that will look for a template named 'view.tpl' in
skins/<your_skin>/customer/addons/my_addon/views/my_addon/view.tpl

If you don't want this to go to its own view, you would do an
return array(CONTROLLER_STATUS_REDIRECT, <some_redirect_url>);
instead of the OK

If your block is available wherever you redirect to, then the {$passed_value} will be available to your block.

EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • tuannmvn
  • Newbie
  • Trial users
  • Join Date: 04-May 13
  • 1 posts

Posted 13 May 2013 - 01:53 AM #26

Hello every one,

I am trying to create new block, named is “account”, I have saved data in admin area succesful and i want to show data in storefront (home page), source structure in below:

1/Addon:

MODEL: addons\account\func.php
<?php

function fn_account_get(){
$account = db_get_array("SELECT * FROM ?:account");
return $account;
}
?>


CONTROLLER: Addons\account\controllers\customer\account.php
<?php
if ( !defined('AREA') ) { die('Access denied'); }
if($mode=='account' && $_SERVER['REQUEST_METHOD'] != 'POST'){

$account=fn_account_get();
$view->assign('account', $account);

return array(CONTROLLER_STATUS_OK);
}
?>

SCHEMAS: addons\account\schemas\block_manager\blocks.post.php
<?php
if ( !defined('AREA') ) { die('Access denied'); }

$schema['account'] = array (
'content' => array (
'items' => array (
'remove_indent' => 'true',
'hide_label' => 'true',
'type' => 'function',
'object' => 'account',
'items_function' => 'fn_account_get',
),
),
'templates' => array(
'addons/account/blocks/account.tpl' => array(),
),

'wrappers' => 'blocks/wrappers',
);
?>
VIEW: var\skins_repository\basic\customer\addons\account\views\account\account.php
{foreach from=$account item="acc"}

{$acc.name}

{/foreach}

My Problem:

The block after installed, it’s show OK with URL: http://localhost/wor...account.account

BUT I want it show on homepage: http://localhost/wor...scart/index.php

How can i config ? Please suggest for me. Thank you very much

 
  • vickythegme
  • Member
  • Trial users
  • Join Date: 27-Feb 15
  • 18 posts

Posted 06 March 2015 - 09:17 AM #27

Hi,

I came across this issue and I tried to solve it as @tbirseth mentioned, but when I tried the url (index.php?dispatch=custom_code.my_info) it shows 404 page error.

Any Ideas on this one?

I added a custom_code addon in my cscart 4.x installation and added the design code in design folder view.tpl and tried the dispatch url.

Its not working.

Addon Folder - app/addon/custom_code/controllers/customer/custom_code.php

Design Folder - design/themes/theme_name/templates/addon/custom_code/views/custom_code/view.tpl

What am I doing wrong?

<ul class="basic_info" style="margin: 0px; padding: 0px; list-style: none; color: rgb(28, 40, 55); font-family: arial, verdana, tahoma, sans-serif; font-size: 12px; line-height: 14.3999996185303px; text-align: center;">
<li style="margin: 10px 0px 0px; padding: 0px;"> </li>
</ul>

 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 12049 posts

Posted 06 March 2015 - 08:36 PM #28

The name of the template is derived from the "mode" of the dispatch. I.e. if you are using:
dispatch=custom_code.my_info
then the template that will be called is:
design/themes/theme_name/templates/addons/custom_code/views/custom_code/my_info.tpl

If you do not want it to get to the template file then you can just redirect from your custom_code controller when the mode my_info is detected.

Note that if you are POSTing data to custom_code.my_info you MUST redirect for things to work properly. Cs-cart does not behave properly when navigating from a POST request.

EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • vickythegme
  • Member
  • Trial users
  • Join Date: 27-Feb 15
  • 18 posts

Posted 10 March 2015 - 06:51 AM #29

Hi, Thanks for the reply @tbirseth.

So, I just managed to make my controller work just fine. Managed to insert the product data in my custom table.

The issue that I m facing is after my controller mode my_info does its job, I would like to show a notification for which I've a page notification.tpl in my design folder (design/themes/theme_name/templates/addon/custom_code/views/custom_code/components/notification.tpl)
Any suggestion on how to do this.?

I've tried adding the notification code in a similar way below.
if (defined('AJAX_REQUEST')) {
$title = "Product Added";
$msg = Registry::get('view')->fetch('addons/custom_code/views/custom_code/components/notification.tpl');
fn_set_notification('I', $title, $msg, 'I');
}

It doesn't seem to work fine. But sometimes when I refresh the page I'm getting the notification shown in my index page . Works wierd. I want the notification to be shown only when my controller mode my_info is called.

Any suggestions to make it work ?