Skip to content

Commit 005c7eb

Browse files
committed
iyileştirmeler yapıldı.
1 parent a295a11 commit 005c7eb

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/SistemApi/Model/Urun.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php namespace SistemApi\Model;
22

3+
use Illuminate\Support\Collection;
34
use SistemApi\Model\Base\Model;
45

56
/**
@@ -16,6 +17,7 @@
1617
* // model
1718
*
1819
* @property UrunKategori kategori
20+
* @property Collection|Resim[] resimler
1921
*
2022
*/
2123
class Urun extends Model
@@ -24,6 +26,13 @@ public function __set($key, $value)
2426
{
2527
switch ($key) {
2628
case 'kategori': $value = new UrunKategori($value); break;
29+
case 'resimler':
30+
$collection = new Collection();
31+
foreach ($value as $item) {
32+
$collection->push(new Resim($item));
33+
}
34+
$value = $collection;
35+
break;
2736
}
2837

2938
parent::__set($key, $value);

src/SistemApi/Service/UrunService.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use SistemApi\Model\Response\Urun\SiparisPagedResponse;
1111
use SistemApi\Model\Response\UrunKategoriPagedResponse;
1212
use SistemApi\Model\Response\UrunPagedResponse;
13+
use SistemApi\Model\Urun;
1314
use SistemApi\Model\Urun\SiparisAdres;
1415
use SistemApi\Model\UrunKategori;
1516
use SistemApi\Model\UrunOzellikGrup;
@@ -46,6 +47,29 @@ public function liste(UrunListeAyar $ayar = null)
4647
throw new UnknownException($response);
4748
}
4849

50+
/**
51+
* @param int $id
52+
* @return Urun
53+
*
54+
* @throws NotFoundException
55+
* @throws UnauthorizedException
56+
*/
57+
public function get($id)
58+
{
59+
// response alalım
60+
$response = $this->api->get('/urun/detay/' . $id);
61+
62+
// durum koduna göre işlem yapalım
63+
switch ($response->code) {
64+
65+
case 200: return new Urun($response->body);
66+
case 401: throw new UnauthorizedException($response->body->mesaj);
67+
case 404: throw new NotFoundException($response->body->mesaj);
68+
}
69+
70+
throw new UnknownException($response);
71+
}
72+
4973
/**
5074
* @deprecated use listeKategori
5175
*

0 commit comments

Comments
 (0)