Ver Mensaje Individual
  #1 (permalink)  
Antiguo 02/04/2016, 14:47
WebHelp
 
Fecha de Ingreso: junio-2008
Mensajes: 45
Antigüedad: 15 años, 11 meses
Puntos: 0
Generar un obj array

Buenas, estoy empezando a trabajar con la Api de MercadoPago , pero quería hacer un intento de carrito de compras. Pero para eso primero quería generar las preferencias de los datos.

Esto es lo que tengo que generar :

Código PHP:
$preference_data = array(
    
"items" => array(
        array(
            
"id" => "item-ID-1234",
            
"title" => "item",
            
"quantity" => 1,
            
"currency_id" => "ARS"// Available currencies at: https://api.mercadopago.com/currencies
            
"picture_url" => "https://www.mercadopago.com/org-img/MP3/home/logomp3.gif",
            
"description" => "Item description",
            
"category_id" => "art"// Available categories at https://api.mercadopago.com/item_categories
            
"unit_price" => 10.00
        
),
        array(
            
"id" => "item-ID-12343",
            
"title" => "item2",
            
"quantity" => 1,
            
"currency_id" => "ARS"// Available currencies at: https://api.mercadopago.com/currencies
            
"unit_price" => 10.00
        
)

    ),
    
"payer" => array(
        array(
            
"name" => "user-name",
            
"surname" => "user-surname",
            
"email" => "[email protected]",
            
"date_created" => "2015-06-02T12:58:41.425-04:00",
            
"phone" => array(
                
"area_code" => "11",
                
"number" => "4444-4444"
            
),
            
"identification" => array(
                
"type" => "DNI",
                
"number" => "12345678"
            
),
            
"address" => array(
                
"street_name" => "Street",
                
"street_number" => 123,
                
"zip_code" => "5700"
            

        )
    ),
); 
Yo hice un intento fallido, pero cercano ... Que seria este codigo :

Código PHP:
$general = array();
$itemstodos = (object) array( "items" => array() );
$item = (object) array(
    
"id" => "item-ID-1234",
    
"title" => "Multicolor kite",
    
"quantity" => 1,
    
"currency_id" => "ARS"// Available currencies at: https://api.mercadopago.com/currencies
    
"picture_url" => "https://www.mercadopago.com/org-img/MP3/home/logomp3.gif",
    
"description" => "Item description",
    
"category_id" => "art"// Available categories at https://api.mercadopago.com/item_categories
    
"unit_price" => 10.00
    
);

$payertodos = (object) array( "payer" => array() );

$payer = (object) array(
            
"name" => "user-name",
            
"surname" => "user-surname",
            
"email" => "[email protected]",
            
"date_created" => "2015-06-02T12:58:41.425-04:00",
            
"phone" => array(
                
"area_code" => "11",
                
"number" => "4444-4444"
            
),
            
"identification" => array(
                
"type" => "DNI",
                
"number" => "12345678"
            
),
            
"address" => array(
                
"street_name" => "Street",
                
"street_number" => 123,
                
"zip_code" => "5700"
            

        );

array_push($itemstodos->items$item);
array_push($general$itemstodos);
array_push($payertodos->payer$payer);
array_push($general$payertodos);
print_r($general); 

No se si alguien me puede ayudar xD o decirme una forma mas bonita de hacerlo.

Última edición por WebHelp; 02/04/2016 a las 15:07