Good morning! I'm already 2 weeks trying to solve my problem and I did not find the answer anywhere until I tried this method but it still gives error: MarketPay API
Paid market documentation passes this template:
$preference_data = array(
"items" => array(
array(
"title" => "Produto teste",
"quantity" => 1,
"currency_id" => "BRL",
"unit_price" => 10.00
)
)
);
$preference = $mp->create_preference($preference_data);
But I do not know how to pass more than one product added to the cart. I already tried to make an array to pull the items, but without success.
$items = array();
foreach($cartItems as $item){
$items[] = array(
"title" => $item->getProduct()->getName(),
"quantity" => $item->getQuantity(),
"currency_id" => "BRL",
"unit_price" => $item->getProduct()->getPrice()
);
}
$preference_data = array(
"items" =>$items
);
$preference = $mp->create_preference($preference_data);