This repository was archived by the owner on Feb 10, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapiclient.php
More file actions
6006 lines (4786 loc) · 185 KB
/
apiclient.php
File metadata and controls
6006 lines (4786 loc) · 185 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
define('ECWID_APIV3_URL', "https://app.ecwid.com/api/v3");
/**
* Instances of this object are returned from ApiClient's method calls. A caller then should call execute()
* on this object to make the request and return a result.
*/
abstract class ApiRequest {
/**
* A function with signature ($url, $method, $body, $headers)
* that executes the HTTP request and returns an ApiResponse object.
*/
public $executor;
public $url;
public $body;
public function __construct($executor, $url, HttpEntity $body = null) {
$this->executor = $executor;
$this->url = $url;
$this->body =$body;
}
public abstract function execute();
}
class ApiResponse {
/**
* Response data.
*/
public $data;
/**
* Response Content-Type, including charset.
*/
public $contentType;
/**
* Response headers, assoc array.
*/
public $headers;
public function __construct($data, $contentType, $headers) {
$this->data = $data;
$this->contentType = $contentType;
$this->headers = $headers;
}
}
class HttpEntity {
const JSON = "application/json; charset=utf-8";
const TEXT = "text/plain; charset=utf-8";
const BINARY = "application/octet-stream";
public $body;
public $contentType;
public function __construct($body, $contentType) {
$this->body = $body;
$this->contentType = $contentType;
}
}
class StatusException extends Exception {
public function __construct($message, $code) {
parent::__construct($message, $code);
}
}
class IllegalArgumentException extends Exception {
public function __construct($message, $code = 0) {
parent::__construct($message, $code);
}
}
class EmptyBodyException extends Exception {
public function __construct($message) {
parent::__construct($message);
}
}
class ApiDTO {
public function __construct($json = null) {
foreach ($this as $key => $val) {
unset($this->{$key});
}
if ($json != null) {
foreach ($json as $key => $value) {
$this->{$key} = $value;
}
}
}
/**
* Return an object that can be passed to json_encode()
*/
public function asJson() {
return $this;
}
}
class ApiDiscountCoupon extends ApiDTO {
/**
* Coupon title
*/
public $name;
/**
* Unique coupon code
*/
public $code;
/**
* Discount type: ABS, PERCENT or SHIPPING . Default is ABS
*/
public $discountType;
/**
* Discount coupon state: ACTIVE, PAUSED, EXPIRED or USEDUP . Default is ACTIVE
*/
public $status;
/**
* Discount amount. 0 is default
*/
public $discount;
/**
* The date of coupon launch
*/
public $launchDate;
/**
* Coupon expliration date, e.g. 2014-06-06 08:00:00 +0400
*/
public $expirationDate;
/**
* The minimum order subtotal the coupon applies to
*/
public $totalLimit;
/**
* Number of uses limitation: UNLIMITED, ONCEPERCUSTOMER, SINGLE . UNLIMITED is default
*/
public $usesLimit;
/**
* Coupon usage limitation flag identifying whether the coupon works for all customers or only repeat customers. false is default
*/
public $repeatCustomerOnly;
/**
* Coupon creation date
*/
public $creationDate;
/**
* Number of uses
*/
public $orderCount;
/**
* The products and categories the coupon can be applied to
* @var ApiDiscountCouponCatalogLimit
*/
public $catalogLimit;
public function __construct($json = null) {
parent::__construct($json);
if (isset($this->catalogLimit))
$this->catalogLimit = new ApiDiscountCouponCatalogLimit($this->catalogLimit);
}
}
class ApiDiscountCouponCatalogLimit extends ApiDTO {
/**
* Список идентификаторов товаров, перечисленных через запятую, к которым может быть применен купон
*/
public $products;
/**
* Список идентификаторов категорий, перечисленных через запятую, к товарам которых может быть применен купон
*/
public $categories;
public function __construct($json = null) {
parent::__construct($json);
}
}
class ApiNotFoundError extends ApiDTO {
/**
* Детальное сообщение об ошибке
*/
public $errorMessage;
public function __construct($json = null) {
parent::__construct($json);
}
}
class ApiIllegalParameterError extends ApiDTO {
/**
* Детальное сообщение об ошибке
*/
public $errorMessage;
public function __construct($json = null) {
parent::__construct($json);
}
}
class ApiNonUniqueError extends ApiDTO {
/**
* Детальное сообщение об ошибке
*/
public $errorMessage;
public function __construct($json = null) {
parent::__construct($json);
}
}
class ApiLimitError extends ApiDTO {
/**
* Детальное сообщение об ошибке
*/
public $errorMessage;
public function __construct($json = null) {
parent::__construct($json);
}
}
class ApiPaidFeatureError extends ApiDTO {
/**
* Детальное сообщение об ошибке
*/
public $errorMessage;
public function __construct($json = null) {
parent::__construct($json);
}
}
class ApiAuthError extends ApiDTO {
/**
* Детальное сообщение об ошибке
*/
public $errorMessage;
public function __construct($json = null) {
parent::__construct($json);
}
}
class ApiValidationError extends ApiDTO {
/**
* Детальное сообщение об ошибке
*/
public $errorMessage;
public function __construct($json = null) {
parent::__construct($json);
}
}
class ApiFileUploadError extends ApiDTO {
/**
* Детальное сообщение об ошибке
*/
public $errorMessage;
public function __construct($json = null) {
parent::__construct($json);
}
}
class ApiInternalError extends ApiDTO {
/**
* Детальное сообщение об ошибке
*/
public $errorMessage;
public function __construct($json = null) {
parent::__construct($json);
}
}
class ApiImportInProgressError extends ApiDTO {
/**
* Детальное сообщение об ошибке
*/
public $errorMessage;
public function __construct($json = null) {
parent::__construct($json);
}
}
class ApiRetryError extends ApiDTO {
/**
* Детальное сообщение об ошибке
*/
public $errorMessage;
public function __construct($json = null) {
parent::__construct($json);
}
}
class ApiEntityTooLongError extends ApiDTO {
/**
* Детальное сообщение об ошибке
*/
public $errorMessage;
public function __construct($json = null) {
parent::__construct($json);
}
}
class ApiUnprocessableImageError extends ApiDTO {
/**
* Детальное сообщение об ошибке
*/
public $errorMessage;
public function __construct($json = null) {
parent::__construct($json);
}
}
class ApiDeleteStatus extends ApiDTO {
/**
* Количество удаленных сущностей
*/
public $deleteCount;
public function __construct($json = null) {
parent::__construct($json);
}
}
class ApiUpdateStatus extends ApiDTO {
/**
* Количество обновленных сущностей
*/
public $updateCount;
public function __construct($json = null) {
parent::__construct($json);
}
}
class ApiCreateStatus extends ApiDTO {
/**
* Идентификатор созданной сущности
*/
public $id;
public function __construct($json = null) {
parent::__construct($json);
}
}
class ApiUploadStatus extends ApiDTO {
/**
* Айдишник залитого к нам файла
*/
public $id;
public function __construct($json = null) {
parent::__construct($json);
}
}
class ApiProduct extends ApiDTO {
/**
* A unique integer product ID.
*/
public $id;
/**
* Product SKU, that is, a unique code of the inventory item. Items with different options can have different SKUs, which are specified in the embedded Combination objects.
*/
public $sku;
/**
* An URL of the product thumbnail. The thumbnail size is specified in the store profile and may be different from the category thumbnail size. This is either an URL of an image uploaded to the /api/v2/STORE-ID/images or an URL of an external resource.
*/
public $thumbnailUrl;
/**
* Количество товара в стоке. Если количество товара неограничено(unlimited), то данного поля в ответе не будет.
*/
public $quantity;
/**
* "true", если количество товара не ограничено.
*/
public $unlimited;
/**
* True если товар есть на складе(количество товара или его комбинаций больше 0, либо если их количество не ограничено)
*/
public $inStock;
/**
* Product name as a plain text.
*/
public $name;
/**
* Basic product price.
*/
public $price;
/**
* The price shown in the product list, which may be different from the basic price if the default product combination overrides the basic price.
*/
public $priceInProductList;
/**
* The sorted array of (quantity limit, price) pairs.
* @var ApiWholesalePrice[]
*/
public $wholesalePrices;
/**
* 'Compare To' price shown strike-out in the customer frontend.
*/
public $compareToPrice;
/**
* Is shipping required for this product delivery
*/
public $isShippingRequired;
/**
* Product weight, in the store units. Absent for intangible products.
*/
public $weight;
/**
* URL of the product's description web page.
*/
public $url;
/**
* Product creation date/time.
*/
public $created;
/**
* Product last update date/time. Can be null for products that were created before this.
*/
public $updated;
/**
* Id of a product class this product belongs to (like 'Books'). Zero '0' value means 'General' class, which is the default for new products. Product classes have additional attributes you can see on the 'Attributes' tab in the product editor.
*/
public $productClassId;
/**
* 'true' if product is enabled, 'false' otherwise. Disabled products do not show in the customer frontend.
*/
public $enabled;
/**
* A list of the product options. Empty if no options are specified for the product.
* @var ApiProductOption[]
*/
public $options;
/**
* The value of the 'Send me a note when quantity in stock reaches' field.
*/
public $warningLimit;
/**
* True if the shipping is calculated as 'Fixed rate per item' (see Tax and Shipping / Shipping freight in the product editor). With this option on, global shipping settings do not affect the shipping rate of the item. The fixedShippingRate field is than specifies the shipping cost.
*/
public $fixedShippingRateOnly;
/**
* For fixedShippingRateOnly=true, this value is used instead of the shipping. For fixedShippingRateOnly=false, this value adds to the shipping cost.
*/
public $fixedShippingRate;
/**
* Id of a combination corresponding to the default product option values. E.g. if the default t-shirt color is 'white', and there is a separate combination for the white t-shirts, that combination is returned.
*/
public $defaultCombinationId;
/**
* An URL of a product image that must be shown to the user. If the original image is greater then 500x500 pixels, it is resized to make it smaller. The original image is always available under the originalImageUrl field of a Product. This is either an URL of an image uploaded to the /api/v2/STORE-ID/images or an URL of an external resource.
*/
public $imageUrl;
/**
* An URL of the product thumbnail fitted in the 80x80 box.
*/
public $smallThumbnailUrl;
/**
* An URL of an original product image that was uploaded for this product.
*/
public $originalImageUrl;
/**
* Product description in HTML.
*/
public $description;
/**
* A list of gallery images.
* @var ApiGalleryImage[]
*/
public $galleryImages;
/**
* A list of categories which this product belongs to.
*/
public $categoryIds;
/**
* Id of a category marked by a store owner as 'default' for this product. Default category shows up in a product page when no category id is given in the URL.
*/
public $defaultCategoryId;
/**
* Количество добавлений в избранное. Возвращается если фича favorites включена.
* @var ApiFavorites
*/
public $favorites;
/**
* If present, contains product's attributes values (see the description of object Attribute below). You can edit the attribute values on the 'Attributes' tab in the product editor.
* @var ApiAttributeValue[]
*/
public $attributes;
/**
* E-goods attached to the product. This field is only available for authorized requests.
* @var ApiProductFile[]
*/
public $files;
/**
* The configuration of related products, as shown in the 'Related Products' tab of the Product Editor.
* @var ApiRelatedProducts
*/
public $relatedProducts;
/**
* This can only be used when product retrieval. This field is absent on saving a product.
* @var ApiCombination[]
*/
public $combinations;
public function __construct($json = null) {
parent::__construct($json);
if (isset($this->wholesalePrices))
for ($i=0; $i < count($this->wholesalePrices); $i++)
if (isset($this->wholesalePrices[$i]))
$this->wholesalePrices[$i] = new ApiWholesalePrice($this->wholesalePrices[$i]);
if (isset($this->options))
for ($i=0; $i < count($this->options); $i++)
if (isset($this->options[$i]))
$this->options[$i] = new ApiProductOption($this->options[$i]);
if (isset($this->galleryImages))
for ($i=0; $i < count($this->galleryImages); $i++)
if (isset($this->galleryImages[$i]))
$this->galleryImages[$i] = new ApiGalleryImage($this->galleryImages[$i]);
if (isset($this->favorites))
$this->favorites = new ApiFavorites($this->favorites);
if (isset($this->attributes))
for ($i=0; $i < count($this->attributes); $i++)
if (isset($this->attributes[$i]))
$this->attributes[$i] = new ApiAttributeValue($this->attributes[$i]);
if (isset($this->files))
for ($i=0; $i < count($this->files); $i++)
if (isset($this->files[$i]))
$this->files[$i] = new ApiProductFile($this->files[$i]);
if (isset($this->relatedProducts))
$this->relatedProducts = new ApiRelatedProducts($this->relatedProducts);
if (isset($this->combinations))
for ($i=0; $i < count($this->combinations); $i++)
if (isset($this->combinations[$i]))
$this->combinations[$i] = new ApiCombination($this->combinations[$i]);
}
}
class ApiFavorites extends ApiDTO {
/**
* Количества добавлений в избранное числом как есть
*/
public $count;
/**
* Краткое текстовое представление количества добавлений в избранное. Например: 123, 4k, 5.3M
*/
public $displayedCount;
public function __construct($json = null) {
parent::__construct($json);
}
}
class ApiRelatedProducts extends ApiDTO {
/**
* IDs of the related products. May contain ids of removed products, in which case the removed ids should be disregarded.
*/
public $productIds;
/**
* Specifies the random number of related products from a given category.
* @var ApiRelatedCategory
*/
public $relatedCategory;
public function __construct($json = null) {
parent::__construct($json);
if (isset($this->relatedCategory))
$this->relatedCategory = new ApiRelatedCategory($this->relatedCategory);
}
}
class ApiRelatedCategory extends ApiDTO {
/**
* Флаг включенности выбора связанных товаров из категории
*/
public $enabled;
/**
* Id of a category whose products you wish to add as related products. Zero value means "any category", that is, just random products.
*/
public $categoryId;
/**
* Number of random products from a given category (or from all store, if categoryId==0), which should be shown as a related products of a given product.
*/
public $productCount;
public function __construct($json = null) {
parent::__construct($json);
}
}
class ApiWholesalePrice extends ApiDTO {
/**
* Number of items for which the special price is eligible.
*/
public $quantity;
/**
* Special price for the product when ordered more the 'quantity' items.
*/
public $price;
public function __construct($json = null) {
parent::__construct($json);
}
}
class ApiGalleryImage extends ApiDTO {
/**
* The image identificator
*/
public $id;
/**
* The image description, displayed in 'alt' image attribute, as a plain text.
*/
public $alt;
/**
* The image url.
*/
public $url;
/**
* An URL of the image thumbnail fit into the 46x42 box.
*/
public $thumbnail;
/**
* Width of the image.
*/
public $width;
/**
* Height of the image.
*/
public $height;
public function __construct($json = null) {
parent::__construct($json);
}
}
class ApiProductFile extends ApiDTO {
/**
* Unique integer file ID.
*/
public $id;
/**
* A plain-text file name.
*/
public $name;
/**
* A plain-text file description.
*/
public $description;
/**
* File size, in bytes, as a 64-bit integer.
*/
public $size;
/**
* Ссылка на egood, которой не касаются никакие лимиты. Отдавать эту ссылку кастомеру не стоит, ибо содержит токен для доступа в админку магазина
*/
public $adminUrl;
public function __construct($json = null) {
parent::__construct($json);
}
}
class ApiCombination extends ApiDTO {
/**
* A unique integer combination ID.
*/
public $id;
/**
* A positive integer number, unique to the product, shown in the combinations table in the
* product editor.
*/
public $combinationNumber;
/**
* Set of options which identifies this combination. An array of {name:, value:} objects.
* @var ApiOptionValue[]
*/
public $options;
/**
* If present, combination SKU, unique code. If null, product sku is assumed.
*/
public $sku;
/**
* An URL of the product combination thumbnail fitted in the 80x80 box. If null, product thumbnail is assumed.
*/
public $smallThumbnailUrl;
/**
* An URL of the product combination thumbnail. The thumbnail size is specified in the store profile and
* may be different from the category thumbnail size. If null, product thumbnail is assumed.
*/
public $thumbnailUrl;
/**
* An URL of a combination image that must be shown to the user. If the original image is greater
* then 500x500 pixels, it is resized to make it smaller. The original image is always available under the
* originalImageUrl field of a Product. If null, product image is assumed.
*/
public $imageUrl;
/**
* An URL of a non-resized combination image that was uploaded for this combination.
* If null, product image is assumed.
*/
public $originalImageUrl;
/**
* Количество товара данной комбинации на складе.
* Если значение товарных остатков для конкретной комбинации не задано, то возвращаться будет значение остатков исходного продукта.
* Если количество товара неограничено(unlimited), то данного поля в ответе не будет.
*/
public $quantity;
/**
* "true", если количество товара не ограничено.
*/
public $unlimited;
/**
* Price of the product having the specified option values. If null, basic product price is assumed.
*/
public $price;
/**
* The sorted array of (quantity limit, price) pairs. If null, no wholesale prices are assumed
* and 'price' field takes place.
* @var ApiWholesalePrice[]
*/
public $wholesalePrices;
/**
* True if the combination has its own weight that overrides the product's weight. False if the combination is intangible (no shipping required).
* Null if the weight should be inherited from the product.
*/
public $isShippingRequired;
/**
* Product weight, in the store units. If null, the weight is inherited from the product.
*/
public $weight;
/**
* The value of the 'Send me a note when quantity in stock reaches' field. If null, product's
* limit is used.
*/
public $warningLimit;
/**
* Specifies amount by which to increase the combination's inventory in stock (for PUT requests). Negative number decreases inventory.
*/
public $inventoryDelta;
public function __construct($json = null) {
parent::__construct($json);
if (isset($this->options))
for ($i=0; $i < count($this->options); $i++)
if (isset($this->options[$i]))
$this->options[$i] = new ApiOptionValue($this->options[$i]);
if (isset($this->wholesalePrices))
for ($i=0; $i < count($this->wholesalePrices); $i++)
if (isset($this->wholesalePrices[$i]))
$this->wholesalePrices[$i] = new ApiWholesalePrice($this->wholesalePrices[$i]);
}
}
class ApiOptionValue extends ApiDTO {
/**
* Option name, as in Product.options[i].name
*/
public $name;
/**
* Option value one of Product.options[i].choices[j].text
*/
public $value;
public function __construct($json = null) {
parent::__construct($json);
}
}
class ApiProductOption extends ApiDTO {
/**
* Тип продуктовой опции
*/
public $type;
/**
* Option name, like 'Color', as a plain text.
*/
public $name;
/**
* All possible option choices, if the type is 'SELECT', 'CHECKBOX' or 'RADIO'. Absent otherwise. Default is empty
* @var ApiProductOptionChoice[]
*/
public $choices;
/**