Skip to content

Commit

Permalink
Merge pull request vindi#109 from cedran/master
Browse files Browse the repository at this point in the history
fix 2: PLANOS (3) e (4) - ajuste na edicao de planos importados
  • Loading branch information
cedran authored Aug 14, 2024
2 parents c847309 + 8ab298a commit 9ab8c4c
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions Model/Vindi/Plan.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ public function save($data = []): int
$endpoint = 'plans';
$method = 'POST';

if ($plan = $this->findOneByCode($data['code'])) {
if (!empty($data['vindi_id']) && $plan = $this->findOneById($data['vindi_id'])) {
$endpoint .= '/' . $plan['id'];
$method = 'PUT';
} elseif ($plan = $this->findOneByCode($data['code'])) {
$endpoint .= '/' . $plan['id'];
$method = 'PUT';
}
Expand Down Expand Up @@ -63,7 +66,25 @@ public function findOneByCode($code)
}

/**
* @param $page
* Retrieve a plan by its ID
*
* @param int $id
* @return array|bool
* @throws LocalizedException
*/
public function findOneById(int $id)
{
$response = $this->api->request("plans/{$id}", 'GET');

if ($response && isset($response['plan']['id'])) {
return $response['plan'];
}

return false;
}

/**
* @param int $page
* @return bool|mixed
*/
public function getAllPlans($page = 1)
Expand Down

0 comments on commit 9ab8c4c

Please sign in to comment.