<?php

ini_set('include_path', ini_get('include_path') . ':' . $_SERVER['DOCUMENT_ROOT'] . '/admin/includes/');
include_once 'doba/DobaProductAPI.php';
$simple = "\r\n<dce>\r\n  <response>\r\n    <outcome>success</outcome>\r\n    <products>\r\n      <product>\r\n        <product_id>51696</product_id>\r\n        <title>a</title>\r\n        <description>&lt;li&gt;Allows accessories to be in neat application&lt;li&gt;Automatic switching to the active device without connecting and reconnecting&lt;li&gt;Matches with Playstation 2&#x99; unit</description>\r\n        <product_sku>GEPS2CS</product_sku>\r\n        <brand>GAME ELEMENTS</brand>\r\n        <condition>new</condition>\r\n        <freight>a</freight>\r\n        <ship_width>8</ship_width>\r\n        <ship_length>11</ship_length>\r\n        <ship_height>4</ship_height>\r\n        <ship_weight>2.16</ship_weight>\r\n        <ship_cost>10.49</ship_cost>\r\n        <items>\r\n          <item>\r\n            <item_id>64670</item_id>\r\n            <supplier_id>a</supplier_id>\r\n            <name>PS2&reg; Command Stand 2-in-1</name>\r\n            <item_sku>GEPS2CS</item_sku>\r\n            <map>0.00</map>\r\n            <price>25.08</price>\r\n            <prepay_price>24.00</prepay_price>\r\n            <msrp>49.95</msrp>\r\n            <qty_avail>3</qty_avail>\r\n            <stock>in-stock</stock>\r\n            <last_update>2008-02-20 17:06:10</last_update>\r\n          </item>\r\n        </items>\r\n        <images>\r\n          <image>\r\n            <url>http://images.doba.com/products/1/geps2cs.jpg</url>\r\n            <thumb_url>http://images.doba.com/products/1/_thumb/geps2cs.jpg</thumb_url>\r\n            <image_height>200</image_height>\r\n            <image_width>240</image_width>\r\n            <default>1</default>\r\n          </image>\r\n        </images>\r\n        <supplier_id>1</supplier_id>\r\n        <supplier_name>Alpha</supplier_name>\r\n        <supplier_processing>1-4 business days to ship out and receive tracking number.</supplier_processing>\r\n        <supplier_alerts>a</supplier_alerts>\r\n        <upc>026616065332</upc>\r\n        <supplier_notes>This supplier does not ship to Hawaii or Alaska. \r\n\r\nPlasma TVs are not eligible for return to Alpha. Most TV/Monitors 30&#x94;/projections products and Samsung TV&#x92;s 14&#x94; or larger to not qualify under normal Alpha Return Policy. Contact Samsung @ 1-800-SAMSUNG for service. Most TV&#x92;s/Monitors 30&#x94; or larger and projection products require in-field service repairs under manufacturer&#x92;s warranty. These products are not eligible for return. Please contact the appropriate manufacturer for troubleshooting repair service.</supplier_notes>\r\n        <supplier_drop_fee>2.50</supplier_drop_fee>\r\n        <product_group>basic</product_group>\r\n      </product>\r\n    </products>\r\n  </response>\r\n</dce>\r\n";
echo "<pre>";
$p = DobaProductAPI::parseProductDetails($simple);
print_r($p);
echo "</pre>";
<?php

ini_set('include_path', ini_get('include_path') . ':' . $_SERVER['DOCUMENT_ROOT'] . '/admin/includes/');
include_once 'doba/DobaApi.php';
include_once 'doba/DobaProductAPI.php';
$api = new DobaApi();
// change the following variables to have the data you wish to submit
$action = DOBA_API_ACTION_GETPRODUCTDETAIL;
$data = array('watchlist_id' => '94227');
// end fields to be changed
echo "<strong>Testing:</strong> " . $action . "<br><strong>With data:</strong><pre>";
print_r($data);
echo "</pre><strong>Result:</strong>";
if ($api->compileRequestXml($action, $data) && $api->sendRequest()) {
    echo " Successfully submitted<br><strong>Response XML:</strong><pre>";
    echo htmlentities($api->getResponseXml());
    $productList = DobaProductAPI::parseProductDetails($api->getResponseXml());
    var_dump($productList);
} else {
    if ($api->hasErrors()) {
        echo " Submission Failure, with errors<br><strong>Errors:</strong><pre>";
        print_r($api->getErrors());
    } else {
        echo " Submission Failure, no errors<br><strong>Object dump:</strong><pre>";
        var_dump($api);
    }
}
echo "</pre>";
                $msg = 'Your request could not be completed at this time.  Please try again later.';
            }
        }
    } else {
        $msg = 'Please select a watchlist to use.';
    }
}
$watchlists = array();
if (DOBA_API_ENABLED !== true) {
    $msg = 'You must set up your Doba API authentication before you can use this tool.  Find out more by sending an email to support@doba.com.';
} else {
    // load up the watchlists set up under the current api auth
    $action = DOBA_API_ACTION_GETWATCHLISTS;
    $data = array();
    if ($api->compileRequestXml($action, $data) && $api->sendRequest()) {
        $res = DobaProductAPI::parseWatchlistResponse($api->getResponseXml());
        $watchlists = $res['data'];
        if ($res['response'] !== 'success') {
            $msg = ERROR_WATCHLIST_REQUEST_NOT_SUCCESS;
        }
    } else {
        if ($api->hasErrors()) {
            $msg = 'Your request could not be completed due to the following errors:<br>- ' . implode('<br>- ', $api->getErrors());
        } else {
            $msg = ERROR_WATCHLIST_REQUEST_NOT_SUCCESS;
        }
    }
}
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php 
 function parseProductDetails($data)
 {
     $productList = new DobaProducts();
     $p = new XMLParser($data);
     $ProdDetails = $p->getOutput();
     if ($ProdDetails['dce']['response']['outcome'] == 'success') {
         if (array_key_exists('product', $ProdDetails['dce']['response']['products'])) {
             //Only 1 product;
             $prod = $ProdDetails['dce']['response']['products']['product'];
             $tempDPDArray = DobaProductAPI::findItems($prod);
             foreach ($tempDPDArray as $currProd) {
                 $currProd->product_id($prod['product_id']);
                 $currProd->title($prod['title']);
                 $currProd->description($prod['description']);
                 DobaProductAPI::findImage($prod, $currProd);
                 $currProd->product_sku($prod['product_sku']);
                 $currProd->ship_weight($prod['ship_weight']);
                 $currProd->ship_cost($prod['ship_cost']);
                 $currProd->upc($prod['upc']);
                 $currProd->brand($prod['brand']);
                 if (isset($prod['OSC_BRAND'])) {
                     $currProd->brand($prod['OSC_BRAND']);
                 }
                 $currProd->category_name('');
                 if (isset($prod['OSC_CATEGORY'])) {
                     $currProd->category_name($prod['OSC_CATEGORY']);
                 }
                 //Set Price
                 if (isset($prod['OSC_WHOLESALE_MARKUP_PERCENT'])) {
                     $currProd->price(DobaInteraction::setPrice('osc_wholesale_markup_percent', $prod['OSC_WHOLESALE_MARKUP_PERCENT'], $currProd->wholesale_price(), $currProd->map(), $currProd->msrp()));
                 } elseif (isset($prod['OSC_WHOLESALE_MARKUP_DOLLAR'])) {
                     $currProd->price(DobaInteraction::setPrice('osc_wholesale_markup_dollar', $prod['OSC_WHOLESALE_MARKUP_DOLLAR'], $currProd->wholesale_price(), $currProd->map(), $currProd->msrp()));
                 } elseif (isset($prod['OSC_MARKUP_EXACT'])) {
                     $currProd->price(DobaInteraction::setPrice('osc_markup_exact', $prod['OSC_MARKUP_EXACT'], $currProd->wholesale_price(), $currProd->map(), $currProd->msrp()));
                 } elseif (isset($prod['OSC_MSRP_MARKUP_PERCENT'])) {
                     $currProd->price(DobaInteraction::setPrice('osc_msrp_markup_percent', $prod['OSC_MSRP_MARKUP_PERCENT'], $currProd->wholesale_price(), $currProd->map(), $currProd->msrp()));
                 } elseif (isset($prod['OSC_MSRP_MARKUP_DOLLAR'])) {
                     $currProd->price(DobaInteraction::setPrice('osc_msrp_markup_dollar', $prod['OSC_MSRP_MARKUP_DOLLAR'], $currProd->wholesale_price(), $currProd->map(), $currProd->msrp()));
                 } else {
                     $currProd->price(DobaInteraction::setPrice('none', $currProd->wholesale_price(), $currProd->wholesale_price(), $currProd->map(), $currProd->msrp()));
                 }
                 //Set Quantity
                 if (isset($prod['OSC_QUANTITY_AUTOADJUST'])) {
                     $currProd->quantity(DobaInteraction::setQuantity('osc_quantity_autoadjust', $prod['OSC_QUANTITY_AUTOADJUST'], $currProd->quantity));
                 } elseif (isset($prod['OSC_QUANTITY_EXACT'])) {
                     $currProd->quantity(DobaInteraction::setQuantity('osc_quantity_exact', $prod['OSC_QUANTITY_EXACT'], $currProd->quantity));
                 } else {
                     $currProd->quantity(DobaInteraction::setQuantity('none', $currProd->quantity, $currProd->quantity));
                 }
                 $productList->addProduct($currProd);
             }
         } else {
             foreach ($ProdDetails['dce']['response']['products'] as $prod) {
                 $tempDPDArray = DobaProductAPI::findItems($prod);
                 foreach ($tempDPDArray as $currProd) {
                     $currProd->product_id($prod['product_id']);
                     $currProd->title($prod['title']);
                     $currProd->description($prod['description']);
                     DobaProductAPI::findImage($prod, $currProd);
                     $currProd->product_sku($prod['product_sku']);
                     $currProd->ship_weight($prod['ship_weight']);
                     $currProd->ship_cost($prod['ship_cost']);
                     $currProd->upc($prod['upc']);
                     $currProd->brand($prod['brand']);
                     if (isset($prod['OSC_BRAND'])) {
                         $currProd->brand($prod['OSC_BRAND']);
                     } else {
                         if (isset($prod['osc_brand'])) {
                             $currProd->brand($prod['osc_brand']);
                         }
                     }
                     $currProd->category_name('');
                     if (isset($prod['OSC_CATEGORY'])) {
                         $currProd->category_name($prod['OSC_CATEGORY']);
                     } else {
                         if (isset($prod['osc_category'])) {
                             $currProd->category_name($prod['osc_category']);
                         }
                     }
                     //Set Price
                     if (isset($prod['OSC_WHOLESALE_MARKUP_PERCENT'])) {
                         $currProd->price(DobaInteraction::setPrice('osc_wholesale_markup_percent', $prod['OSC_WHOLESALE_MARKUP_PERCENT'], $currProd->wholesale_price(), $currProd->map(), $currProd->msrp()));
                     } elseif (isset($prod['OSC_WHOLESALE_MARKUP_DOLLAR'])) {
                         $currProd->price(DobaInteraction::setPrice('osc_wholesale_markup_dollar', $prod['OSC_WHOLESALE_MARKUP_DOLLAR'], $currProd->wholesale_price(), $currProd->map(), $currProd->msrp()));
                     } elseif (isset($prod['OSC_MARKUP_EXACT'])) {
                         $currProd->price(DobaInteraction::setPrice('osc_markup_exact', $prod['OSC_MARKUP_EXACT'], $currProd->wholesale_price(), $currProd->map(), $currProd->msrp()));
                     } elseif (isset($prod['OSC_MSRP_MARKUP_PERCENT'])) {
                         $currProd->price(DobaInteraction::setPrice('osc_msrp_markup_percent', $prod['OSC_MSRP_MARKUP_PERCENT'], $currProd->wholesale_price(), $currProd->map(), $currProd->msrp()));
                     } elseif (isset($prod['OSC_MSRP_MARKUP_DOLLAR'])) {
                         $currProd->price(DobaInteraction::setPrice('osc_msrp_markup_dollar', $prod['OSC_MSRP_MARKUP_DOLLAR'], $currProd->wholesale_price(), $currProd->map(), $currProd->msrp()));
                     } else {
                         $currProd->price(DobaInteraction::setPrice('none', $currProd->wholesale_price(), $currProd->wholesale_price(), $currProd->map(), $currProd->msrp()));
                     }
                     //Set Quantity
                     if (isset($prod['OSC_QUANTITY_AUTOADJUST'])) {
                         $currProd->quantity(DobaInteraction::setQuantity('osc_quantity_autoadjust', $prod['OSC_QUANTITY_AUTOADJUST'], $currProd->quantity));
                     } elseif (isset($prod['OSC_QUANTITY_EXACT'])) {
                         $currProd->quantity(DobaInteraction::setQuantity('osc_quantity_exact', $prod['OSC_QUANTITY_EXACT'], $currProd->quantity));
                     } else {
                         $currProd->quantity(DobaInteraction::setQuantity('none', $currProd->quantity, $currProd->quantity));
                     }
                     $productList->addProduct($currProd);
                 }
             }
         }
         return $productList;
     } else {
         return $ProdDetails['dce']['response']['outcome'];
     }
 }