Olay şu xml içlerinde stok kodları var bu stok koduna göre ürün stoklarını çekiyor sistem.
Çözerim diyen iban ile birlikte direkt whatsappdan yazabilir.
Whatsapp.
Çalışan Kod
public function ipromosyonApi($id){
$urunler = array();
$xml = simplexml_load_file("http://www.ipromosyon.com/xml");
for($i = 0; $i < count($xml->urun); $i++){
$urunler[trim((string)$xml->urun[$i]->urun_kodu)] = array(
"urun_kodu" => trim((string)$xml->urun[$i]->urun_kodu),
"mevcut_stok" => trim((string)$xml->urun[$i]->mevcut_stok),
"toplam_stok" => trim((string)$xml->urun[$i]->toplam_stok),
);
if(count($xml->urun[$i]->urun_secenekleri) != 0){
for($j = 0; $j < count($xml->urun[$i]->urun_secenekleri->secenek); $j++){
$urunler[trim((string)$xml->urun[$i]->urun_kodu)]["secenekler"][(string)$xml->urun[$i]->urun_secenekleri->secenek[$j]["adi"]] = (string)$xml->urun[$i]->urun_secenekleri->secenek[$j];
}
}
}
if(array_key_exists($id, $urunler) == true){
return $urunler[$id];
} else {
return array();
}
}Çalıştırmak istediğim KOD
//PromolifeXML
public function promolifeApi($id){
$urunler = array();
$xml = simplexml_load_file("https://www.promolife.com.tr/xml/product.xml");
for($i = 0; $i < count($xml->urun); $i++){
$Urunler[trim((string)$xml->Urun[$i]->UrunKod)] = array(
"urun_kodu" => trim((string)$xml->Urun[$i]->UrunKod),
"mevcut_stok" => trim((string)$xml->Urun[$i]->UrunToplamStok),
"toplam_stok" => trim((string)$xml->Urun[$i]->UrunToplamStok),
);
if(count($xml->urun[$i]->urun_secenekleri) != 0){
for($j = 0; $j < count($xml->urun[$i]->urun_secenekleri->secenek); $j++){
$urunler[trim((string)$xml->urun[$i]->urun_kodu)]["secenekler"][(string)$xml->urun[$i]->urun_secenekleri->secenek[$j]["adi"]] = (string)$xml->urun[$i]->urun_secenekleri->secenek[$j];
}
}
}
if(array_key_exists($id, $urunler) == true){
return $urunler[$id];
} else {
return array();
}
}