Completed
Push — master ( 540c4f...fc8089 )
by Onur
01:02
created

Product::updateProductBasic()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
c 0
b 0
f 0
rs 9.552
cc 1
nc 1
nop 1
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 = self::GENERAL_LIMIT): 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 = self::GENERAL_LIMIT, 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
     * @param array $data
246
     * @return object
247
     * @description Kayıtlı olan bir ürünün, N11 ürün ID’si ya da mağaza kodu ile ürün fiyatını, ürün üzerindeki indirimi ve isteğe bağlı olarak stok ID’si ya da mağaza stok kodu ile belirtilen stoklarının, miktarı ve ilgili stok biriminin liste fiyatının güncellenmesi için kullanılır.
248
     */
249
    public function updateProductBasic(array $data): object
250
    {
251
        $this->_parameters["productId"] = $data["productId"];
252
        $this->_parameters["productSellerCode"] = $data["productSellerCode"];
253
        $this->_parameters["price"] = $data["price"];
254
        $this->_parameters["description"] = $data["description"];
255
        $this->_parameters["images"] = [
256
            "image" => $data["images"]
257
        ];
258
        $this->_parameters["productDiscount"] = [
259
            "discountType" => $data["discountType"],
260
            "discountValue" => $data["discountValue"],
261
            "discountStartDate" => $data["startDate"],
262
            "discountEndDate" => $data["discountEndDate"],
263
            "discountStockCode" => $data["discountStockCode"],
264
            "optionPrice" => $data["optionPrice"],
265
            "quantity" => $data["quantity"],
266
        ];
267
        $this->_parameters["stockItems"] = [
268
            "stockItem" => $data["stockItems"]
269
        ];
270
        return $this->_client->UpdateProductBasic($this->_parameters);
271
    }
272
273
    /**
274
     * @param int $productId
275
     * @param string $buyerEmail
276
     * @param string $subject
277
     * @param $status
278
     * @param string $questionDate
279
     * @param int $currentPage
280
     * @param int $pageSize
281
     * @return object
282
     * @description Müşterileriniz tarafından mağazanıza sorulan soruları listeler.
283
     * Sorularınızı listelemek için Appkey ve Appsecret bilgileriniz gerekmektedir.
284
     */
285
    public function getProductQuestionList(int $productId, string $buyerEmail, string $subject, $status, string $questionDate, int $currentPage = 1, int $pageSize = self::GENERAL_LIMIT): object {
286
        $this->_parameters["currentPage"] = $currentPage;
287
        $this->_parameters["pageSize"] = $pageSize;
288
        $this->_parameters["productQuestionSearch"] = [
289
            "productId" => $productId,
290
            "buyerEmail" => $buyerEmail,
291
            "subject" => $subject,
292
            "status" => $status,
293
            "questionDate" => $questionDate,
294
        ];
295
        return $this->_client->GetProductQuestionList($this->_parameters);
296
    }
297
298
    /**
299
     * @param int $productQuestionId
300
     * @return object
301
     * @description GetProductQuestionList ile sıralanan soruların içeriğini, buradan gelen ID ve getProductQuestionDetail yardımıyla görüntüleyebilirsiniz.
302
     */
303
    public function getProductQuestionDetail(int $productQuestionId): object {
304
        $this->_parameters["productQuestionId"] = $productQuestionId;
305
        return $this->_client->GetProductQuestionDetail($this->_parameters);
306
    }
307
308
    /**
309
     * @param int $productQuestionId
310
     * @param string $productAnswer
311
     * @return object
312
     * @description Müşterilerden gelen ürün sorularını cevaplamak için kullanılır.
313
     * Cevap vermek için productQuestionId değeri zorunludur ve GetProductQuestionList‘ten id edinilebilir.
314
     */
315
    public function saveProductAnswer(int $productQuestionId, string $productAnswer): object {
316
        $this->_parameters["productQuestionId"] = $productQuestionId;
317
        $this->_parameters["productAnswer"] = $productAnswer;
318
        return $this->_client->SaveProductAnswer($this->_parameters);
319
    }
320
321
    /**
322
     * @return object
323
     * @description Seller ın sahip olduğu tüm ürünleri, ait olduğu statülere göre sınıflandırıp, statü/sayı bilgisi döner.
324
     * Seller a göre cevap döndüğü için istekte sadece authorization olması yeterlidir.
325
     * Her bir seller maksimum 3 kez istek gönderebilir.
326
     */
327
    public function productAllStatusCountsRequest(): object {
328
        return $this->_client->ProductAllStatusCountsRequest($this->_parameters);
329
    }
330
331
}
332