Hook creation to input data

Open to all! Ask other shopowners for help.
Post Reply
BatteryTrader
Contributor
Posts: 153
Joined: Thu Apr 11, 2024 7:18 am
Phoenix Version: 1.1.0.3
Has thanked: 3 times
Been thanked: 17 times

Hook creation to input data

Post by BatteryTrader »

I have managed to make changes to core file

Includes\system\versioned\1.0.7.10\cart_order_builder.php to do what i want

Ie include both products_seo_title and products_number_of columns from the database into an order, great

But trying to have a unchanged core, and trying to set up a hook, but spent hours on it now and cannot get the data in.

Currently have Includes\system\versioned\1.0.7.10\cart_order_builder.php like

Code: Select all

    public function __construct(&$order) {
      if (is_null(static::$column_keys)) {
        static::$column_keys = [
          'qty' => 'quantity',
          'name' => 'name',
 //         'seo_title' => 'seo_title',
 //         'number_of' => 'number_of',
          'model' => 'model',
          'price' => 'price',
          'final_price' => 'final_price',
          'weight' => 'weight',
          'id' => 'id',
        $GLOBALS['hooks']->cat('cartbuilder')
        ];
        $parameters = [
          'column_keys' => &static::$column_keys,  
        ];
        $GLOBALS['all_hooks']->cat('cartOrderProductColumns', $parameters);
      }
With a hook in includes\hooks\shop\system\versioned\cartbuilder.php

Code: Select all

<?php
/*
  $Id$

  CE Phoenix, E-Commerce made Easy
  https://phoenixcart.org

  Copyright (c) 2025 Phoenix Cart

  Released under the GNU General Public License
*/

class hook_shop_system_versioned_cartbuilder {

  function listen_cartbuilder() {
    $cartbuilder = 'seo_title' => 'seo_title',
          'number_of' => 'number_of',

    return $cartbuilder ;
  }

}
Feel I am doing something silly wrong, but tried loads of different ways, this will be the first hook I have ever made so not sure what it is I am doing wrong, trying to compare but getting nowhere.

Any pointers would be handy

Kind regards

David

Tags:


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
Kofod95
Senior Contributor
Posts: 748
Joined: Sat Feb 06, 2021 7:38 pm
Phoenix Version: 1.0.8.20
Has thanked: 99 times
Been thanked: 179 times

Re: Hook creation to input data

Post by Kofod95 »

I think the syntax is a little different.
Maybe try:

Code: Select all

    $column_keys[] = 'seo_title' => 'seo_title';
    $columns_keys[] = 'number_of' => 'number_of';
or

Code: Select all

  array_push($column_keys, 'seo_title' => 'seo_title', 'number_of' => 'number_of');
Otherwise, you can maybe use what I use for my add-on to add delivery address contact info I use the following to add to the database:

Code: Select all

  class hook_shop_siteWide_deliveryContactInfo {
	function listen_insertOrder($parameters){
	  $order =& $GLOBALS['order'];
	  $parameters['sql_data']['orders']['delivery_contact_info'] = $GLOBALS['customer_data']->get('contact_info', $order->delivery);
	}
  }
In this context it might look something like:

Code: Select all

function listen_cartOrderProductColumns($parameters){
  $parameters['column_keys']['seo_title'] =  'seo_title';
  $parameters['column_keys']['number_of'] = 'number_of';
  }
//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
BatteryTrader
Contributor
Posts: 153
Joined: Thu Apr 11, 2024 7:18 am
Phoenix Version: 1.1.0.3
Has thanked: 3 times
Been thanked: 17 times

Re: Hook creation to input data

Post by BatteryTrader »

Thanks for the reply Kofod95

In your case what do you add on the page you want to insert the info

$GLOBALS['hooks']->cat('insertOrder')

?

Thank you
User avatar
Kofod95
Senior Contributor
Posts: 748
Joined: Sat Feb 06, 2021 7:38 pm
Phoenix Version: 1.0.8.20
Has thanked: 99 times
Been thanked: 179 times

Re: Hook creation to input data

Post by Kofod95 »

BatteryTrader wrote: Mon May 12, 2025 7:38 am In your case what do you add on the page you want to insert the info
Not quite sure I understand your question?
I haven't edited core, if that's what you mean?

Edited my first post, to hopefully be a bit more helpful.

//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
BatteryTrader
Contributor
Posts: 153
Joined: Thu Apr 11, 2024 7:18 am
Phoenix Version: 1.1.0.3
Has thanked: 3 times
Been thanked: 17 times

Re: Hook creation to input data

Post by BatteryTrader »

Hi Daniel

Thanks, think I understand a lot more now, just couldn't get my head around it.

It failed, but I think its because the Parameters should be Null at the start, have to go out now but its given me a greater understanding. I obviously had the wrong end of the stick.

Regards

David
BatteryTrader
Contributor
Posts: 153
Joined: Thu Apr 11, 2024 7:18 am
Phoenix Version: 1.1.0.3
Has thanked: 3 times
Been thanked: 17 times

Re: Hook creation to input data

Post by BatteryTrader »

Just an update
class hook_shop_system_cartbuilder {


function listen_cartOrderProductColumns($parameters){
$parameters['column_keys']['seo_title'] = 'seo_title';
$parameters['column_keys']['number_of'] = 'number_of';
}

}
Worked great, more importantly, has given me an insight into how the hooks work.

Thanks Daniel


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply