Page 1 of 2

Getting data from product_description to orders_products

Posted: Sat May 20, 2023 9:46 am
by Xpajun
I'm trying to get the content of my products_description[products_parts] column (by product_id) through to orders_products[products_parts] on the customer ordering.

Keep trying a number of things withoout success, I know this line in products_info.php

Code: Select all

  $product_info_query = tep_db_query("SELECT p.*, pd.* FROM products p, products_description pd where p.products_status = 1 and p.products_id = " . (int)$_GET['products_id'] . " and pd.products_id = p.products_id and pd.language_id = " . (int)$languages_id);
 
selects the pd. products_parts, but how do I include products_parts to be included in the insert order - I have included thus in insert_order.php

Code: Select all

  $sql_data['orders_products'] = [];
  $sql_data['orders_products_attributes'] = [];
  $sql_data['orders_products_download'] = [];
  foreach ($order->products as $i => $product) {
    $sql_data['orders_products'][$i] = [
      'products_id' => tep_get_prid($product['id']),
      'products_model' => $product['model'],
      'products_name' => $product['name'],
      'products_parts' => $product['parts'],
      'products_price' => $product['price'],
      'final_price' => $product['final_price'],
      'products_tax' => $product['tax'],
      'products_quantity' => $product['qty'],
    ];

I'm working on the principal that I need to have a line of code in product_info (in templates?) I want to keep the contents hidden from customers and only use it with orders_batch

I'm currently trying this on OSCOM CE Phoenix v1.0.7.5 - php is 7.3.33 (Zend 3.3.33)

Re: Getting data from product_description to orders_products

Posted: Sat May 20, 2023 5:22 pm
by ecartz
It would be much easier for me to explain how to do this in 1.0.8.19 or later.

Basic idea:

1. The product query will load all the data.
2. In shopping cart, you have to load parts manually from the product result.
3. In order, you have to load parts manually from the shopping cart.
4. In insert_order, you have to load parts manually from the order (which looks like the code you posted).

So I think you are missing steps 2 and 3.

Alternately, you could do a separate database query just to get the parts data and put it into the array in insert_order. The bad part of that is that you have to do one query per line item.

In 1.0.7.5, you might have to make core changes to do this. In 1.0.8.19, you wouldn't.

Re: Getting data from product_description to orders_products

Posted: Sat May 20, 2023 7:53 pm
by Xpajun
ecartz wrote: Sat May 20, 2023 5:22 pm It would be much easier for me to explain how to do this in 1.0.8.19 or later.

Basic idea:

1. The product query will load all the data.
2. In shopping cart, you have to load parts manually from the product result.
3. In order, you have to load parts manually from the shopping cart.
4. In insert_order, you have to load parts manually from the order (which looks like the code you posted).

So I think you are missing steps 2 and 3.

Alternately, you could do a separate database query just to get the parts data and put it into the array in insert_order. The bad part of that is that you have to do one query per line item.

In 1.0.7.5, you might have to make core changes to do this. In 1.0.8.19, you wouldn't.
Thank you for the pointers - I will give it a try and report back - I'm not too worried about altering core as it'll be only me to use it at the moment

Re: Getting data from product_description to orders_products

Posted: Wed Feb 07, 2024 7:58 pm
by Xpajun
ecartz wrote: Sat May 20, 2023 5:22 pm It would be much easier for me to explain how to do this in 1.0.8.19 or later.

Basic idea:

1. The product query will load all the data.
2. In shopping cart, you have to load parts manually from the product result.
3. In order, you have to load parts manually from the shopping cart.
4. In insert_order, you have to load parts manually from the order (which looks like the code you posted).

So I think you are missing steps 2 and 3.

Alternately, you could do a separate database query just to get the parts data and put it into the array in insert_order. The bad part of that is that you have to do one query per line item.

In 1.0.7.5, you might have to make core changes to do this. In 1.0.8.19, you wouldn't.
Sorry to drag this up again after nearly 2 years but I'm looking at this again for 1.0.8.20 - I never did get it working for 1.0.7.5 do you have an explaination for doing this in 1.0.8.20 please Matt

Re: Getting data from product_description to orders_products

Posted: Thu Feb 08, 2024 4:52 am
by ecartz
In https://github.com/CE-PhoenixCart/Phoen ... er.php#L33 there is a hook. Also https://github.com/CE-PhoenixCart/Phoen ... 27-L140C38 So add something like

Code: Select all

class hook_shop_checkout_process_parts {

  public function listen_cartOrderProductColumns($parameters) {
    $parameters['column_keys']['parts'] = 'parts';
  }

  public function listen_insertOrder($parameters) {
    foreach ($GLOBALS['order']->products as $i => $product) {
      $parameters['sql_data']['orders_products'][$i]['products_parts'] = $product['parts'];
    }
  }

}

Re: Getting data from product_description to orders_products

Posted: Thu Feb 08, 2024 9:43 am
by Xpajun
ecartz wrote: Thu Feb 08, 2024 4:52 am In https://github.com/CE-PhoenixCart/Phoen ... er.php#L33 there is a hook. Also https://github.com/CE-PhoenixCart/Phoen ... 27-L140C38 So add something like

Code: Select all

class hook_shop_checkout_process_parts {

  public function listen_cartOrderProductColumns($parameters) {
    $parameters['column_keys']['parts'] = 'parts';
  }

  public function listen_insertOrder($parameters) {
    foreach ($GLOBALS['order']->products as $i => $product) {
      $parameters['sql_data']['orders_products'][$i]['products_parts'] = $product['parts'];
    }
  }

}
Thank you Matt I'll give that a try

Re: Getting data from product_description to orders_products

Posted: Mon Feb 19, 2024 5:55 pm
by Xpajun
ecartz wrote: Thu Feb 08, 2024 4:52 am In https://github.com/CE-PhoenixCart/Phoen ... er.php#L33 there is a hook. Also https://github.com/CE-PhoenixCart/Phoen ... 27-L140C38 So add something like

Code: Select all

class hook_shop_checkout_process_parts {

  public function listen_cartOrderProductColumns($parameters) {
    $parameters['column_keys']['parts'] = 'parts';
  }

  public function listen_insertOrder($parameters) {
    foreach ($GLOBALS['order']->products as $i => $product) {
      $parameters['sql_data']['orders_products'][$i]['products_parts'] = $product['parts'];
    }
  }

}
Hi Matt @ecartz I've been trying this and have been getting the following error:

Code: Select all

[19-Feb-2024 17:35:43 UTC] PHP Fatal error:  Uncaught Error: Class 'hook_shop_siteWide_shop_checkout_process_parts' not found in /home/***/public_html/***/includes/system/versioned/1.0.7.other/1.0.7.12/guarantor.php:17
Stack trace:
#0 /home/***/public_html/***/includes/system/versioned/1.0.8.1/hooks.php(111): Guarantor::ensure_global('hook_shop_siteW...')
#1 /home/***/public_html/***/includes/system/versioned/1.0.8.1/hooks.php(132): hooks->register('siteWide')
#2 /home/***/public_html/***/includes/system/versioned/1.0.8.1/hooks.php(127): hooks->register_pipeline('siteWide')
#3 /home/***/public_html/***/includes/system/versioned/1.0.8.1/hooks.php(160): hooks->register_page(Array)
#4 /home/***/public_html/***/includes/application_top.php(30): hooks->generate('startApplicatio...')
#5 /home/***/public_html/***/index.php(13): require('/home/***/...')
#6 {main}
  thrown in /home/***/public_html/***/includes/system/versioned/1.0.7.other/1.0.7.12/guarantor.php on line 17

Can you help please?

Re: Getting data from product_description to orders_products

Posted: Mon Feb 19, 2024 6:35 pm
by heatherbell
Xpajun wrote: Mon Feb 19, 2024 5:55 pm Can you help please?
one or other of the names is wrong - this name can't be right - hook_shop_siteWide_shop_checkout_process_parts
see - https://phoenixcart.org/phoenixcartwiki ... a_New_Hook

Re: Getting data from product_description to orders_products

Posted: Mon Feb 19, 2024 8:10 pm
by Xpajun
heatherbell wrote: Mon Feb 19, 2024 6:35 pm
Xpajun wrote: Mon Feb 19, 2024 5:55 pm Can you help please?
one or other of the names is wrong - this name can't be right - hook_shop_siteWide_shop_checkout_process_parts
see - https://phoenixcart.org/phoenixcartwiki ... a_New_Hook
I believe I put the hook in the wrong place - now moved it to templates>xpajun>includes>hooks>shop>progress butstill getting an error:

Code: Select all

[19-Feb-2024 18:31:24 UTC] PHP Fatal error:  Uncaught Error: Class 'hook_shop_progress_shop_checkout_process_parts' not found in /home/***/public_html/***/includes/system/versioned/1.0.7.other/1.0.7.12/guarantor.php:17
Stack trace:
#0 /home/***/public_html/***/includes/system/versioned/1.0.8.1/hooks.php(111): Guarantor::ensure_global('hook_shop_progr...')
#1 /home/***/public_html/***/includes/system/versioned/1.0.8.1/hooks.php(132): hooks->register('progress')
#2 /home/***/public_html/***/templates/xpajun/includes/pages/checkout_shipping.php(13): hooks->register_pipeline('progress')
#3 /home/***/public_html/***/checkout_shipping.php(43): require('/home/***/...')
#4 {main}
  thrown in /home/***/public_html/***/includes/system/versioned/1.0.7.other/1.0.7.12/guarantor.php on line 17


Re: Getting data from product_description to orders_products

Posted: Tue Feb 20, 2024 1:36 am
by ecartz
templates/xpajun/includes/hooks/shop/checkout_process/parts.php with the class named hook_shop_checkout_process_parts