Get from ProductData (Unit, Group)

Forum for .PHP developers using the E-conomic API.
Exchange your ideas, tip and tricks using the API.
Best Practices

Get from ProductData (Unit, Group)

Postby thauser » Thu Sep 15, 2011 9:16 pm

Hi!

Code: Select all
// Fetch list of all products.
$productHandles = $client->Product_GetAll()->Product_GetAllResult->ProductHandle;
$productDataObjects =$client->Product_GetDataArray(array('entityHandles' => $productHandles))->Product_GetDataArrayResult->ProductData;

            foreach ($productDataObjects as $i => $productData) {
           
            ...CODE HERE...

}


I can get a lot of values - like;

$productData->Number
$productData->Name
$productData->SalesPrice

But I can NOT get these values;

$productData->Unit
$productData->ProductGroup

Any ideas?

BR Thauser
-
thauser
 
Posts: 6
Joined: Thu Sep 15, 2011 9:08 pm

Re: Get from ProductData (Unit, Group)

Postby Christian Estrup » Sat Sep 17, 2011 7:57 am

Hi,
As you can see here - https://secure.e-conomic.com/secure/api ... ct_GetData - ProductData most certainly does include both unit and group references.

What makes you think you can't get hold of these?


BR,
Christian Estrup
Chief Architect

Image
Online accounting
User avatar
Christian Estrup
 
Posts: 245
Joined: Tue Jun 09, 2009 6:37 pm

Re: Get from ProductData (Unit, Group)

Postby thauser » Sat Sep 17, 2011 10:21 am

I can´t - try it with this code - the last two does not come out;

Code: Select all
<?

    // Helper function to check query parameters.
    function checkParameter($param)
    {
        if (!$_REQUEST[$param])
        {
            echo "Missing <code>" . $param . "</code> parameter in query string.";
            exit(0);
        }       
    }
   
    checkParameter("agreementNumber");
    checkParameter("username");
    checkParameter("password");
   
    $wsdlUrl = 'https://www.e-conomic.com/secure/api1/EconomicWebservice.asmx?WSDL';
       
    $client = new SoapClient($wsdlUrl, array("trace" => 1, "exceptions" => 1));         
   
    echo "Connecting to e-conomic API<br />";
    $client->Connect(array(
        'agreementNumber' => $_REQUEST['agreementNumber'],
        'userName'        => $_REQUEST['username'],
        'password'        => $_REQUEST['password']));

try
{

    // Fetch list of all products.
    $productHandles = $client->Product_GetAll()->Product_GetAllResult->ProductHandle;
    $productDataObjects =$client->Product_GetDataArray(array('entityHandles' => $productHandles))->Product_GetDataArrayResult->ProductData;

            foreach ($productDataObjects as $i => $productData) {

            echo "1 ".$productData->Number."<br>";
            echo "2 ".$productData->Name."<br>";
            echo "3 ".$productData->SalesPrice."<br>";
            echo "4 ".$productData->Unit."<br>";
            echo "5 ".$productData->Group."<br><br>";

            }

// Disconnect e-conomic API
$client->Disconnect();
echo "Disconnected from e-conomic API<br />";
}

catch(Exception $exception)
{
    print("<p><i>" . $exception->getMessage() . "</i></p>");       
    $client->Disconnect();
}
?>


BR Thauser
-
thauser
 
Posts: 6
Joined: Thu Sep 15, 2011 9:08 pm

Re: Get from ProductData (Unit, Group)

Postby Christian Estrup » Sat Sep 17, 2011 11:04 am

I'm no expert on PHP - but what your ProductData really returns for ProductGroup and Unit are actually a ProductGroupHandle and a UnitHandle, respectively.


BR,
Christian Estrup
Chief Architect

Image
Online accounting
User avatar
Christian Estrup
 
Posts: 245
Joined: Tue Jun 09, 2009 6:37 pm

Re: Get from ProductData (Unit, Group)

Postby thauser » Sat Sep 17, 2011 9:52 pm

Christian,

We are moving in the right direction - know I can get the numbers with;

Code: Select all
$productData->UnitHandle->Number;
$productData->ProductGroupHandle->Number;


But I can NOT get the name (eg. of the unit).

In the API Contents PDF, Units is listet as including Number, Name


y.e-static.net/file-att/api-contents/api-contents.pdf

Suggestions?

BR Thauser
-
thauser
 
Posts: 6
Joined: Thu Sep 15, 2011 9:08 pm

Re: Get from ProductData (Unit, Group)

Postby Christian Estrup » Sun Sep 18, 2011 6:45 am

Again, not knowing anything about PHP:

The handle 'happens to include' a Number, which 'happens to be' both the ID and the user-visible number.

However, downloading ProductData does not automatically transfer ALL properties of ALL related objects - such as unit and group. If it did, then you'd quickly be auto-recursively getting much more data than you need.

In .NET, you'd be able to do something like:

string unitName = objProductData.Unit.Name;

However, in PHP, you may or may not need to explicitly do a Unit_FindByNumber(), passing the Unit handle included in the ProductData.

Somehow I sense you SHOULD be able to do something like what you can in .NET - but suffice to say, that depends on how your PHP-WSDL-consumption-object-conversion-whatever works out, and I'm out of my league here.

Anyone?


BR,
Christian Estrup
Chief Architect

Image
Online accounting
User avatar
Christian Estrup
 
Posts: 245
Joined: Tue Jun 09, 2009 6:37 pm

Re: Get from ProductData (Unit, Group)

Postby thauser » Sun Sep 18, 2011 10:18 pm

Got it - almost gave up...

Find the unit name by its number (2 in this case);

Code: Select all
$unitHandle = array('Number' => 2);
$unitName = $client->Unit_GetName(array('unitHandle' => $unitHandle));
echo "U: ".$unitName->Unit_GetNameResult."<br>";


BR Thauser
-
thauser
 
Posts: 6
Joined: Thu Sep 15, 2011 9:08 pm


Return to PHP



cron