Skip to content

Commit 93fd572

Browse files
authored
Merge pull request #55 from pipedrive/GRAL-2493
GRAL-2493 Add support to custom fields in products
2 parents f4771b8 + 385ecb6 commit 93fd572

File tree

6 files changed

+14
-160
lines changed

6 files changed

+14
-160
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6307,7 +6307,7 @@ $results = $products->searchProducts($collect);
63076307

63086308
### <a name="add_a_product"></a>![Method: ](https://apidocs.io/img/method.png ".ProductsController.addAProduct") addAProduct
63096309

6310-
> Adds a new product to the products inventory. For more information on how to add a product, see <a href="https://pipedrive.readme.io/docs/adding-a-product" target="_blank" rel="noopener noreferrer">this tutorial</a>.
6310+
> Adds a new product to the products inventory. For more information on how to add a product, see <a href="https://pipedrive.readme.io/docs/adding-a-product" target="_blank" rel="noopener noreferrer">this tutorial</a>. Note that you can supply additional custom fields along with the request that are not described here. These custom fields are different for each Pipedrive account and can be recognized by long hashes as keys. To determine which custom fields exists, fetch the productFields and look for 'key' values.
63116311
63126312

63136313
```php
@@ -6388,7 +6388,7 @@ $products->getOneProduct($id);
63886388

63896389
### <a name="update_a_product"></a>![Method: ](https://apidocs.io/img/method.png ".ProductsController.updateAProduct") updateAProduct
63906390

6391-
> Updates product data.
6391+
> Updates product data. Note that you can supply additional custom fields along with the request that are not described here. These custom fields are different for each Pipedrive account and can be recognized by long hashes as keys. To determine which custom fields exists, fetch the productFields and look for 'key' values.
63926392
63936393

63946394
```php

src/Controllers/BaseController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class BaseController
2424
* User-agent to be sent with API calls
2525
* @var string
2626
*/
27-
const USER_AGENT = 'Pipedrive-SDK-PHP-3.2.0';
27+
const USER_AGENT = 'Pipedrive-SDK-PHP-4.0.0';
2828

2929
/**
3030
* HttpCallBack instance associated with this controller

src/Controllers/DealsController.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,7 @@ public function getAllDeals(
174174
//handle errors defined at the API level
175175
$this->validateResponse($_httpResponse, $_httpContext);
176176

177-
$mapper = $this->getJsonMapper();
178-
179-
return CamelCaseHelper::keysToCamelCase($mapper->mapClass($response->body, 'Pipedrive\\Models\\GetDeals'));
177+
return CamelCaseHelper::keysToCamelCase($response->body);
180178
}
181179

182180
/**
@@ -508,9 +506,7 @@ public function getDetailsOfADeal(
508506
//handle errors defined at the API level
509507
$this->validateResponse($_httpResponse, $_httpContext);
510508

511-
$mapper = $this->getJsonMapper();
512-
513-
return CamelCaseHelper::keysToCamelCase($mapper->mapClass($response->body, 'Pipedrive\\Models\\GetDeal'));
509+
return CamelCaseHelper::keysToCamelCase($response->body);
514510
}
515511

516512
/**

src/Controllers/ProductsController.php

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,7 @@ public function getAllProducts(
106106
//handle errors defined at the API level
107107
$this->validateResponse($_httpResponse, $_httpContext);
108108

109-
$mapper = $this->getJsonMapper();
110-
111-
return CamelCaseHelper::keysToCamelCase($mapper->mapClass($response->body, 'Pipedrive\\Models\\Product'));
109+
return CamelCaseHelper::keysToCamelCase($response->body);
112110
}
113111

114112

@@ -381,29 +379,18 @@ public function updateAProduct(
381379
$_headers = array (
382380
'user-agent' => BaseController::USER_AGENT,
383381
'Accept' => 'application/json',
382+
'content-type' => 'application/json; charset=utf-8',
384383
'Authorization' => sprintf('Bearer %1$s', Configuration::$oAuthToken->accessToken)
385384
);
386385

387-
//prepare parameters
388-
$_parameters = array (
389-
'name' => $this->val($options, 'name'),
390-
'code' => $this->val($options, 'code'),
391-
'unit' => $this->val($options, 'unit'),
392-
'tax' => $this->val($options, 'tax'),
393-
'active_flag' => APIHelper::prepareFormFields($this->val($options, 'activeFlag')),
394-
'visible_to' => APIHelper::prepareFormFields($this->val($options, 'visibleTo')),
395-
'owner_id' => $this->val($options, 'ownerId'),
396-
'prices' => $this->val($options, 'prices')
397-
);
398-
399386
//call on-before Http callback
400-
$_httpRequest = new HttpRequest(HttpMethod::PUT, $_headers, $_queryUrl, $_parameters);
387+
$_httpRequest = new HttpRequest(HttpMethod::PUT, $_headers, $_queryUrl, $options);
401388
if ($this->getHttpCallBack() != null) {
402389
$this->getHttpCallBack()->callOnBeforeRequest($_httpRequest);
403390
}
404391

405392
//and invoke the API call request to fetch the response
406-
$response = Request::put($_queryUrl, $_headers, Request\Body::Form($_parameters));
393+
$response = Request::put($_queryUrl, $_headers, Request\Body::Json($options));
407394

408395
$_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body);
409396
$_httpContext = new HttpContext($_httpRequest, $_httpResponse);
@@ -416,9 +403,7 @@ public function updateAProduct(
416403
//handle errors defined at the API level
417404
$this->validateResponse($_httpResponse, $_httpContext);
418405

419-
$mapper = $this->getJsonMapper();
420-
421-
return CamelCaseHelper::keysToCamelCase($mapper->mapClass($response->body, 'Pipedrive\\Models\\Product'));
406+
return CamelCaseHelper::keysToCamelCase($response->body);
422407
}
423408

424409
/**
@@ -650,19 +635,14 @@ public function addAFollowerToAProduct(
650635
'Authorization' => sprintf('Bearer %1$s', Configuration::$oAuthToken->accessToken)
651636
);
652637

653-
//prepare parameters
654-
$_parameters = array (
655-
'user_id' => $this->val($options, 'userId')
656-
);
657-
658638
//call on-before Http callback
659-
$_httpRequest = new HttpRequest(HttpMethod::POST, $_headers, $_queryUrl, $_parameters);
639+
$_httpRequest = new HttpRequest(HttpMethod::POST, $_headers, $_queryUrl, $options);
660640
if ($this->getHttpCallBack() != null) {
661641
$this->getHttpCallBack()->callOnBeforeRequest($_httpRequest);
662642
}
663643

664644
//and invoke the API call request to fetch the response
665-
$response = Request::post($_queryUrl, $_headers, Request\Body::Form($_parameters));
645+
$response = Request::post($_queryUrl, $_headers, Request\Body::Json($options));
666646

667647
$_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body);
668648
$_httpContext = new HttpContext($_httpRequest, $_httpResponse);

src/Models/GetDealsTimeline.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ class GetDealsTimeline implements JsonSerializable
2323
/**
2424
* Open and won Deals grouped into periods by defined interval, amount and date-type dealField
2525
* (field_key)
26-
* @var \Pipedrive\Models\Data25|null $data public property
26+
* @var \Pipedrive\Models\Data25[]|null $data public property
2727
*/
2828
public $data;
2929

3030
/**
3131
* Constructor to set initial or default values of member properties
3232
* @param bool $success Initialization value for $this->success
33-
* @param Data25 $data Initialization value for $this->data
33+
* @param Data25[] $data Initialization value for $this->data
3434
*/
3535
public function __construct()
3636
{

src/Models/Product.php

Lines changed: 0 additions & 122 deletions
This file was deleted.

0 commit comments

Comments
 (0)