1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Padosoft\AffiliateNetwork\Networks; |
4
|
|
|
|
5
|
|
|
use Padosoft\AffiliateNetwork\DealsResultset; |
6
|
|
|
use Padosoft\AffiliateNetwork\Product; |
7
|
|
|
use Padosoft\AffiliateNetwork\ProductsResultset; |
8
|
|
|
use Padosoft\AffiliateNetwork\Transaction; |
9
|
|
|
use Padosoft\AffiliateNetwork\Merchant; |
10
|
|
|
use Padosoft\AffiliateNetwork\Stat; |
11
|
|
|
use Padosoft\AffiliateNetwork\Deal; |
12
|
|
|
use Padosoft\AffiliateNetwork\AbstractNetwork; |
13
|
|
|
use Padosoft\AffiliateNetwork\NetworkInterface; |
14
|
|
|
use Padosoft\AffiliateNetwork\ZanoxEx; |
15
|
|
|
|
16
|
|
|
// require "../vendor/fubralimited/php-oara/Oara/Network/Publisher/Zanox/Zapi/ApiClient.php"; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class Zanox |
20
|
|
|
* @package Padosoft\AffiliateNetwork\Networks |
21
|
|
|
*/ |
22
|
|
|
class Zanox extends AbstractNetwork implements NetworkInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var object |
26
|
|
|
*/ |
27
|
|
|
private $_network = null; |
28
|
|
|
protected $_apiClient = null; |
29
|
|
|
private $_username = ''; |
30
|
|
|
private $_password = ''; |
31
|
|
|
private $_logged = false; |
32
|
|
|
protected $_tracking_parameter = 'zpar0'; |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @method __construct |
37
|
|
|
*/ |
38
|
|
View Code Duplication |
public function __construct(string $username, string $password,string $idSite='') |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
$this->_network = new ZanoxEx; |
41
|
|
|
$this->_username = $username; |
42
|
|
|
$this->_password = $password; |
43
|
|
|
$this->login( $this->_username, $this->_password ); |
44
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function login(string $username, string $password,string $idSite=''): bool |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
$this->_logged = false; |
50
|
|
|
if (isNullOrEmpty( $username ) || isNullOrEmpty( $password )) { |
51
|
|
|
|
52
|
|
|
return false; |
53
|
|
|
} |
54
|
|
|
$this->_username = $username; |
55
|
|
|
$this->_password = $password; |
56
|
|
|
$credentials = array(); |
57
|
|
|
$credentials["connectid"] = $this->_username; |
58
|
|
|
$credentials["secretkey"] = $this->_password; |
59
|
|
|
$this->_network->login( $credentials ); |
60
|
|
|
$this->_apiClient = $this->_network->getApiClient(); |
61
|
|
|
if ($this->_network->checkConnection()) { |
62
|
|
|
$this->_logged = true; |
63
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return $this->_logged; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return bool |
71
|
|
|
*/ |
72
|
|
|
public function checkLogin(): bool |
73
|
|
|
{ |
74
|
|
|
return $this->_logged; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return array of Merchants |
79
|
|
|
*/ |
80
|
|
View Code Duplication |
public function getMerchants(): array |
|
|
|
|
81
|
|
|
{ |
82
|
|
|
if (!$this->checkLogin()) { |
83
|
|
|
return array(); |
84
|
|
|
} |
85
|
|
|
$arrResult = array(); |
86
|
|
|
$merchantList = $this->_network->getMerchantList(); |
87
|
|
|
foreach ($merchantList as $merchant) { |
88
|
|
|
$Merchant = Merchant::createInstance(); |
89
|
|
|
$Merchant->merchant_ID = $merchant['cid']; |
90
|
|
|
$Merchant->name = $merchant['name']; |
91
|
|
|
$arrResult[] = $Merchant; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return $arrResult; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param int|null $merchantID |
99
|
|
|
* @param int $page |
100
|
|
|
* @param int $items_per_page |
101
|
|
|
* |
102
|
|
|
* @return DealsResultset |
103
|
|
|
*/ |
104
|
|
|
public function getDeals($merchantID=NULL,int $page = 0, int $items_per_page = 0 ): DealsResultset |
105
|
|
|
{ |
106
|
|
|
$result = DealsResultset::createInstance(); |
107
|
|
|
if (!$this->checkLogin()) { |
108
|
|
|
return $result; |
109
|
|
|
} |
110
|
|
|
/* |
111
|
|
|
if (!isIntegerPositive($items_per_page) || $items_per_page <= 0 || $items_per_page > 999) { |
112
|
|
|
$items_per_page = 999; |
113
|
|
|
} |
114
|
|
|
*/ |
115
|
|
|
$adSpaces=$this->_apiClient->getAdspaces(0,100); |
116
|
|
|
if (!is_object($adSpaces)){ |
117
|
|
|
$adSpaces=json_encode($adSpaces); |
118
|
|
|
} |
119
|
|
|
if ($adSpaces->items<1){ |
120
|
|
|
return $result; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
$adSpaceId=$adSpaces->adspaceItems->adspaceItem[0]->id; |
124
|
|
|
if (!isIntegerPositive($merchantID)){ |
125
|
|
|
$merchantID=NULL; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
$Response = $this->_apiClient->searchIncentives($merchantID,$adSpaceId,null,null, $page, $items_per_page); |
129
|
|
|
|
130
|
|
|
if (!is_object($Response)){ |
131
|
|
|
$Response=json_decode($Response); |
132
|
|
|
} |
133
|
|
|
$result->page=$Response->page; |
134
|
|
|
$result->items=$Response->items; |
135
|
|
|
$result->total=$Response->total; |
136
|
|
|
// ($Response->total>0)?$result->num_pages=(int)ceil($Response->total/$items_per_page):$result->num_pages=0; |
137
|
|
|
// Check if items exists - 2018-02-27 <PN> |
138
|
|
|
if (!property_exists($Response, 'incentiveItems')) { |
139
|
|
|
return $result; |
140
|
|
|
} |
141
|
|
|
if (!property_exists($Response->incentiveItems, 'incentiveItem')) { |
142
|
|
|
return $result; |
143
|
|
|
} |
144
|
|
|
$arrAdmediumItems = $Response->incentiveItems->incentiveItem; |
145
|
|
|
|
146
|
|
|
foreach ($arrAdmediumItems as $admediumItems) { |
147
|
|
|
$Deal = Deal::createInstance(); |
148
|
|
|
$Deal->deal_ID = (int)$admediumItems->id; |
149
|
|
|
$Deal->start_date = $Deal->convertDate($admediumItems->startDate); |
|
|
|
|
150
|
|
|
isset($admediumItems->endDate) ? $Deal->end_date = $Deal->convertDate($admediumItems->endDate): $Deal->end_date = '2099-12-31'; |
|
|
|
|
151
|
|
|
$Deal->name = $admediumItems->name; |
152
|
|
|
isset($admediumItems->couponCode) ? $Deal->code = $admediumItems->couponCode : $Deal->code = ''; |
153
|
|
|
$Deal->description = $admediumItems->info4customer; |
154
|
|
|
$Deal->information = $admediumItems->info4publisher.' '.$admediumItems->restrictions; |
155
|
|
|
$Deal->is_percentage = 0; |
|
|
|
|
156
|
|
|
$Deal->discount_amount = 0; |
|
|
|
|
157
|
|
|
$Deal->currency_initial = ''; |
158
|
|
|
if (isset($admediumItems->percentage) && isIntegerPositive($admediumItems->percentage)){ |
159
|
|
|
$Deal->is_percentage = 1; |
|
|
|
|
160
|
|
|
$Deal->discount_amount = $admediumItems->percentage; |
161
|
|
|
}elseif (isset($admediumItems->total)){ |
162
|
|
|
$Deal->discount_amount = $admediumItems->total; |
163
|
|
|
$Deal->currency_initial = $admediumItems->currency; |
164
|
|
|
} |
165
|
|
|
switch ($admediumItems->incentiveType) { |
166
|
|
|
case 'coupons': |
167
|
|
|
$Deal->deal_type = \Oara\Utilities::OFFER_TYPE_VOUCHER; |
168
|
|
|
break; |
169
|
|
|
case 'bargains': |
170
|
|
|
$Deal->deal_type = \Oara\Utilities::OFFER_TYPE_DISCOUNT; |
171
|
|
|
break; |
172
|
|
|
case 'noShippingCosts': |
173
|
|
|
$Deal->deal_type = \Oara\Utilities::OFFER_TYPE_FREE_SHIPPING; |
174
|
|
|
break; |
175
|
|
|
case 'freeProducts': |
176
|
|
|
$Deal->deal_type = \Oara\Utilities::OFFER_TYPE_FREE_ARTICLE; |
177
|
|
|
break; |
178
|
|
|
case 'lotteries': |
179
|
|
|
$Deal->deal_type = \Oara\Utilities::OFFER_TYPE_LOTTERY; |
180
|
|
|
break; |
181
|
|
|
default: |
182
|
|
|
$Deal->deal_type = \Oara\Utilities::OFFER_TYPE_DISCOUNT; |
183
|
|
|
break; |
184
|
|
|
} |
185
|
|
|
$Deal->merchant_ID = (int)$admediumItems->program->id; |
186
|
|
|
|
187
|
|
|
$Deal->merchant_name = $admediumItems->program->_; |
188
|
|
|
if (isset($admediumItems->admedia->admediumItem[0]->trackingLinks->trackingLink)) { |
189
|
|
|
$Deal->ppv = $admediumItems->admedia->admediumItem[0]->trackingLinks->trackingLink[0]->ppv; |
190
|
|
|
$Deal->ppc = $admediumItems->admedia->admediumItem[0]->trackingLinks->trackingLink[0]->ppc; |
191
|
|
|
$Deal->default_track_uri = $Deal->ppc; |
192
|
|
|
} |
193
|
|
|
else { |
194
|
|
|
$Deal->ppv = "*** NO LINK ***"; |
195
|
|
|
$Deal->ppc = "*** NO LINK ***"; |
196
|
|
|
|
197
|
|
|
} |
198
|
|
|
$arrResult[] = $Deal; |
|
|
|
|
199
|
|
|
} |
200
|
|
|
$result->deals[] = $arrResult; |
|
|
|
|
201
|
|
|
return $result; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* @param \DateTime $dateFrom |
207
|
|
|
* @param \DateTime $dateTo |
208
|
|
|
* @param int $merchantID |
|
|
|
|
209
|
|
|
* |
210
|
|
|
* @return array of Transaction |
211
|
|
|
*/ |
212
|
|
|
public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()): array |
213
|
|
|
{ |
214
|
|
|
if (!$this->checkLogin()) { |
215
|
|
|
return array(); |
216
|
|
|
} |
217
|
|
|
$dateFrom2=new \DateTime($dateFrom->format('Y-m-d')); |
218
|
|
|
if ($dateTo->format('Y-m-d')==$dateFrom2->format('Y-m-d')){ |
219
|
|
|
$dateFrom2->sub(new \DateInterval('P1D')); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
$arrResult = array(); |
223
|
|
View Code Duplication |
if (count( $arrMerchantID ) < 1) { |
|
|
|
|
224
|
|
|
$merchants = $this->getMerchants(); |
225
|
|
|
foreach ($merchants as $merchant) { |
226
|
|
|
$arrMerchantID[$merchant->merchant_ID] = ['cid' => $merchant->merchant_ID, 'name' => $merchant->name]; |
227
|
|
|
} |
228
|
|
|
} |
229
|
|
|
$transcationList = $this->_network->getTransactionList( $arrMerchantID, $dateFrom2, $dateTo ); |
230
|
|
|
foreach ($transcationList as $transaction) { |
231
|
|
|
$Transaction = Transaction::createInstance(); |
232
|
|
|
array_key_exists_safe( $transaction, |
233
|
|
|
'currency' ) ? $Transaction->currency = $transaction['currency'] : $Transaction->currency = ''; |
234
|
|
|
array_key_exists_safe( $transaction, |
235
|
|
|
'status' ) ? $Transaction->status = $transaction['status'] : $Transaction->status = ''; |
236
|
|
|
array_key_exists_safe( $transaction, |
237
|
|
|
'amount' ) ? $Transaction->amount = $transaction['amount'] : $Transaction->amount = ''; |
|
|
|
|
238
|
|
|
array_key_exists_safe( $transaction, |
239
|
|
|
'custom_id' ) ? $Transaction->custom_ID = $transaction['custom_id'] : $Transaction->custom_ID = ''; |
240
|
|
|
array_key_exists_safe( $transaction, |
241
|
|
|
'title' ) ? $Transaction->title = $transaction['title'] : $Transaction->title = ''; |
242
|
|
|
array_key_exists_safe( $transaction, |
243
|
|
|
'unique_id' ) ? $Transaction->unique_ID = $transaction['unique_id'] : $Transaction->unique_ID = ''; |
244
|
|
|
array_key_exists_safe( $transaction, |
245
|
|
|
'commission' ) ? $Transaction->commission = $transaction['commission'] : $Transaction->commission = ''; |
|
|
|
|
246
|
|
|
$date = new \DateTime( $transaction['date'] ); |
247
|
|
|
$Transaction->date = $date; // $date->format('Y-m-d H:i:s'); |
|
|
|
|
248
|
|
|
array_key_exists_safe( $transaction, |
249
|
|
|
'merchantId' ) ? $Transaction->merchant_ID = $transaction['merchantId'] : $Transaction->merchant_ID = ''; |
|
|
|
|
250
|
|
|
array_key_exists_safe( $transaction, |
251
|
|
|
'approved' ) ? $Transaction->approved = $transaction['approved'] : $Transaction->approved = ''; |
|
|
|
|
252
|
|
|
$arrResult[] = $Transaction; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
return $arrResult; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @param \DateTime $dateFrom |
260
|
|
|
* @param \DateTime $dateTo |
261
|
|
|
* @param int $merchantID |
262
|
|
|
* |
263
|
|
|
* @return array of Stat |
264
|
|
|
*/ |
265
|
|
|
public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0): array |
266
|
|
|
{ |
267
|
|
|
return array(); |
268
|
|
|
/* |
269
|
|
|
$this->_apiClient->setConnectId($this->_username); |
270
|
|
|
$this->_apiClient->setSecretKey($this->_password); |
271
|
|
|
$dateFromIsoEngFormat = $dateFrom->format('Y-m-d'); |
272
|
|
|
$dateToIsoEngFormat = $dateTo->format('Y-m-d'); |
273
|
|
|
$response = $this->_apiClient->getReportBasic($dateFromIsoEngFormat, $dateToIsoEngFormat); |
274
|
|
|
$arrResponse = json_decode($response, true); |
275
|
|
|
$reportItems = $arrResponse['reportItems']; |
276
|
|
|
$Stat = Stat::createInstance(); |
277
|
|
|
$Stat->reportItems = $reportItems; |
278
|
|
|
|
279
|
|
|
return array($Stat); |
280
|
|
|
*/ |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* @param array $params this array can contains these keys |
285
|
|
|
* string query search string |
286
|
|
|
* string searchType search type (optional) (contextual or phrase) |
287
|
|
|
* string region limit search to region (optional) |
288
|
|
|
* int categoryId limit search to categorys (optional) |
289
|
|
|
* array programId limit search to program list of programs (optional) |
290
|
|
|
* boolean hasImages products with images (optional) |
291
|
|
|
* float minPrice minimum price (optional) |
292
|
|
|
* float maxPrice maximum price (optional) |
293
|
|
|
* int adspaceId adspace id (optional) |
294
|
|
|
* int page page of result set (optional) |
295
|
|
|
* int items items per page (optional) |
296
|
|
|
* |
297
|
|
|
* @return ProductsResultset |
298
|
|
|
*/ |
299
|
|
|
public function getProducts(array $params = []): ProductsResultset |
300
|
|
|
{ |
301
|
|
|
$_params = array_merge([ |
302
|
|
|
'query' => null, |
303
|
|
|
'searchType' => null, |
304
|
|
|
'query' => null, |
305
|
|
|
'searchType' => null, |
306
|
|
|
'region' => null, |
307
|
|
|
'categoryId' => null, |
308
|
|
|
'programId' => null, |
309
|
|
|
'hasImages' => null, |
310
|
|
|
'minPrice' => null, |
311
|
|
|
'maxPrice' => null, |
312
|
|
|
'adspaceId' => null, |
313
|
|
|
'page' => 0, |
314
|
|
|
'items' => 10 |
315
|
|
|
], $params); |
316
|
|
|
$products = $this->_network->getProducts($_params); |
317
|
|
|
$set = ProductsResultset::createInstance(); |
318
|
|
|
if (!property_exists($products, 'productItems') || !property_exists($products->productItems, 'productItem')) |
319
|
|
|
{ |
320
|
|
|
return ProductsResultset::createInstance(); |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
$set->page = $products->page; |
324
|
|
|
$set->items = $products->items; |
325
|
|
|
$set->total = $products->total; |
326
|
|
|
|
327
|
|
|
foreach ($products->productItems->productItem as $productItem) { |
328
|
|
|
$Product = Product::createInstance(); |
329
|
|
|
if (property_exists($productItem, 'name')) { |
330
|
|
|
$Product->name = $productItem->name;//'Danava', |
331
|
|
|
} |
332
|
|
|
if (property_exists($productItem, 'modified')) { |
333
|
|
|
$Product->modified = $productItem->modified; //'2016-11-24T11:52:03Z', |
334
|
|
|
} |
335
|
|
|
if (property_exists($productItem, 'program')) { |
336
|
|
|
$Product->merchant_ID = $productItem->program->id; //'Twelve Thirteen DE' |
337
|
|
|
$Product->merchant_name = $productItem->program->_; //17434, |
338
|
|
|
} |
339
|
|
|
if (property_exists($productItem, 'price')) |
340
|
|
|
$Product->price = $productItem->price; //129.0 |
341
|
|
|
if (property_exists($productItem, 'currency')) |
342
|
|
|
$Product->currency = $productItem->currency; //'EUR' |
343
|
|
|
if (property_exists($productItem, 'trackingLinks') && property_exists($productItem->trackingLinks, 'trackingLink')) { |
344
|
|
|
$Product->ppv = $productItem->trackingLinks->trackingLink[0]->ppv; |
345
|
|
|
$Product->ppc = $productItem->trackingLinks->trackingLink[0]->ppc; |
346
|
|
|
$Product->adspaceId = $productItem->trackingLinks->trackingLink[0]->adspaceId; |
|
|
|
|
347
|
|
|
} |
348
|
|
|
if (property_exists($productItem, 'description')) |
349
|
|
|
$Product->description = $productItem->description; //'Rosegold trifft auf puristisches Schwarz ? aufwendige und traditionelle Makramee Technik trifft auf Eleganz. Das neue Danava Buddha Armband besteht aus schwarzem Onyx, dieser Edelstein wird sehr gerne als Schmuckstein verwendet und viel lieber getragen. Der feingearbeitete rosegoldene Buddha verleiht diesem Armband einen fernöstlichen Stil. Es lässt sich wunderbar zu allen Anlässen Tragen und zu vielen Outfits kombinieren, da es Eleganz ausstrahlt. Das Symbol des Buddhas ist besonders in dieser Saison sehr gefragt.', |
350
|
|
|
if (property_exists($productItem, 'manufacturer')) |
351
|
|
|
$Product->manufacturer = $productItem->manufacturer; //'Twelve Thirteen Jewelry' |
352
|
|
|
if (property_exists($productItem, 'ean')) |
353
|
|
|
$Product->ean = $productItem->ean; //'0796716271505' |
354
|
|
|
if (property_exists($productItem, 'deliveryTime')) |
355
|
|
|
$Product->deliveryTime = $productItem->deliveryTime; //'1-3 Tage' |
356
|
|
|
if (property_exists($productItem, 'priceOld')) |
357
|
|
|
$Product->priceOld = $productItem->priceOld; //0.0 |
358
|
|
|
if (property_exists($productItem, 'shippingCosts')) |
359
|
|
|
$Product->shippingCosts = $productItem->shippingCosts; //'0.0' |
360
|
|
|
if (property_exists($productItem, 'shipping')) |
361
|
|
|
$Product->shipping = $productItem->shipping; // '0.0' |
362
|
|
|
if (property_exists($productItem, 'merchantCategory')) |
363
|
|
|
$Product->merchantCategory = $productItem->merchantCategory; //'Damen / Damen Armbänder / Buddha Armbänder' |
364
|
|
|
if (property_exists($productItem, 'merchantProductId')) |
365
|
|
|
$Product->merchantProductId = $productItem->merchantProductId; //'BR018.M' |
366
|
|
|
if (property_exists($productItem, 'id')) |
367
|
|
|
$Product->id = $productItem->id; //'1ed7c3b4ab79cdbbf127cb78ec2aaff4' |
368
|
|
|
if (property_exists($productItem, 'image') && property_exists($productItem->image, 'large')) { |
369
|
|
|
$Product->image = $productItem->image->large; |
370
|
|
|
} |
371
|
|
|
$set->products[] = $Product; |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
return $set; |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
public function getTrackingParameter(){ |
378
|
|
|
return $this->_tracking_parameter; |
379
|
|
|
} |
380
|
|
|
} |
381
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.