0

For ecommerce, that expected name value pair I have the following approved code:

function create_example_purchase() {

set_credentials();
$purchase = array(
    'name'        => 'Digital Good Purchase Example',
    'description' => 'Example Digital Good Purchase',
    'amount'      => '12.00', // sum of all item_amount
    'items'       => array(
        array( // First item
            'item_name'        => 'First item name',
            'item_description' => 'a description of the 1st item',
            'item_amount'      => '6.00',
            'item_tax'         => '0.00',
            'item_quantity'    => 1,
            'item_number'      => 'XF100',
        ),
        array( // Second item
            'item_name'        => 'Second Item',
            'item_description' => 'a description of the 2nd item',
            'item_amount'      => '3.00',
            'item_tax'         => '0.00',
            'item_quantity'    => 2,
            'item_number'      => 'XJ100',
        ),
    )
);

return new Purchase( $purchase); 

}

I would like to get $items Array inside associative $purchase array dynamically from shipping cart.

Is there a way to generate exactly the same output above?

My dirty solution, to write $purchase array as string inclusive the generated $items array in a file and include it later in the called script.

Help appreciated.

Ayad Mfs
  • 33
  • 5

1 Answers1

0
$itemsArray = function_that_returns_your_2d_item_array();

$purchase['items'] = $itemsArray;

or if the function_that_returns_your_2d_item_array() returns a 2d array indexed by 'items' you could do:

$purchase = array_merge($purchase, $itemsArray);
ncremins
  • 9,140
  • 2
  • 25
  • 24
  • Thank you creminsn, the output is though different. When I rename array inside to $purchase['items'] , the output will be even more similar. The problem output must be the same to be accepted. – Ayad Mfs Apr 06 '12 at 13:01