-4

I want to work with api.

Here is my code:

// create a new purchase bill
$purchase = $parasut->make('sale')->create(array (
    'description'    => $siparis,
    'invoice_id'     => null,
    'invoice_series' => null,
    'currency'       => 'TRL',
    'item_type'      => 'invoice',
    'issue_date'     => $order_date_created,
    'due_date'       => $order_date_created,
    'contact_id'     => $contactToken,
    'category_id'    => null,
    'archived'       => false,
    'billing_address' => $user_address,
    'billing_fax'   => null,
    'billing_phone' => $user_phone,
    'details_attributes' => array (
        $parasut->make('product')->getProductFromOrder(), // the products
    ),
));

Here is getProductFromOrder() function:

public function getProductFromOrder()
{
    $sku = array(5542003,5542004);
    $qty = array("3","1");
    $total = array("11.29","12.00");

    for($i=0; $i<count($sku); $i++){
        $urunler[$i] = array(
                    'product_id'     => $sku[$i], // the products
                    'quantity'       => '3',
                    'unit_price'     => '12.99',
                    'vat_rate'       => '18',
                    'discount_type'  => 'amount',
                    'discount_value' => '0',
            );
        print ($urunler[$i]);
    }
}

Its not working. When i run the first code, products not showing. Where is the mistake?

Thanks in advance for help.

A.Hakan
  • 18
  • 4

1 Answers1

1

Change the function getProductFromOrder() to this instead:

public function getProductFromOrder()
{
    $sku = array(5542003,5542004);
    $qty = array("3","1");
    $total = array("11.29","12.00");

    for($i=0; $i<count($sku); $i++){
        $urunler[$i] = array(
                    'product_id'     => $sku[$i], // the products
                    'quantity'       => '3',
                    'unit_price'     => '12.99',
                    'vat_rate'       => '18',
                    'discount_type'  => 'amount',
                    'discount_value' => '0',
            );
    }
    return $urunler;
}

Use return instead of print and write the return outside the for loop.

mega6382
  • 9,211
  • 17
  • 48
  • 69