1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Onurkacmaz\LaravelN11\Models; |
4
|
|
|
|
5
|
|
|
use Onurkacmaz\LaravelN11\Exceptions\N11Exception; |
6
|
|
|
use Onurkacmaz\LaravelN11\Interfaces\ProductInterface; |
7
|
|
|
use Onurkacmaz\LaravelN11\Service; |
8
|
|
|
use SoapClient; |
9
|
|
|
|
10
|
|
|
class Product extends Service implements ProductInterface |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
public const ACTIVE = "Active"; |
14
|
|
|
public const SUSPENDED = "Suspended"; |
15
|
|
|
public const PROHIBITED = "Prohibited"; |
16
|
|
|
public const UNLISTED = "Unlisted"; |
17
|
|
|
public const WAITING_FOR_APPROVAL = "WaitingForApproval"; |
18
|
|
|
public const REJECTED = "Rejected"; |
19
|
|
|
public const UNAPPROVED_UPDATE = "UnapprovedUpdate"; |
20
|
|
|
|
21
|
|
|
public const DISCOUNT_AMOUNT = 1; |
22
|
|
|
public const DISCOUNT_PERCENT = 2; |
23
|
|
|
public const DISCOUNTED_PRICE = 3; |
24
|
|
|
|
25
|
|
|
public const TL = 1; |
26
|
|
|
public const USD = 2; |
27
|
|
|
public const EURO = 3; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var SoapClient|null |
31
|
|
|
*/ |
32
|
|
|
private $_client; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
private $endPoint = "/ProductService.wsdl"; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* City constructor |
41
|
|
|
* @throws N11Exception|\SoapFault |
42
|
|
|
*/ |
43
|
|
|
public function __construct() |
44
|
|
|
{ |
45
|
|
|
parent::__construct(); |
46
|
|
|
$this->_client = $this->setEndPoint($this->endPoint); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param int $productId |
51
|
|
|
* @return object |
52
|
|
|
* @description N11 ürün ID sini kullanarak sistemde kayıtlı olan ürünün bilgilerini getirir. |
53
|
|
|
*/ |
54
|
|
|
public function getProductByProductId(int $productId): object |
55
|
|
|
{ |
56
|
|
|
$this->_parameters["productId"] = $productId; |
57
|
|
|
return $this->_client->GetProductByProductId($this->_parameters); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param string $productSellerCode |
62
|
|
|
* @return object |
63
|
|
|
* @description Mağaza ürün kodunu kullanarak sistemde kayıtlı olan ürünün bilgilerini getirir. |
64
|
|
|
*/ |
65
|
|
|
public function getProductBySellerCode(string $productSellerCode): object |
66
|
|
|
{ |
67
|
|
|
$this->_parameters["sellerCode"] = $productSellerCode; |
68
|
|
|
return $this->_client->GetProductBySellerCode($this->_parameters); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param int $currentPage |
73
|
|
|
* @param int $pageSize |
74
|
|
|
* @return object |
75
|
|
|
*/ |
76
|
|
|
public function getProductList(int $currentPage = 1, int $pageSize = 100): object |
77
|
|
|
{ |
78
|
|
|
$this->_parameters["pagingData"] = [ |
79
|
|
|
"currentPage" => $currentPage, |
80
|
|
|
"pageSize" => $pageSize |
81
|
|
|
]; |
82
|
|
|
return $this->_client->GetProductList($this->_parameters); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param array $data |
87
|
|
|
* @return object |
88
|
|
|
* @description Yeni ürün oluşturmak veya mevcut ürünü güncellemek için kullanılır. |
89
|
|
|
* Ürün kodu “productSellerCode” adıyla veirlen data bu mağaza için bir kayıtlı bir ürünü gösteriyorsa bu ürün güncellenir, aksi halde yeni bir ürün oluşturulur. |
90
|
|
|
*/ |
91
|
|
|
public function saveProduct(array $data): object |
92
|
|
|
{ |
93
|
|
|
$this->_parameters["product"] = $data; |
94
|
|
|
return $this->_client->SaveProduct($this->_parameters); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param int $currentPage |
99
|
|
|
* @param int $pageSize |
100
|
|
|
* @param string|null $keyword |
101
|
|
|
* @param null $saleStartDate |
102
|
|
|
* @param null $saleEndDate |
103
|
|
|
* @param string $approvalStatus |
104
|
|
|
* @return object |
105
|
|
|
* @description Mağaza ürünlerini aramak için kullanılır. |
106
|
|
|
*/ |
107
|
|
|
public function searchProducts(int $currentPage = 1, int $pageSize = 100, string $keyword = null, $saleStartDate = null, $saleEndDate = null, $approvalStatus = self::ACTIVE): object |
108
|
|
|
{ |
109
|
|
|
$this->_parameters["pagingData"] = [ |
110
|
|
|
"currentPage" => $currentPage, |
111
|
|
|
"pageSize" => $pageSize |
112
|
|
|
]; |
113
|
|
|
$this->_parameters["productSearch"] = [ |
114
|
|
|
"name" => $keyword, |
115
|
|
|
"saleDate" => [ |
116
|
|
|
"startDate" => $saleStartDate, |
117
|
|
|
"endDate" => $saleEndDate, |
118
|
|
|
] |
119
|
|
|
]; |
120
|
|
|
$this->_parameters["approvalStatus"] = $approvalStatus; |
121
|
|
|
return $this->_client->SearchProducts($this->_parameters); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @param int $productId |
126
|
|
|
* @return object |
127
|
|
|
* @description Kayıtlı olan bir ürünü N11 Id si kullanarak silmek için kullanılır. |
128
|
|
|
*/ |
129
|
|
|
public function deleteProductById(int $productId): object |
130
|
|
|
{ |
131
|
|
|
$this->_parameters["productId"] = $productId; |
132
|
|
|
$this->_client->DeleteProductById($this->_parameters); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @param string $productSellerCode |
137
|
|
|
* @return object |
138
|
|
|
* @description Kayıtlı olan bir ürünü mağaza ürün kodu kullanılarak silmek için kullanılır. |
139
|
|
|
*/ |
140
|
|
|
public function deleteProductBySellerCode(string $productSellerCode): object |
141
|
|
|
{ |
142
|
|
|
$this->_parameters["productSellerCode"] = $productSellerCode; |
143
|
|
|
$this->_client->DeleteProductBySellerCode($this->_parameters); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @param int $productId |
148
|
|
|
* @param int $discountType |
149
|
|
|
* @param float|int $discountValue |
150
|
|
|
* @param string|null $startDate |
151
|
|
|
* @param string|null $endDate |
152
|
|
|
* @return object |
153
|
|
|
* @description Bir ürünün N11 ürün ID sini kullanarak indirim bilgilerinin güncellenmesi için kullanılır. |
154
|
|
|
* Girilen indirim miktarı ürün listeleme fiyatına uygulanır. |
155
|
|
|
* Liste fiyatı ile ürünün indirimli fiyatı arasındaki fark kadar ürün stok birim fiyatlarına da indirim uygulanır. |
156
|
|
|
*/ |
157
|
|
|
public function updateDiscountValueByProductId(int $productId, int $discountType = self::DISCOUNT_AMOUNT, float $discountValue = 0, string $startDate = null, string $endDate = null): object |
158
|
|
|
{ |
159
|
|
|
$this->_parameters["productId"] = $productId; |
160
|
|
|
$this->_parameters["discountType"] = $discountType; |
161
|
|
|
$this->_parameters["productDiscount"] = [ |
162
|
|
|
"discountValue" => $discountValue, |
163
|
|
|
"discountStartDate" => $startDate, |
164
|
|
|
"discountEndDate" => $endDate, |
165
|
|
|
]; |
166
|
|
|
return $this->_client->UpdateDiscountValueByProductId($this->_parameters); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @param string $productSellerCode |
171
|
|
|
* @param int $discountType |
172
|
|
|
* @param float|int $discountValue |
173
|
|
|
* @param string|null $startDate |
174
|
|
|
* @param string|null $endDate |
175
|
|
|
* @return object |
176
|
|
|
* @description Bir ürünün mağaza ürün kodunu kullanarak indirim bilgilerinin güncellenmesi için kullanılır. |
177
|
|
|
* Girilen indirim miktarı ürün listeleme fiyatına uygulanır. |
178
|
|
|
* Liste fiyatı ile ürünün indirimli fiyatı arasındaki fark kadar ürün stok birim fiyatlarına da indirim uygulanır. |
179
|
|
|
*/ |
180
|
|
|
public function updateDiscountValueByProductSellerCode(string $productSellerCode, int $discountType = self::DISCOUNT_AMOUNT, float $discountValue = 0, string $startDate = null, string $endDate = null): object |
181
|
|
|
{ |
182
|
|
|
$this->_parameters["productSellerCode"] = $productSellerCode; |
183
|
|
|
$this->_parameters["discountType"] = $discountType; |
184
|
|
|
$this->_parameters["productDiscount"] = [ |
185
|
|
|
"discountValue" => $discountValue, |
186
|
|
|
"discountStartDate" => $startDate, |
187
|
|
|
"discountEndDate" => $endDate, |
188
|
|
|
]; |
189
|
|
|
return $this->_client->UpdateDiscountValueByProductSellerCode($this->_parameters); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @param int $productId |
194
|
|
|
* @param float $price |
195
|
|
|
* @param int $currencyType |
196
|
|
|
* @param string|null $sellerStockCode |
197
|
|
|
* @param float|null $optionPrice |
198
|
|
|
* @return object |
199
|
|
|
* @description Bir ürünün N11 ürün ID si kullanılarak ürünün sadece baz fiyat bilgilerini, |
200
|
|
|
* ürün stok birimi fiyat bilgilerini veya her ikisinin güncellenmesi için kullanılır. |
201
|
|
|
*/ |
202
|
|
|
public function updateProductPriceById(int $productId, float $price, $currencyType = self::TL, string $sellerStockCode = null, float $optionPrice = null): object |
203
|
|
|
{ |
204
|
|
|
$this->_parameters["productId"] = $productId; |
205
|
|
|
$this->_parameters["price"] = $price; |
206
|
|
|
$this->_parameters["currencyType"] = $currencyType; |
207
|
|
|
$this->_parameters["product"] = [ |
208
|
|
|
"stockItems" => [ |
209
|
|
|
"stockItem" => [ |
210
|
|
|
"sellerStockCode" => $sellerStockCode, |
211
|
|
|
"optionPrice" => $optionPrice, |
212
|
|
|
] |
213
|
|
|
] |
214
|
|
|
]; |
215
|
|
|
return $this->_client->UpdateProductPriceById($this->_parameters); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @param string $productSellerCode |
220
|
|
|
* @param float $price |
221
|
|
|
* @param int $currencyType |
222
|
|
|
* @param string|null $sellerStockCode |
223
|
|
|
* @param float|null $optionPrice |
224
|
|
|
* @return object |
225
|
|
|
* @description Bir ürünün N11 ürün ID si kullanılarak ürünün sadece baz fiyat bilgilerini, |
226
|
|
|
* ürün stok birimi fiyat bilgilerini veya her ikisinin güncellenmesi için kullanılır. |
227
|
|
|
*/ |
228
|
|
|
public function updateProductPriceBySellerCode(string $productSellerCode, float $price, $currencyType = self::TL, string $sellerStockCode = null, float $optionPrice = null): object |
229
|
|
|
{ |
230
|
|
|
$this->_parameters["productSellerCode"] = $productSellerCode; |
231
|
|
|
$this->_parameters["price"] = $price; |
232
|
|
|
$this->_parameters["currencyType"] = $currencyType; |
233
|
|
|
$this->_parameters["product"] = [ |
234
|
|
|
"stockItems" => [ |
235
|
|
|
"stockItem" => [ |
236
|
|
|
"sellerStockCode" => $sellerStockCode, |
237
|
|
|
"optionPrice" => $optionPrice, |
238
|
|
|
] |
239
|
|
|
] |
240
|
|
|
]; |
241
|
|
|
return $this->_client->UpdateProductPriceBySellerCode($this->_parameters); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
} |
245
|
|
|
|