Skip to content

Commit

Permalink
Create custom field choice
Browse files Browse the repository at this point in the history
  • Loading branch information
ursuleacv committed May 8, 2018
1 parent 5ed5b03 commit d7735a4
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "ursuleacv/oauth2-lightspeed",
"description": "LightSpeed OAuth 2.0 Client Provider for The PHP League OAuth2-Client",
"license": "MIT",
"version": "2.0.24",
"version": "2.0.25",
"authors": [
{
"name": "Valentin Ursuleac",
Expand Down
64 changes: 63 additions & 1 deletion src/Provider/MerchantOS.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,68 @@ public function createCustomField($data)
return [];
}

/**
* @param integer $customFieldId
* @param array $params
* @return mixed
*/
public function getAllCustomFieldChoices($customFieldId, $params = [])
{
$response = $this->makeAPICall('Account.Customer/CustomField/'
. $customFieldId . '/CustomFieldChoice', 'GET', null, $params, null);

//validate the response
if (isset($response['CustomFieldChoice']) && $this->itemsCount($response) == 1) {
return [$response['CustomFieldChoice']];
} elseif (isset($response['CustomFieldChoice']) && $this->itemsCount($response) > 1) {
return $response['CustomFieldChoice'];
}

return [];
}

/**
* @param integer $customFieldId
* @param integer $customFieldChoiceID
* @param array $params
* @return mixed
*/
public function getCustomFieldChoice($customFieldId, $customFieldChoiceID, $params = [])
{
$response = $this->makeAPICall('Account.Customer/CustomField/'
. $customFieldId . '/CustomFieldChoice', 'GET', $customFieldChoiceID, $params, null);

//validate the response
if (isset($response['CustomFieldChoice']) && $this->itemsCount($response) == 1) {
return $response['CustomFieldChoice'];
} elseif (isset($response['CustomFieldChoice']) && $this->itemsCount($response) > 1) {
return $response['CustomFieldChoice'];
}

return [];
}

/**
* @param integer $customFieldId
* @param array $data
* @return mixed
*/
public function createCustomFieldChoice($customFieldId, $data)
{
$params = [];
$response = $this->makeAPICall('Account.Customer/CustomField/'
. $customFieldId . '/CustomFieldChoice', 'POST', null, $params, $data);

//validate the response
if (isset($response['CustomFieldChoice']) && $this->itemsCount($response) == 1) {
return $response['CustomFieldChoice'];
} elseif (isset($response['CustomFieldChoice']) && $this->itemsCount($response) > 1) {
return $response['CustomFieldChoice'];
}

return [];
}

/**
* @param array $data
* @return mixed
Expand Down Expand Up @@ -886,7 +948,7 @@ public function makeAPICall($controlUrl, $action, $uniqueId, $params, $data)
$response = $client->request($action, $url, [
'headers' => $headers,
'json' => $data,
'connect_timeout' => $this->connectTimeout
'connect_timeout' => $this->connectTimeout,
]);
} else {
$response = $client->request($action, $url, ['headers' => $headers, 'json' => $data]);
Expand Down

0 comments on commit d7735a4

Please sign in to comment.