Adapt Your Add-Ons To Cs-Cart 4.1.4

Hi there,



Thanks for the information.



I have a number of addons that will need to be updated. Do you know if anyone has written a script that will take care of this for us (well at least most of the heavy lifting)?



Is there a history of these pages in the forum that contain the list of changes? I am only noticing a single page in the docs at the moment that talks about bringing your addon over from v3, it doesn't mention these other changes in 4.x.x versions.



All the best,

Nathan

In 4.2 they started doing a thread about changes affecting addon developers.



Imac had stated that they were getting ready to publish one about going from 4.2 to 4.3 but I haven't seen it yet.

ok thanks. I am sure that this information about the changes between version 4.x.x was on the cscart docs a couple weeks ago (I stumbled across it a few times) but I can't see it easily anymore… Maybe it was taken down, I will keep an eye on the forums.

Can someone please explain this from the docs:

[list]

[*]

In order to support PHP 5, prepend all hook parameters with &:





fn_my_addon_place_order([color=#666666]&[/color][color=#BB60D5]$order_id[/color], [color=#666666]&[/color][color=#BB60D5]$order_status[/color], [color=#666666]&…[/color])

[/list]

Is this talking about where your hook function definitions are located? This is how I interpreted it and judging by the code that ships with v4 it looks like it. But if so, why is there no mention of it on this page:



PHP Hooks — CS-Cart 4.1.x documentation



Shouldn't it be mentioned about the pass by reference there?

In PHP, pass by reference from the calling function has been deprecated since PHP 4.

The called function should use “pass by reference” methods which is prepending each variable you want to use by reference with an ampersand. I.e.


my_function(&$param1, $param2, &$param3) {
// $param1 and $param3 are passed by reference (I.e. they will affect the values in the calling function)
// and $param2 is not and can be considered 'local' in scope.
$param1 = 'x';
$param2 = 'y';
$param3 = 'z';
// In the calling function, $param1 will be changed to 'x', $param2 will be unaffected and $param3 will be changed to 'z'
}


I actually believe that all versions of PHP 5 defaulted to call by value and needed to be explicitly declared in the called function to be by reference. But I'm not sure of the exact cut-over time frame.

ok thanks for the info…



The main reason I am asking is that I have written a BASH script that is attempting to do the majority of the heavy lifting to upgrade a heap of v3 addons I have written to v4 and the script is currently checking which hooks are registered in the init.php file for a v3 addon and then finding the function declaration in the PHP files for the addon and prepending each argument with an & (if it didn't have one already).



From what I can tell, this approach appears to be correct based upon the other addons that have been written for CS-CART - and I was just making sure that my efforts were not in vein.

There's a whole lot more that needs to be redone in a V2 or V3 addon for it to be compatible with V4.



Strongly suggest you simply contact the addon provider and ask them for a V4 version. The path to all the files have changed signficantly as well as the introduction of things like company_id and other things related to multiple storefronts.



So just addressing the hook calling method isn't going to really get you anywhere.

well that is one part of it, I have been following this page and the script so far takes care of all of these items (except for HTTP requests):



http://docs.cs-cart…ing_3_to_4.html



I realise there are other mods for internal changes to v4… sure beats manually editing each addon and reduces the likelihood of errors.



BTW - I am only talking taking a v3 addon to v4 with this script… I was lucky enough to not start working with CS-CART until v3! :) I am the developer of these addons.



So assuming the docs are up to date, then I see no reason why the script shouldn’t work…