$base='Host';
$proxy = new SoapClient($base.'/api/v2_soap?wsdl=1');
$sessionId = $proxy->login('user123', 'user123'))
$allCategories = $proxy -> catalogCategoryTree($sessionId, 2);
$allCategories = get_object_vars($allCategories);
$i = 0;
foreach($allCategories['children'] as $k => $v ){
$v=get_object_vars($v);
$cat[$i]["RootCategory"] = array("Category" => $v['name']);
$subCat = $proxy -> catalogCategoryTree($sessionId, $v['category_id']);
$subCat = get_object_vars($subCat);
$ii = 0;
foreach($subCat['children'] as $k1=>$v1) {
$v1 = get_object_vars($v1);
$cat[$i]["SubCategory"][$ii]['Subcatinfo']= array("SubCategory" =>$v1['name'],"SubCategory_id"=>$v1['category_id']);
$res = $proxy->catalogCategoryAssignedProducts($sessionId,$v1['category_id']);
$iii = 0;
foreach($res as $key=>$value) {
$value = get_object_vars($value);
$att=array("name", "description", "short_description");
$res2 = $proxy -> catalogProductInfo($sessionId,'13');
foreach($res2 as $key2=>$value2) {
var_dump("Name=>",$value2['name']);
$value2 = get_object_vars($value2);
$cat[$i]["SubCategory"][$ii]['Product_Details'][$iii]["Product_info"]= array("Product_id"=>$value['product_id'],"Product_Name" =>$value2["name"],"Product_sku"=>$value2["sku"],"Product_Categories"=>$value2['categories']);
}
$iii++;
}
$ii++;
}
$i++;
}
echo json_encode($cat);
以下代码的OutPut如下 -
[
{
"RootCategory": {
"Category": "Mens Wear"
}
},
{
"RootCategory": {
"Category": "Womens Wear"
}
},
{
"RootCategory": {
"Category": "Mobile Phones"
}
},
{
"RootCategory": {
"Category": "Grocery"
},
"SubCategory": [
{
"Subcatinfo": {
"SubCategory": "SPICES & SEASONING",
"SubCategory_id": 28
}
},
{
"Subcatinfo": {
"SubCategory": "CEREALS & PULSES",
"SubCategory_id": 29
}
},
{
"Subcatinfo": {
"SubCategory": "RICE & FLOUR",
"SubCategory_id": 30
},
"Product_Details": [
{
"Product_info": {
"Product_id": 13,
"Product_Name": null,
"Product_sku": null,
"Product_Categories": null
}
},
{
"Product_info": {
"Product_id": 24,
"Product_Name": null,
"Product_sku": null,
"Product_Categories": null
}
}
]
},
{
"Subcatinfo": {
"SubCategory": "OIL & GHEE",
"SubCategory_id": 31
}
},
{
"Subcatinfo": {
"SubCategory": "SWEETNER & WHITNER",
"SubCategory_id": 32
}
},
{
"Subcatinfo": {
"SubCategory": "OTHERS",
"SubCategory_id": 33
}
}
]
},
{
"RootCategory": {
"Category": "Food"
},
"SubCategory": [
{
"Subcatinfo": {
"SubCategory": "DRIED READY MEALS",
"SubCategory_id": 34
}
},
{
"Subcatinfo": {
"SubCategory": "SAUCES,SPREADS & PICKLES",
"SubCategory_id": 35
}
},
{
"Subcatinfo": {
"SubCategory": "BAKERY",
"SubCategory_id": 36
}
},
{
"Subcatinfo": {
"SubCategory": "CHIPS & NAMKEENS",
"SubCategory_id": 37
}
}
]
},
{
"RootCategory": {
"Category": "BEVERAGES"
},
"SubCategory": [
{
"Subcatinfo": {
"SubCategory": "TEA & COFFEE",
"SubCategory_id": 42
}
},
{
"Subcatinfo": {
"SubCategory": "HEALTH & ENERGY DRINKS",
"SubCategory_id": 43
}
},
{
"Subcatinfo": {
"SubCategory": "FRUIT DRINKS",
"SubCategory_id": 44
}
}
]
},
{
"RootCategory": {
"Category": "PERSONAL CARE"
},
"SubCategory": [
{
"Subcatinfo": {
"SubCategory": "FACE CARE & LOTION",
"SubCategory_id": 41
}
},
{
"Subcatinfo": {
"SubCategory": "FACE WASH & SCRUBS",
"SubCategory_id": 45
}
},
{
"Subcatinfo": {
"SubCategory": "SHAMPOO & CONDITIONER",
"SubCategory_id": 46
},
"Product_Details": [
{
"Product_info": {
"Product_id": 17,
"Product_Name": null,
"Product_sku": null,
"Product_Categories": null
}
}
]
},
{
"Subcatinfo": {
"SubCategory": "ORAL CARE",
"SubCategory_id": 47
}
},
{
"Subcatinfo": {
"SubCategory": "BODY & HANDWASH",
"SubCategory_id": 48
}
},
{
"Subcatinfo": {
"SubCategory": "HAIR OIL & SERUM",
"SubCategory_id": 49
},
"Product_Details": [
{
"Product_info": {
"Product_id": 16,
"Product_Name": null,
"Product_sku": null,
"Product_Categories": null
}
},
{
"Product_info": {
"Product_id": 21,
"Product_Name": null,
"Product_sku": null,
"Product_Categories": null
}
}
]
},
{
"Subcatinfo": {
"SubCategory": "DEO,PERFUMES & TALC",
"SubCategory_id": 50
}
},
{
"Subcatinfo": {
"SubCategory": "HAIR STYLING CREAMS & GEL",
"SubCategory_id": 51
}
},
{
"Subcatinfo": {
"SubCategory": "SHAVING NEEDS",
"SubCategory_id": 52
}
},
{
"Subcatinfo": {
"SubCategory": "SHOE CARE",
"SubCategory_id": 58
}
}
]
},
{
"RootCategory": {
"Category": "DETERGENT & TOILETRIES"
},
"SubCategory": [
{
"Subcatinfo": {
"SubCategory": "DETERGENT BAR & POWDER",
"SubCategory_id": 53
},
"Product_Details": [
{
"Product_info": {
"Product_id": 14,
"Product_Name": null,
"Product_sku": null,
"Product_Categories": null
}
},
{
"Product_info": {
"Product_id": 15,
"Product_Name": null,
"Product_sku": null,
"Product_Categories": null
}
},
{
"Product_info": {
"Product_id": 20,
"Product_Name": null,
"Product_sku": null,
"Product_Categories": null
}
},
{
"Product_info": {
"Product_id": 22,
"Product_Name": null,
"Product_sku": null,
"Product_Categories": null
}
}
]
},
{
"Subcatinfo": {
"SubCategory": "SANITARY&FLOOR CLEANERS",
"SubCategory_id": 54
}
},
{
"Subcatinfo": {
"SubCategory": "FABRIC CARE",
"SubCategory_id": 55
}
},
{
"Subcatinfo": {
"SubCategory": "DETERGENT BAR & POWDER",
"SubCategory_id": 56
}
},
{
"Subcatinfo": {
"SubCategory": "DISHWASHER AGENTS",
"SubCategory_id": 57
}
}
]
},
{
"RootCategory": {
"Category": "Baby CARE"
},
"SubCategory": [
{
"Subcatinfo": {
"SubCategory": "BABY DIAPERS",
"SubCategory_id": 59
}
},
{
"Subcatinfo": {
"SubCategory": "BABY CREAMS",
"SubCategory_id": 60
},
"Product_Details": [
{
"Product_info": {
"Product_id": 18,
"Product_Name": null,
"Product_sku": null,
"Product_Categories": null
}
}
]
},
{
"Subcatinfo": {
"SubCategory": "BABY SOAP",
"SubCategory_id": 61
}
},
{
"Subcatinfo": {
"SubCategory": "BABY SHAMPOO",
"SubCategory_id": 62
}
},
{
"Subcatinfo": {
"SubCategory": "BABY OIL",
"SubCategory_id": 63
}
},
{
"Subcatinfo": {
"SubCategory": "BABY FOOD",
"SubCategory_id": 64
}
}
]
},
{
"RootCategory": {
"Category": "OTHER PRODUCTS"
},
"SubCategory": [
{
"Subcatinfo": {
"SubCategory": "REPELLENT",
"SubCategory_id": 73
}
},
{
"Subcatinfo": {
"SubCategory": "MEDICATIONS&TREATMENT",
"SubCategory_id": 74
},
"Product_Details": [
{
"Product_info": {
"Product_id": 23,
"Product_Name": null,
"Product_sku": null,
"Product_Categories": null
}
}
]
},
{
"Subcatinfo": {
"SubCategory": "WOMEN'S HYGIENE",
"SubCategory_id": 75
}
},
{
"Subcatinfo": {
"SubCategory": "CONDOMS",
"SubCategory_id": 76
}
},
{
"Subcatinfo": {
"SubCategory": "SEXUAL WELLNESS",
"SubCategory_id": 77
}
},
{
"Subcatinfo": {
"SubCategory": "FOIL PAPER & NAPKINS",
"SubCategory_id": 78
}
}
]
}
为什么我得到产品详细信息的空值。已经完成所有但无法获得这些确切的值。 如果我明确地传递了一个字符串(product_id),我得到了正确的输出,如
Input- $res = $proxy -> catalogProductInfo($sessionId,'13');
$res = $proxy -> catalogProductInfo($sessionId,'13');
$res = get_object_vars($res);
echojson_encode(array("Product_Name"=>$res['name'],"Product_sku"=>$res['sku'],"Product_Categories"=>$res['categories']));
Output-
{"Product_Name":"AASHIRVAAD SELECT ATTA","Product_sku":"A00669","Product_Categories":["2","18","30"]}
由于
答案 0 :(得分:0)
我只是在第4个foreach循环之前放入catalogProductInfo函数并删除那个foreach循环。代码在这里
<?php
$base='yourhost';
$proxy = new SoapClient($base.'/api/v2_soap?wsdl=1');
if($sessionId = $proxy->login('user123', 'user123'))
{
// echo "Login Success";
$functions = $proxy->__getFunctions ();
}
$allCategories = $proxy -> catalogCategoryTree($sessionId, 2);
$allCategories = get_object_vars($allCategories);
$i = 0;
foreach($allCategories['children'] as $k => $v ){
$v=get_object_vars($v);
$cat[$i]["RootCategory"] = array("Category" => $v['name']);
$subCat = $proxy -> catalogCategoryTree($sessionId, $v['category_id']);
$subCat = get_object_vars($subCat);
$ii = 0;
foreach($subCat['children'] as $k1=>$v1) {
$v1 = get_object_vars($v1);
$cat[$i]["SubCategory"][$ii]['Subcatinfo']= array("SubCategory" =>$v1['name'],"SubCategory_id"=>$v1['category_id']);
$res = $proxy -> catalogCategoryAssignedProducts($sessionId, $v1['category_id']);
$iii = 0;
foreach($res as $key=>$value) {
$value = get_object_vars($value);
$att=array("name", "description", "short_description");
$res2 = $proxy -> catalogProductInfo($sessionId,strval($value['product_id']));
$res2=get_object_vars($res2);
//echo "Name=".$res2['name'];
$cat[$i]["SubCategory"][$ii]['Product_Details'][$iii]["Product_info"]= array("Product_id"=>$value['product_id'],"Product_Name" =>$res2["name"],
"Product_sku"=>$res2["sku"],"Product_Categories"=>$res2['categories'],"Type"=>$res2['type'],"Description"=>$res2['description'],
"Short-Description"=>$res2['short_description '],"status"=>$res2['status'],"Visibility"=>$res2['visibility'],"price"=>$res2['price'],
"special-price"=>$res2['special_price']);
$iii++;
}
$ii++;
}
$i++;
}
echo json_encode($cat);
,所需的输出是 -
[
{
"RootCategory": {
"Category": "Mens Wear"
}
},
{
"RootCategory": {
"Category": "Womens Wear"
}
},
{
"RootCategory": {
"Category": "Mobile Phones"
}
},
{
"RootCategory": {
"Category": "Grocery"
},
"SubCategory": [
{
"Subcatinfo": {
"SubCategory": "SPICES & SEASONING",
"SubCategory_id": 28
}
},
{
"Subcatinfo": {
"SubCategory": "CEREALS & PULSES",
"SubCategory_id": 29
}
},
{
"Subcatinfo": {
"SubCategory": "RICE & FLOUR",
"SubCategory_id": 30
},
"Product_Details": [
{
"Product_info": {
"Product_id": 13,
"Product_Name": "AASHIRVAAD SELECT ATTA",
"Product_sku": "A00669",
"Product_Categories": [
"2",
"18",
"30"
],
"Type": "simple",
"Description": "Aashirvaad Atta is made from the choicest grains - heavy on the palm, golden amber in colour and hard in bite. It is carefully ground using modern 'chakki - grinding' process for the perfect balance of colour, taste and nutrition which also ensures that Aashirvaad atta contains 0% Maida and is 100% Sampoorna Atta. The dough made from Aashirvaad Atta absorbs more water, hence rotis remain softer for longer.",
"Short-Description": null,
"status": "1",
"Visibility": "4",
"price": "60.0000",
"special-price": "0.0000"
}
},
{
"Product_info": {
"Product_id": 24,
"Product_Name": "AASHIRVAAD SELECT ATTA 5 Kg",
"Product_sku": "vfhbnvbh",
"Product_Categories": [
"2",
"18",
"30"
],
"Type": "simple",
"Description": "AASHIRVAAD SELECT ATTA 5 KG\r\n",
"Short-Description": null,
"status": "2",
"Visibility": "4",
"price": "50.0000",
"special-price": null
}
}
]
},
{
"Subcatinfo": {
"SubCategory": "OIL & GHEE",
"SubCategory_id": 31
}
},
{
"Subcatinfo": {
"SubCategory": "SWEETNER & WHITNER",
"SubCategory_id": 32
}
},
{
"Subcatinfo": {
"SubCategory": "OTHERS",
"SubCategory_id": 33
}
}
]
},
{
"RootCategory": {
"Category": "Food"
},
"SubCategory": [
{
"Subcatinfo": {
"SubCategory": "DRIED READY MEALS",
"SubCategory_id": 34
}
},
{
"Subcatinfo": {
"SubCategory": "SAUCES,SPREADS & PICKLES",
"SubCategory_id": 35
}
},
{
"Subcatinfo": {
"SubCategory": "BAKERY",
"SubCategory_id": 36
}
},
{
"Subcatinfo": {
"SubCategory": "CHIPS & NAMKEENS",
"SubCategory_id": 37
}
}
]
},
{
"RootCategory": {
"Category": "BEVERAGES"
},
"SubCategory": [
{
"Subcatinfo": {
"SubCategory": "TEA & COFFEE",
"SubCategory_id": 42
}
},
{
"Subcatinfo": {
"SubCategory": "HEALTH & ENERGY DRINKS",
"SubCategory_id": 43
}
},
{
"Subcatinfo": {
"SubCategory": "FRUIT DRINKS",
"SubCategory_id": 44
}
}
]
},
{
"RootCategory": {
"Category": "PERSONAL CARE"
},
"SubCategory": [
{
"Subcatinfo": {
"SubCategory": "FACE CARE & LOTION",
"SubCategory_id": 41
}
},
{
"Subcatinfo": {
"SubCategory": "FACE WASH & SCRUBS",
"SubCategory_id": 45
}
},
{
"Subcatinfo": {
"SubCategory": "SHAMPOO & CONDITIONER",
"SubCategory_id": 46
},
"Product_Details": [
{
"Product_info": {
"Product_id": 17,
"Product_Name": "TRESEMME CLIMATE CONTROL SHMPOO600ML",
"Product_sku": "A00173",
"Product_Categories": [
"2",
"22",
"46"
],
"Type": "simple",
"Description": "TRESEMME CLIMATE CONTROL SHMPOO\r\n",
"Short-Description": null,
"status": "1",
"Visibility": "4",
"price": "345.0000",
"special-price": "335.0000"
}
}
]
},
{
"Subcatinfo": {
"SubCategory": "ORAL CARE",
"SubCategory_id": 47
}
},
{
"Subcatinfo": {
"SubCategory": "BODY & HANDWASH",
"SubCategory_id": 48
}
},
{
"Subcatinfo": {
"SubCategory": "HAIR OIL & SERUM",
"SubCategory_id": 49
},
"Product_Details": [
{
"Product_info": {
"Product_id": 16,
"Product_Name": "DABUR AMLA HAIR OIL 90ML",
"Product_sku": "A00240",
"Product_Categories": [
"2",
"22",
"49"
],
"Type": "simple",
"Description": "DABUR AMLA HAIR OIL\r\n",
"Short-Description": null,
"status": "1",
"Visibility": "4",
"price": "42.0000",
"special-price": "41.0000"
}
},
{
"Product_info": {
"Product_id": 21,
"Product_Name": "DABUR AMLA HAIR OIL 275ML",
"Product_sku": "A00299",
"Product_Categories": [
"2",
"49"
],
"Type": "simple",
"Description": "DABUR AMLA HAIR OIL 275ML\r\n",
"Short-Description": null,
"status": "1",
"Visibility": "4",
"price": "125.0000",
"special-price": "120.0000"
}
}
]
},
{
"Subcatinfo": {
"SubCategory": "DEO,PERFUMES & TALC",
"SubCategory_id": 50
}
},
{
"Subcatinfo": {
"SubCategory": "HAIR STYLING CREAMS & GEL",
"SubCategory_id": 51
}
},
{
"Subcatinfo": {
"SubCategory": "SHAVING NEEDS",
"SubCategory_id": 52
}
},
{
"Subcatinfo": {
"SubCategory": "SHOE CARE",
"SubCategory_id": 58
}
}
]
},
{
"RootCategory": {
"Category": "DETERGENT & TOILETRIES"
},
"SubCategory": [
{
"Subcatinfo": {
"SubCategory": "DETERGENT BAR & POWDER",
"SubCategory_id": 53
},
"Product_Details": [
{
"Product_info": {
"Product_id": 14,
"Product_Name": "SURF EXCEL WSHG BAR 400 G",
"Product_sku": "A00179",
"Product_Categories": [
"2",
"24",
"53"
],
"Type": "simple",
"Description": "SURF EXCEL WSHG BAR 400 G\r\n",
"Short-Description": null,
"status": "1",
"Visibility": "4",
"price": "46.0000",
"special-price": "45.0000"
}
},
{
"Product_info": {
"Product_id": 15,
"Product_Name": "RIN ADVANCED PWDR 1KG",
"Product_sku": "A00303",
"Product_Categories": [
"2",
"24",
"53"
],
"Type": "simple",
"Description": "RIN ADVANCED PWDR 1KG\r\n",
"Short-Description": null,
"status": "1",
"Visibility": "4",
"price": "75.0000",
"special-price": "74.0000"
}
},
{
"Product_info": {
"Product_id": 20,
"Product_Name": "SURF EXCEL WASHING BAR 800 G",
"Product_sku": "A00300",
"Product_Categories": [
"2",
"53"
],
"Type": "simple",
"Description": "SURF EXCEL WASHING BAR 800 G\r\n",
"Short-Description": null,
"status": "1",
"Visibility": "4",
"price": "88.0000",
"special-price": "87.0000"
}
},
{
"Product_info": {
"Product_id": 22,
"Product_Name": "RIN ADVANCED PWDR 1KG",
"Product_sku": "A0030",
"Product_Categories": [
"2",
"53"
],
"Type": "simple",
"Description": "RIN ADVANCED DETERGENT POWDER\r\n",
"Short-Description": null,
"status": "1",
"Visibility": "4",
"price": "75.0000",
"special-price": "74.0000"
}
}
]
},
{
"Subcatinfo": {
"SubCategory": "SANITARY&FLOOR CLEANERS",
"SubCategory_id": 54
}
},
{
"Subcatinfo": {
"SubCategory": "FABRIC CARE",
"SubCategory_id": 55
}
},
{
"Subcatinfo": {
"SubCategory": "DETERGENT BAR & POWDER",
"SubCategory_id": 56
}
},
{
"Subcatinfo": {
"SubCategory": "DISHWASHER AGENTS",
"SubCategory_id": 57
}
}
]
},
{
"RootCategory": {
"Category": "Baby CARE"
},
"SubCategory": [
{
"Subcatinfo": {
"SubCategory": "BABY DIAPERS",
"SubCategory_id": 59
}
},
{
"Subcatinfo": {
"SubCategory": "BABY CREAMS",
"SubCategory_id": 60
},
"Product_Details": [
{
"Product_info": {
"Product_id": 18,
"Product_Name": "JOHNSON BABY MILK CREAM 50G",
"Product_sku": "A00187",
"Product_Categories": [
"2",
"26",
"60"
],
"Type": "simple",
"Description": "JOHNSON BABY MILK CREAM\r\n",
"Short-Description": null,
"status": "1",
"Visibility": "4",
"price": "70.0000",
"special-price": "68.0000"
}
}
]
},
{
"Subcatinfo": {
"SubCategory": "BABY SOAP",
"SubCategory_id": 61
}
},
{
"Subcatinfo": {
"SubCategory": "BABY SHAMPOO",
"SubCategory_id": 62
}
},
{
"Subcatinfo": {
"SubCategory": "BABY OIL",
"SubCategory_id": 63
}
},
{
"Subcatinfo": {
"SubCategory": "BABY FOOD",
"SubCategory_id": 64
}
}
]
},
{
"RootCategory": {
"Category": "OTHER PRODUCTS"
},
"SubCategory": [
{
"Subcatinfo": {
"SubCategory": "REPELLENT",
"SubCategory_id": 73
}
},
{
"Subcatinfo": {
"SubCategory": "MEDICATIONS&TREATMENT",
"SubCategory_id": 74
},
"Product_Details": [
{
"Product_info": {
"Product_id": 23,
"Product_Name": "VOLINI SPRAY 40 GM",
"Product_sku": "A00361",
"Product_Categories": [
"2",
"74"
],
"Type": "simple",
"Description": "VOLINI SPRAY 40 GM\r\n",
"Short-Description": null,
"status": "1",
"Visibility": "4",
"price": "99.0000",
"special-price": "95.0000"
}
}
]
},
{
"Subcatinfo": {
"SubCategory": "WOMEN'S HYGIENE",
"SubCategory_id": 75
}
},
{
"Subcatinfo": {
"SubCategory": "CONDOMS",
"SubCategory_id": 76
}
},
{
"Subcatinfo": {
"SubCategory": "SEXUAL WELLNESS",
"SubCategory_id": 77
}
},
{
"Subcatinfo": {
"SubCategory": "FOIL PAPER & NAPKINS",
"SubCategory_id": 78
}
}
]
}
]
It works for me.