Jump to content

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

Help Using Hook Rate Topic   - - - - -

 
  • Pascal
  • Senior Member
  • Members
  • Join Date: 13-Jun 12
  • 208 posts

Posted 08 August 2019 - 03:43 PM #1

Hi,

 

I have some modification in fn.cart (app/functions) and, of course, it breaks each time I update CS-Cart. I know I have to use Hooks instead of modifiying the core, but I am too weak in code and after reading informations about hooks, I still cannot do it :(

 

Is there anyone that can help me and explain how to make my changes in fn.cart using hooks instead of changing the core ?

 

I need to replace the following code :

$paid_statuses = array('P', 'C');
 
by this one :
$paid_statuses = array('P', 'C', 'O', 'E', 'G', 'H');

 

Thank you in advance for your help :)



 
  • soft-solid
  • Junior Member
  • Members
  • Join Date: 19-Apr 10
  • 919 posts

Posted 08 August 2019 - 03:52 PM #2

Hello

 

You can use hook "get_orders_totals"

 

The function that supports hook should look like this:

 

function fn_YOUR_ADDON_NAME_get_orders_totals(&$paid_statuses, $join, $condition, $group)

{

      $paid_statuses = array('P', 'C', 'O', 'E', 'G', 'H');

}

 

Remember to give the appropriate entry in the init.php file

 

Best regards

Robert


Team of SoftSolid
cs-cart.pl

 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 19846 posts

Posted 09 August 2019 - 05:38 AM #3

The func.php file should be located here

 

app/addons/YOUR_ADDON_NAME/func.php

 

The content of the app/addons/YOUR_ADDON_NAME/init.php file should be

<?php

if (!defined('BOOTSTRAP')) { die('Access denied'); }


fn_register_hooks(
    'get_orders_totals'
);

Do not forget about addon.xml file. Check example in the my_changes addon


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • Pascal
  • Senior Member
  • Members
  • Join Date: 13-Jun 12
  • 208 posts

Posted 09 August 2019 - 07:17 AM #4

Thanks.

So if I understand, I have to create a repertory in addon with my add-on name.

Inside of it, I put the addon.xml file, init.php file that include the information of the hook and the func.php file that include the changes.

 

Do I have then to install the add-on in backend or the hook is automatically started ?



 
  • Pascal
  • Senior Member
  • Members
  • Join Date: 13-Jun 12
  • 208 posts

Posted 09 August 2019 - 09:07 AM #5

And last question, I have some mods in /design/backend/templates/addons/discussion/views/discussion_manager/components/allow_discussion.tpl

 

In that case, it seems there is no hook in that file. Can I make the change using hook or is it impossible ?



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 19846 posts

Posted 09 August 2019 - 01:32 PM #6

Do I have then to install the add-on in backend or the hook is automatically started ?

 

Addon should be installed and has Active status

 

 

And last question, I have some mods in /design/backend/templates/addons/discussion/views/discussion_manager/components/allow_discussion.tpl

 

In that case, it seems there is no hook in that file. Can I make the change using hook or is it impossible ?

 

This template does not have hooks. So you should override it


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • Pascal
  • Senior Member
  • Members
  • Join Date: 13-Jun 12
  • 208 posts

Posted 15 August 2019 - 06:47 AM #7

Does not work :(

I have :

 

- Created directory **ADD-ON NAME** in /app/addons

- Created addon.xml

 

<?xml version="1.0"?>
<addon scheme="3.0">
    <id>ADD-ON NAME</id>
    <version>1.0</version>
    <priority>100500</priority>
    <position>0</position>
    <auto_install>MULTIVENDOR,ULTIMATE</auto_install>
    <default_language>fr</default_language>
</addon>
 
- created init.php
 
<?php
 
if (!defined('BOOTSTRAP')) { die('Access denied'); }
 
 
fn_register_hooks(
    'get_orders_totals'
);
 
- created func.php
 
<?php
 
function fn_ADD-ON NAME_get_orders_totals(&$paid_statuses, $join, $condition, $group)
 
{
 
      $paid_statuses = array('P', 'C', 'O', 'E', 'G', 'H');
 
}
 
After installation, it went to service unavailable for a while. When site comes back, add-on is installed and activated, but it does not show any changes.
Did I made everything right ?


 
  • soft-solid
  • Junior Member
  • Members
  • Join Date: 19-Apr 10
  • 919 posts

Posted 15 August 2019 - 11:32 AM #8

Hello

 

Write what the real addon_id is

 

What are you written between <id></id>

 

<id>ADD-ON NAME</id>

 

Best regards

Robert


Team of SoftSolid
cs-cart.pl

 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 19846 posts

Posted 15 August 2019 - 01:30 PM #9

When you see Service unavailable error, check page source code (Ctrl + U) to see error text


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • Pascal
  • Senior Member
  • Members
  • Join Date: 13-Jun 12
  • 208 posts

Posted 15 August 2019 - 01:31 PM #10

Hello

 

Write what the real addon_id is

 

What are you written between <id></id>

 

<id>ADD-ON NAME</id>

 

Best regards

Robert

Thanks for answer Robert !

I have put ADD-ON NAME in the post for the forum. In my files, it's already replaced by the add-on name I used (fncartmod).



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 19846 posts

Posted 15 August 2019 - 01:34 PM #11

Put the following code to the function to see if it is called

fn_print_r('test');

GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.