Skip to content

Commit a3f3dd4

Browse files
authored
Merge pull request #13 from humanwere/master
Ürün Oluşturma
2 parents 76038c9 + 02cc797 commit a3f3dd4

File tree

4 files changed

+97
-9
lines changed

4 files changed

+97
-9
lines changed

IS/PazarYeri/Trendyol/Helper/Format.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,12 @@ public static function unixTime($timestamp)
8484
* @param int $timestamp
8585
*
8686
*/
87-
public static function trim($text)
88-
{
89-
return trim($text);
90-
}
87+
public static function trim($text)
88+
{
89+
if(is_string($text)){
90+
return trim($text);
91+
}
92+
return $text;
93+
}
9194

9295
}

IS/PazarYeri/Trendyol/Helper/Request.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace IS\PazarYeri\Trendyol\Helper;
44

5+
use IS\PazarYeri\Trendyol\Helper\Format;
6+
57
Class Request
68
{
79

@@ -230,25 +232,28 @@ public function getApiUrl($requestData)
230232
public function getResponse($query, $data, $authorization = true)
231233
{
232234

233-
$requestData = Format::initialize($query, $data);
235+
$requestData = Format::initialize($query, $data);
234236
$ch = curl_init();
237+
$header = [];
235238
curl_setopt($ch, CURLOPT_URL, $this->getApiUrl($requestData));
236239
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->method);
237240
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
238241
curl_setopt($ch, CURLOPT_HEADER, false);
242+
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
239243
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
240244

241245
curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent());
242246

243247
if ($authorization) {
244-
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Basic ' . $this->authorization()));
248+
$header[] = 'Authorization: Basic ' . $this->authorization();
245249
}
246250

247251
if ($this->method == 'POST') {
252+
$header[] = 'Content-Type: application/json';
248253
curl_setopt($ch, CURLOPT_POST, 1);
249-
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($requestData));
254+
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($requestData));
250255
}
251-
256+
curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
252257
$response = trim(curl_exec($ch));
253258
if (empty($response)) {
254259
throw new TrendyolException("Trendyol boş yanıt döndürdü.");

IS/PazarYeri/Trendyol/Services/ProductService.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace IS\PazarYeri\Trendyol\Services;
44

55
use IS\PazarYeri\Trendyol\Helper\Request;
6+
use IS\PazarYeri\Trendyol\Helper\TrendyolException;
67

78
Class ProductService extends Request
89
{
@@ -52,5 +53,81 @@ public function filterProducts($data = array())
5253

5354
return $this->getResponse($query, $data);
5455
}
56+
57+
/**
58+
* Bu servis kullanılarak gönderilen ürünler Trendyol.com'da daha hızlı yayına alınmaktadır. (Ürün Aktarımı v2)
59+
*
60+
*
61+
* @param array $data
62+
* @return array
63+
* @throws TrendyolException
64+
*/
65+
public function createProducts($data = array())
66+
{
67+
$this->setApiUrl('https://api.trendyol.com/sapigw/suppliers/{supplierId}/v2/products');
68+
$this->setMethod("POST");
69+
$query = array(
70+
'items'=> array(
71+
'barcode' => '',
72+
'title' => '',
73+
'productMainId' => '',
74+
'brandId' => '',
75+
'categoryId' => '',
76+
'quantity' => '',
77+
'stockCode' => '',
78+
'dimensionalWeight' => '',
79+
'description' => '',
80+
'currencyType' => '',
81+
'listPrice' => '',
82+
'salePrice' => '',
83+
'cargoCompanyId' => '',
84+
'deliveryDuration' => '',
85+
'images' => '',
86+
'vatRate' => '',
87+
'shipmentAddressId' => '',
88+
'returningAddressId' => '',
89+
'attributes' => ''
90+
)
91+
);
92+
93+
return $this->getResponse($query, $data);
94+
}
95+
96+
/**
97+
* Trendyol'a aktarılan ve onaylanan ürünlerin fiyat ve stok bilgileri eş zamana yakın güncellenir. Stok ve fiyat bligilerini istek içerisinde ayrı ayrı gönderebilirsiniz.
98+
*
99+
* @param array $data
100+
* @return array
101+
* @throws TrendyolException
102+
*/
103+
public function updatePriceAndInventory(array $data = array())
104+
{
105+
106+
$this->setApiUrl('https://api.trendyol.com/sapigw/suppliers/{supplierId}/products/price-and-inventory');
107+
$this->setMethod("POST");
108+
$query = array(
109+
'items'=> array(
110+
'barcode' => '',
111+
'quantity' => '',
112+
'listPrice' => '',
113+
'salePrice' => '',
114+
)
115+
);
116+
return $this->getResponse($query, $data);
117+
}
118+
119+
/**
120+
* Bu method yardımıyla batchRequestId ile alınan işlemlerin sonucunun kontrolü yapılabilir.
121+
*
122+
* @param string $batchRequestId
123+
* @return array
124+
* @throws TrendyolException
125+
*/
126+
public function getBatchRequestResult($batchRequestId)
127+
{
128+
$this->setApiUrl('https://api.trendyol.com/sapigw/suppliers/{supplierId}/products/batch-requests/{batchRequestId}');
129+
130+
return $this->getResponse(true, array('batchRequestId' => $batchRequestId));
131+
}
55132
}
56133

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
"email": "[email protected]"
1111
}
1212
],
13-
"require": {},
13+
"require": {
14+
"ext-curl": "*",
15+
"ext-json": "*"
16+
},
1417
"autoload": {
1518
"psr-4": {
1619
"IS\\PazarYeri\\Trendyol\\": "IS/PazarYeri/Trendyol"

0 commit comments

Comments
 (0)