Adapt Your Add-Ons To CS-Cart 4.2.1

[color=#282828][font=arial, verdana, tahoma, sans-serif]Hello everybody![/font][/color]



Familiarize yourself with the list of changes that can affect your add-ons operation when updating from 4.1.5 to 4.2.1 version.



They are not so numerous, but some of them affected CS-Cart functionality rather heavily.

Here is the list of main changes:



===========================================================



New Responsive theme. You should check your add-ons design with the new theme and adapt it if needed.



[color=#282828][font=arial, verdana, tahoma, sans-serif]-----------------------------------------------------------------------------------------------[/font][/color]



SEO

Because of the fact that the SEO add-on was highly modified (see the list of changes in our blog), PHP functions were changed too. If your add-on works with the SEO functionality, check it.



As for hooks, here is the list of added, removed, and modified hooks:

Removed:

  • seo_static_cache
  • seo_empty_object_name



    Changed:
  • get_seo_vars
  • get_rewrite_rules
  • seo_is_indexed_page
  • seo_url



    For more information open:

    http://www.cs-cart.c…=4.2.1RC#238973



    Choose “Compare with”: “CS-Cart Lifetime License” “4.1.5” and click Seach.



    [color=#282828][font=arial, verdana, tahoma, sans-serif]-----------------------------------------------------------------------------------------------[/font][/color]



    Languages



    PO files format was changed.



    Old:

```php

Editing product

msgctxt “Languages”

msgid “editing_product”

msgstr "Editing product”

```



New:

msgctxt "Languages:tools_addons_restore_defaults"
msgid "Restore defaults"
msgstr "Restore defaults”




So, accordingly, all PO file-related functionality has changed as well.



[color=#282828][font=arial, verdana, tahoma, sans-serif]-----------------------------------------------------------------------------------------------[/font][/color]



Settings



The following settings:

Enable secure connection at checkout

Enable secure connection in the administration panel

Enable secure connection for authentication, profile and orders pages

Keep HTTPS connection once a secure page is visited



were moved from the General section to Security.



settings.General.secure_checkout -> settings.Security.secure_checkout
settings.General.keep_http -> settings.Security.keep_https
settings.General.secure_admin -> settings.Security.secure_admin
settings.General.secure_auth -> settings.Security.secure_auth




[color=#b22222]- Registry::get('settings.General.secure_checkout');[/color]

[color=#006400]+ Registry::get('settings.Security.secure_checkout');[/color]



Example:

$secure_admin_value = Registry::get('settings.Security.secure_admin');



Also the following settings changed their names:


save_selected_layout -> save_selected_view
default_products_layout -> default_products_view
default_products_layout_templates -> default_products_view_templates
default_product_details_layout -> default_product_details_view




[color=#b22222]- Registry::get('settings.Appearance.save_selected_layout');[/color]

[color=#006400]+ Registry::get('settings.Appearance.save_selected_view');[/color]



[color=#282828][font=arial, verdana, tahoma, sans-serif]-----------------------------------------------------------------------------------------------[/font][/color]



We have completely switched to HTML5. There is no more need in the following structure in JavaScript code:


// ...
//]]>




[color=#282828][font=arial, verdana, tahoma, sans-serif]-----------------------------------------------------------------------------------------------[/font][/color]



All the config variables with the resources paths were moved to $config['resources’]



$config['resources'] = array(
'knowledge_base' => '[url="http://kb.cs-cart.com/installation"]http://kb.cs-cart.com/installation'[/url],
'updates_server' => '[url="http://updates.cs-cart.com%27/"]http://updates.cs-cart.com'[/url],
'twitter' => 'cscart',
'feedback_api' => '[url="https://www.cs-cart.com/index.php?dispatch=feedback%27"]https://www.cs-cart.com/index.php?dispatch=feedback'[/url],
'product_url' => '[url="https://www.cs-cart.com%27/"]https://www.cs-cart.com'[/url],
'helpdesk_url' => '[url="https://www.cs-cart.com/helpdesk"]https://www.cs-cart.com/helpdesk'[/url],
'license_url' => '[url="https://www.cs-cart.com/licenses.html"]https://www.cs-cart.com/licenses.html'[/url],
'marketplace_url' => '[url="http://marketplace.cs-cart.com%27/"]http://marketplace.cs-cart.com'[/url],
'admin_protection_url' => '[url="http://kb.cs-cart.com/adminarea-protection"]http://kb.cs-cart.com/adminarea-protection'[/url],
//'demo_store_url' => '[url="http://demo.cs-cart.com/"]http://demo.cs-cart.com/'[/url] . strtolower(PRODUCT_EDITION) . '/'
);

$config['updates_server'] = '[url="http://updates.cs-cart.com%27/"]http://updates.cs-cart.com'[/url]; was left for now for the backward compatibility, but will be removed soon.




[color=#b22222]bad: Registry::get('config.updates_server’)[/color]

[color=#006400]good: Registry::get('config.resources.updates_server')[/color]



[color=#282828][font=arial, verdana, tahoma, sans-serif]-----------------------------------------------------------------------------------------------[/font][/color]



Exim:

The ability to import Order items for a non-existing order was removed.



[color=#282828][font=arial, verdana, tahoma, sans-serif]-----------------------------------------------------------------------------------------------[/font][/color]



Exim:

The ability to import language variables for a non-existing language was removed.



[color=#282828][font=arial, verdana, tahoma, sans-serif]-----------------------------------------------------------------------------------------------[/font][/color]



Layouts: Blocks:



The disable_cache flag for fillings was returned.

Now it is possible to disable cache for certain fillings values (when creating the Random products block, for example).



'products' => array (
'content' => array (
'items' => array (
...
'fillings' => array (
'random_products' => array (
'params' => array (
'sort_by' => 'popularity',
'sort_order' => 'desc',
),
'disable_cache' => true,
),
),

...
),
),
),




[color=#282828][font=arial, verdana, tahoma, sans-serif]-----------------------------------------------------------------------------------------------[/font][/color]



Smarty was updated to the latest version (3.1.15 → 3.1.18).



[color=#282828][font=arial, verdana, tahoma, sans-serif]-----------------------------------------------------------------------------------------------[/font][/color]



The new helpful function was added:


```php

/**

  • Gets company storefront URLs
  • @param integer $company_id company ID
  • @param array $company_data company data (if passed, company_id won't be used)
  • @return array storefront URLs

    */

    function fn_get_storefront_urls($company_id, $company_data = array())

    ```



    [color=#282828][font=arial, verdana, tahoma, sans-serif]-----------------------------------------------------------------------------------------------[/font][/color]



    The is_permanent flag was added to the fn_redirect function. Now it is possible to create 301 redirects.



    [color=#b22222]- function fn_redirect($location, $allow_external_redirect = false)[/color]

    [color=#006400]+ function fn_redirect($location, $allow_external_redirect = false, $is_permanent = false)[/color]



    [color=#282828][font=arial, verdana, tahoma, sans-serif]-----------------------------------------------------------------------------------------------[/font][/color]



    The PRODUCT_NAME constant was added.



    [color=#282828][font=arial, verdana, tahoma, sans-serif]-----------------------------------------------------------------------------------------------[/font][/color]



    Suppliers:

    The ability to create a common shipping method for all suppliers was added.

    The corresponding code was changed.



    [color=#282828][font=arial, verdana, tahoma, sans-serif]-----------------------------------------------------------------------------------------------[/font][/color]



    If it is necessary to extend one add-on with another, now it is possible to select all hook functionality inside the add-on. For example, news_and_emails uses seo. Not to spread the seo functionality across all the news_and_emails functionality, it can be passed to a hook.



    design/backend/templates/addons/news_and_emails/addons/seo/hooks/



    The principles of working are the same as for the other hooks. One exception is that hooks from the addons catalog inside the news_and_emails add-on will be included only when the appropriate add-on is enabled (the SEO add-on in this example).



    The 3rd parameter was added for registering the php hooks:



fn_register_hooks( array('get_news_data', '', 'seo') )




The name of a function processing a hook is fn_seo_get_news_data. It is called out when the SEO add-on is enabled.




[quote]Note: All the described actions take place in the News and emails add-on.[/quote]



[color=#282828][font=arial, verdana, tahoma, sans-serif]-----------------------------------------------------------------------------------------------[/font][/color]



Banners:

Now demo banners are always installed.



[color=#282828][font=arial, verdana, tahoma, sans-serif]-----------------------------------------------------------------------------------------------[/font][/color]



The web configuration file for ISS servers was added (like htaccess).

Check var/conf/ folder.



[color=#282828][font=arial, verdana, tahoma, sans-serif]-----------------------------------------------------------------------------------------------[/font][/color]



The instance method of the Settings class now allows to get settings of the defined company:





[color=#006400]- public static function instance()[/color]

[color=#b22222]+ public static function instance($company_id = null)[/color]



[color=#282828][font=arial, verdana, tahoma, sans-serif]-----------------------------------------------------------------------------------------------[/font][/color]



htaccess now allows to download the .yml and .xml files from the var/ directory.



HOOKS

===============================================



[color=#b22222]- fn_set_hook('update_shipping_post', $shipping_data, $shipping_id, $lang_code);[/color][color=#006400]+ +fn_set_hook('update_shipping_post', $shipping_data, $shipping_id, $lang_code, $action);[/color]





3 Jul UPDATE (forgot to mention)

===============================================

We added new version of an addon.xml file:





So all the add-ons which have XML v3, support PO-files with translations.





Feel free to ask me any questions. I will try to help you!



[color=#006400]Thank you![/color]

[quote name='alexions' timestamp='1404292655' post='186785']

[color=#282828][font=arial, verdana, tahoma, sans-serif]The 3rd parameter was added for registering the php hooks:[/font][/color]



[color=#000000]fn_register_hooks[/color][color=#666600]([/color][color=#000000] array[/color][color=#666600]([/color][color=#008800]'get_news_data'[/color][color=#666600],[/color][color=#000000] [/color][color=#008800]''[/color][color=#666600],[/color][color=#000000] [/color][color=#008800]'seo'[/color][color=#666600])[/color][color=#000000] [/color][color=#666600])[/color]



[color=#282828][font=arial, verdana, tahoma, sans-serif]The name of a function processing a hook is [/font][/color]fn_seo_get_news_data[color=#282828][font=arial, verdana, tahoma, sans-serif]. It is called out when the SEO add-on is enabled.[/font][/color]

[/quote]



Thank you for the detailed instructions. What is the purpose of the second parameter here?

[quote name='eComLabs' timestamp='1404296431' post='186787'] Thank you for the detailed instructions. What is the purpose of the second parameter here? [/quote]



if (isset($hook[2])) {
$addon = $hook[2];
if (Registry::get('addons.' . $addon . '.status') != 'A') { // skip hook registration if addon is not enabled
continue;
}




It means, that hook will be registered only if specified addon is Active.



Best wishes!

[quote name='alexions' timestamp='1404297512' post='186789']

It means, that hook will be registered only if specified addon is Active.

[/quote]



Thank you for the answer. But I meant second parameter, not third one. The third is clear

[quote name='eComLabs' timestamp='1404297959' post='186791'] Thank you for the answer. But I meant second parameter, not third one. The third is clear [/quote]



Oh, sorry. This is the “priority” parameter.

In other words - the order in which the add-ons hooks will be launched.



Each add-on has the “priority” parameter in the addon.xml file. The high priority add-ons hooks will be executed earlier than the low-priority.



For example, you have 2 add-ons A and B.

A has priority 10, B - 20. So all hook functions from the add-on A will be executed before the “B” hook functions. But sometime you need to execute B-hooks before the A-hooks. And you should use register hooks function with the priority parameter.



add-on A

fn_register_hooks(array('some_hook', '20'));



add-on B

fn_register_hooks(array('some_hook', '10'));



Hope, my explanation is clear enough. If not, let me know.

Thank you!

[quote name='alexions' timestamp='1404300041' post='186793']

Hope, my explanation is clear enough. If not, let me know.

[/quote]



Got it. Thanks. You are awesome!

Alexions,



Thank you for the explanations and useful information.

Thank you for sharing this information, very useful.