Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2018
    Posts
    3
    Plugin Contributions
    0

    Default Admin order edit, how to extrat prducts as array?

    PHP version 7.1
    Zencart Version v1.5.7c

    Im trying to implement a invoice api from a third partner, all my test code is working good but i dont know how to extrat the ordered products.

    I need to have an array with all the data


    Code:
    $data = array(
      'Client[ID]' => $clientDenumire,  (static content provided by api developer)
      'Client[HASH]' => '7250110',    (static content provided by api developer)
    
      'Content[0][Name]' => 'Product 1 name',
      'Content[0][Price]' => '10', 
      'Content[0][qty]' => '5');
    
      'Content[1][Name]' => 'Product 2 name',
      'Content[1][Price]' => '12', 
      'Content[1][qty]' => '3');
    
      'Content[2][Name]' => 'Delivery',
      'Content[2][Price]' => '5', 
      'Content[2][qty]' => '1');
    
    );
    I need to extract the ordered products in same array, also the delivery method that user selected

    My try :


    PHP Code:
     for ($i=0$n=sizeof($order->products); $i<$n$i++) {
         
      
    $products= [
      
    'Content['.$i.'][name]' => $order->products[$i]['name'],
      
    'Content['.$i.'][qty]' => $order->products[$i]['qty'],
      
    'Content['.$i.'][price]' => $order->products[$i]['price'],
    ];

     } 
    But i dont know how to get close the loop and to extract informations in same array, also to combine it with my static informations

    Code:
      'Client[ID]' => $clientDenumire,  (static content provided by api developer)
      'Client[HASH]' => '7250110',    (static content provided by api developer)
    I also dont know how to extract my delivery method in same array and for each position to count Content[0], Content[1], Content[2] etc.
    Last edited by doghi22; 28 May 2021 at 01:11 PM.

  2. #2
    Join Date
    Jul 2012
    Posts
    16,732
    Plugin Contributions
    17

    Default Re: Admin order edit, how to extrat prducts as array

    so you can after your for loop do:
    Code:
    $product['Client[ID]'] = $clientDenumire;
    $product['Client[HASH]'] = '7250110';
    or can create an array that contains those two items and merge it, or can merge it directly such as:
    Code:
    $product = array_merge($product, array('Client[ID]' => $clientDenumire, 'Client[HASH]' => '7250110',));
    Delivery method is stored in $orders->info where $orders->info['shipping_method'] and $orders->info['shipping_module_code'] provide the method and module respectively. Some of that information and/or other data may need to be pulled together or further processed to obtain your desired result(s). That information is also available at the "same time" that you are going through your loop. So if you need to put the shipping method with each "product" 'Content[0][shipping_method]' then you could do something like:
    Code:
    for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
    
        $products= [
          'Content['.$i.'][name]' => $order->products[$i]['name'],
          'Content['.$i.'][qty]' => $order->products[$i]['qty'],
          'Content['.$i.'][price]' => $order->products[$i]['price'],
          'Content['.$i.'][shipping_method]' => $order->info['shipping_method'],
        ];
    
    }
    Unless you have something that offers multiple shipping methods per order and the ability to tie the product with the shipping method which would require more processing and "adding" the information to the array similar to described earlier in this response. Note, that in this for loop it may be necessary to cast $i as an integer as I have sometimes seen where something like: 'Content['.$i.'][name]' may product 'Content[][name]' instead of having a 0... So it may be necessary for those lines to have:
    'Content['.(int)$i.'][....]';

    I don't otherwise understand the last part of the last sentence, though it may be addressed by the above suggestion(s). E.g. '...and for each position to count Content[0], Content[1], Content[2] etc.'
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  3. #3
    Join Date
    Aug 2018
    Posts
    3
    Plugin Contributions
    0

    Default Re: Admin order edit, how to extrat prducts as array

    Hello there,

    Thx for your answer.

    I know i can merge arrays and its the best way to work in this project.


    array1 = (
    $product['Client[ID]'] = $clientDenumire;
    $product['Client[HASH]'] = '7250110';)


    The problem is that i dont know how to extract ordered products in this form :


    array2 = (

    'Content[0][Name]' => 'Product 1 name',
    'Content[0][Price]' => '10',
    'Content[0][qty]' => '5');

    'Content[1][Name]' => 'Product 2 name',
    'Content[1][Price]' => '12',
    'Content[1][qty]' => '3');

    'Content[2][Name]' => 'Delivery',
    'Content[2][Price]' => '5',
    'Content[2][qty]' => '1');)

    $FINALARRAY = array_merge($array1 , $array2));

    FINALARRAY = (
    'Client[ID]' => $clientDenumire, (static content provided by api developer)
    'Client[HASH]' => '7250110', (static content provided by api developer)

    'Content[0][Name]' => 'Product 1 name',
    'Content[0][Price]' => '10',
    'Content[0][qty]' => '5');

    'Content[1][Name]' => 'Product 2 name',
    'Content[1][Price]' => '12',
    'Content[1][qty]' => '3');

    'Content[2][Name]' => 'Delivery',
    'Content[2][Price]' => '5',
    'Content[2][qty]' => '1');
    )

    But how can i do array2 ? how to extract the products outside the loop.....
    Last edited by doghi22; 28 May 2021 at 02:53 PM.

  4. #4
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,682
    Plugin Contributions
    9

    Default Re: Admin order edit, how to extrat prducts as array

    Quote Originally Posted by doghi22 View Post
    ...
    I know i can merge arrays and its the best way to work in this project.
    i think not necessarily. i think you need to understand arrays a bit better...

    Quote Originally Posted by doghi22 View Post

    how to extract the products outside the loop.....
    i would do something like this:

    PHP Code:
        require('includes/application_top.php');
        require_once 
    DIR_WS_CLASSES 'order.php';

        
    $orderNo 17575;  // your order number
        
    $clientDenumire 'denumire';

        
    $order = new order($orderNo);

        
    $finalArray[] = [
            
    'Client[ID]' => $clientDenumire,
            
    'Client[HASH]' => '7250110',
        ];

        for (
    $i 0$n sizeof($order->products); $i $n$i++) {
            
    $finalArray[] = [
                
    'name' => $order->products[$i]['name'],
                
    'qty' => $order->products[$i]['qty'],
                
    'price' => $order->products[$i]['price'],
            ];
        }

        if (
    in_array('ot_shipping'array_column($order->totals'class'))) {
            
    $finalArray[] = [
                
    'name' => $order->totals[array_search('ot_shipping'array_column($order->totals'class'))]['title'],
                
    'qty' => 1,
                
    'price' => $order->totals[array_search('ot_shipping'array_column($order->totals'class'))]['value'],
            ];
        } 
    best.
    author of square Webpay.
    mxWorks has premium plugins. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

 

 

Similar Threads

  1. v156 ZC156c Admin - Unable to edit prducts or add new product
    By pecani in forum General Questions
    Replies: 2
    Last Post: 15 Oct 2019, 11:29 AM
  2. Replies: 2
    Last Post: 8 Apr 2015, 01:23 PM
  3. v138a how to edit sort order value in the category browsing page of admin?
    By hmdnawaz in forum Setting Up Categories, Products, Attributes
    Replies: 3
    Last Post: 6 Apr 2012, 01:48 PM
  4. Edit Orders addon: PHP Warning: asort() expects parameter 1 to be array
    By dutchy in forum All Other Contributions/Addons
    Replies: 0
    Last Post: 26 Aug 2010, 08:42 PM
  5. How do I Edit Order of Order Totals in Order Confirmation Email?
    By toussi in forum Managing Customers and Orders
    Replies: 1
    Last Post: 20 Mar 2009, 08:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR