Ciao a tutti,

da poco ho iniziato col php ma non riesco ad ultimare un ciclo che deve passare dei valori a simplexml

La struttura del file xml dovrebbe essere (accanto al tag metto il nome della funzione della libreria che ho a disposizione)

<Variations> VariationsType
<Variation> VariationType
<Quantity> int </Quantity>
<SKU> SKUType (string) </SKU>
<StartPrice> AmountType (double) </StartPrice>
<VariationSpecifics> NameValueListArrayType
<NameValueList> NameValueListType
<Name> string </Name>
<Value> string </Value>
</NameValueList>
</VariationSpecifics>
</Variation>
</Variations>

Le "variationspecifics" andranno lette in un differente database mysql quindi la logica sarà

1) leggi le opzioni in array
2) scrivi tanti <Variation> fin quando non finiscono queste opzioni

Ho tirato su questo codice ma mi crea vari "NameValueList", senza però scriverci dentro i corrispondenti valori Name e Value, o meglio Name e Value vanno a finire fuori dalla struttura (vedi output alla fine del post): dove sbaglio?


$array_opzioni=array('6.25 inches','6.50 inches','6.75 inches');
$i=0;
echo "numero opzioni".count($array_opzioni);
$numero_opzioni=count($array_opzioni);

foreach ($array_opzioni as $opzione){
while ($i<$numero_opzioni) {

$vtset = new VariationType();
$nvlatset = new NameValueListArrayType();
$nvltset[] = new NameValueListType();

$vtset->SKU = 'SKU '.$opzione;
$vtset->StartPrice = $prezzo;
$vtset->Quantity = '10';

$nvltset[]->Name='colore';
$nvltset[]->Value=$opzione;

$nvlatset->NameValueList = $nvltset;
$vtset->VariationSpecifics = $nvlatset;

$item->Variations->Variation = $vtset;

echo "ciclo ";
$i++;
}
}


OUTPUT:

[Variationsrotected] => VariationsType Object
(
[Variationrotected] => VariationType Object
(
[SKUrotected] => SKU 6.25 inches
[StartPricerotected] => 292.990005
[Quantityrotected] => 10
[VariationSpecificsrotected] => NameValueListArrayType Object
(
[NameValueListrotected] => Array
(
[0] => NameValueListType Object
(
[Namerotected] =>
[Valuerotected] =>
[Sourcerotected] =>
[_dataInValueArrayrotected] =>
[_typeNamerotected] => NameValueListType
[_nsrotected] =>
[_nsURIrotected] => urn:ebay:apis:eBLBaseComponents
[_isArrayTyperotected] =>
[_attributes] => Array
(
)

[attributeValues] =>
[valuerotected] =>
)

[1] => stdClass Object
(
[Name] => colore
)

[2] => stdClass Object
(
[Value] => 6.25 inches
)

[3] => NameValueListType Object
(
[Namerotected] =>
[Valuerotected] =>
[Sourcerotected] =>
[_dataInValueArrayrotected] =>
[_typeNamerotected] => NameValueListType
[_nsrotected] =>
[_nsURIrotected] => urn:ebay:apis:eBLBaseComponents
[_isArrayTyperotected] =>
[_attributes] => Array
(
)

[attributeValues] =>
[valuerotected] =>
)

[4] => stdClass Object
(
[Name] => colore
)

[5] => stdClass Object
(
[Value] => 6.25 inches
)

[6] => NameValueListType Object
(
[Namerotected] =>
[Valuerotected] =>
[Sourcerotected] =>
[_dataInValueArrayrotected] =>
[_typeNamerotected] => NameValueListType
[_nsrotected] =>
[_nsURIrotected] => urn:ebay:apis:eBLBaseComponents
[_isArrayTyperotected] =>
[_attributes] => Array
(
)

[attributeValues] =>
[valuerotected] =>
)

[7] => stdClass Object
(
[Name] => colore
)

[8] => stdClass Object
(
[Value] => 6.25 inches
)

)

[_dataInValueArrayrotected] =>
[_typeNamerotected] => NameValueListArrayType
[_nsrotected] =>
[_nsURIrotected] => urn:ebay:apis:eBLBaseComponents
[_isArrayTyperotected] =>
[_attributes] => Array
(
)

[attributeValues] =>
[valuerotected] =>
)

Grazie!