V4 Addon Conversion Cheat Sheet

Here's the stuff I find I need to do for my V3/V2 addons to get them working in V4. It deals mostly with admin side but customer side should be very similar…



I'm certain it's not complete because as I forget things, I also forget to update the list!



In the PHP files:[list]

[]Search and replace instances of 'EN' or “EN” with 'en' or “en” (or any other lang_codes used)

[
]change language tag in addon.xml to en

[]Search for “fn_get_lang_var” and replace with “__”

[
]Move controllers/admin to controllers/backend (stupid change)

[]Move controllers/customer to controllers/frontend (stupid change)

[
]Port schemas/menu/menu.post.xml to the new schemas/menu/menu.post.php

[][color=#0000cd]Move schemas/settings/variants.post.php to schemas/settings/variants.functions.post.php[/color] (stupid change)

[
]Update the schemas/permissions/permissions.post.php to the newer format, create a language variable for the permission_id used for permissions

[]Change instances of "if(!defined('AREA'))' to 'if(!defined('BOOTSTRAP'))'

[
]Add “use Tygh\Registry;” to each file that uses the Registry class. Same for other system classes.

[]Search for “fn_http_request” and change to “Http::post” or “Http::get” as needed. Note that the headers are not returned and only the result is returned from the new Http class. . So now returns a string (or false) instead of an array()

[
]Find all instances of DIR_* and replace with appropriate Registry::get('config.dir.XX') references.

[]Search for and remove any class instantiations that return the class pointer by reference to returning by value references.

[/list]

In the admin templates:[list]

[
]Move css files from var/skins_repository to the design/backend/css/addons/[addon_name] folder

[]Adjust the design/backend/templates/addons/hooks/index/styles.post.tpl file to use the V4 method

[
]Again search and replace any upper case language codes in the template files

[]Search for any $lang.var_name references and change to __(“var_name”)

[
]Find any include files from “common_templates” and change to “common” (stupid change)

[]Find/change any “form-field” class definitions to “control-label” ensure container has class “control-group”

[
]Move any mail templates to their new locations (admin and customer side).

[/list]

If you do anything with payment gateways…[list]

[*]Change any instances of $processor_data['params'] to $processor_data['processor_params'] (stupid change)

[/list]

Also note that in V4, you can never really uninstall an admin addon since all the files are hard-wired into their final locations and there about 10 possible locations for addon files to reside. Major step backward for very little value.



Edit History:

2/13/14 - Added move of variants.post.php ([color=#0000cd]in blue[/color])

Thanks!

http://docs.cs-cart.com/adapting-addon-3to4

Hi,



I tried to adapt an addon from V3 to V4 and applied the necessary changes from above lists. But then, when I navigate to Design>Layouts all blocks went missing. Do you have any idea why such thing happened? Any help is very much appreciated.

No good answer. Would require an investigation. Have you checked your error_log? If you have an error in your controller related to the blocks schema, then it could cause nothing to be shown.

Hi Tony,



A couple of years ago, you had helped me customize an external PHP file I was using to modify customer accounts so that it would use the fn_send_mail function to send an email to the customer with their customer profile after the change was made. You had included this code at the top to include the internal cs-cart functions for my use:



define('AREA', 'A');

define('AREA_NAME', 'admin');

if( !file_exists('./prepare.php') )

chdir('…'); // In /scripts directory?

require_once(“./prepare.php”);

require_once(“./init.php”);



When I converted to v4, this no longer works. I had to remove the references to /prepare.php and just require init.php. So it looks like this now:



define('AREA', 'A');

define('AREA_NAME', 'admin');

require_once(“…/init.php”);



But still I am not able to call fn_send_mail successfully (other functions seem to work fine). This code gives me a Class 'Registry' not found error:



Registry::get('view_mail')->assign('password', $genpwd);

Registry::get('view_mail')->assign('send_password', TRUE);

Registry::get('view_mail')->assign('user_data', $user_data);

$result=fn_send_mail($custemail, 'Webmaster@XXXX.com', 'profiles/create_profile_subj.tpl', 'profiles/create_profile.tpl', '', $lang_code);



Does this have to do with what's included/not included at the top? Or is there some other change I need to make to include the registry class and call fn_send_mail?

fn_send_mail() function no longer exists. It was replaced by the Mail class as Mail::sendMail method.

It needs to be rewritten since you can no longer (supidly) set the subject template name (it assumes it is template_name_subj.tpl) and several other changes.

Your whole file needs to be reviewed and converted to V4. You have namespaces to deal with for Registry and Mail as well as probably several other changes.



Suggest you search the knowledge base about converting addons to V4.

UGH that's great. I tried to click the link above to a CS-Cart doc but got a 404. Ok, thank you.

[quote name='colleende' timestamp='1435957034' post='221571']

UGH that's great. I tried to click the link above to a CS-Cart doc but got a 404. Ok, thank you.

[/quote]



The correct URL is