Getting data from product_description to orders_products

Open to all! Ask other shopowners for help.
Xpajun
Contributor
Posts: 187
Joined: Thu Mar 04, 2021 1:18 pm
Phoenix Version: v1.0.9.0
Has thanked: 3 times
Been thanked: 6 times

Getting data from product_description to orders_products

Post 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)
Current Store is now running 1.0.9.0 - php 8.2.18
Now working on taking a short rest :D - php 8.2.18


Join The Code Co-op to get access to your library in the Code Co-op Forum
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: Getting data from product_description to orders_products

Post 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.
Xpajun
Contributor
Posts: 187
Joined: Thu Mar 04, 2021 1:18 pm
Phoenix Version: v1.0.9.0
Has thanked: 3 times
Been thanked: 6 times

Re: Getting data from product_description to orders_products

Post 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
Current Store is now running 1.0.9.0 - php 8.2.18
Now working on taking a short rest :D - php 8.2.18
Xpajun
Contributor
Posts: 187
Joined: Thu Mar 04, 2021 1:18 pm
Phoenix Version: v1.0.9.0
Has thanked: 3 times
Been thanked: 6 times

Re: Getting data from product_description to orders_products

Post 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
Current Store is now running 1.0.9.0 - php 8.2.18
Now working on taking a short rest :D - php 8.2.18
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: Getting data from product_description to orders_products

Post 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'];
    }
  }

}
Xpajun
Contributor
Posts: 187
Joined: Thu Mar 04, 2021 1:18 pm
Phoenix Version: v1.0.9.0
Has thanked: 3 times
Been thanked: 6 times

Re: Getting data from product_description to orders_products

Post 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
Current Store is now running 1.0.9.0 - php 8.2.18
Now working on taking a short rest :D - php 8.2.18
Xpajun
Contributor
Posts: 187
Joined: Thu Mar 04, 2021 1:18 pm
Phoenix Version: v1.0.9.0
Has thanked: 3 times
Been thanked: 6 times

Re: Getting data from product_description to orders_products

Post 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?
Current Store is now running 1.0.9.0 - php 8.2.18
Now working on taking a short rest :D - php 8.2.18
heatherbell
Senior Contributor
Posts: 2540
Joined: Mon Oct 07, 2019 4:39 am
Phoenix Version:
Has thanked: 35 times
Been thanked: 243 times

Re: Getting data from product_description to orders_products

Post 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
Xpajun
Contributor
Posts: 187
Joined: Thu Mar 04, 2021 1:18 pm
Phoenix Version: v1.0.9.0
Has thanked: 3 times
Been thanked: 6 times

Re: Getting data from product_description to orders_products

Post 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

Current Store is now running 1.0.9.0 - php 8.2.18
Now working on taking a short rest :D - php 8.2.18
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: Getting data from product_description to orders_products

Post by ecartz »

templates/xpajun/includes/hooks/shop/checkout_process/parts.php with the class named hook_shop_checkout_process_parts


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