These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | $settings = require_once '../settings.php'; |
||
3 | use Yandex\Market\Partner\PartnerClient; |
||
4 | use Yandex\Common\Exception\ForbiddenException; |
||
5 | |||
6 | $errorMessage = false; |
||
7 | |||
8 | // Is auth |
||
9 | if (isset($_COOKIE['yaAccessToken']) && isset($_COOKIE['yaClientId'])) { |
||
10 | $market = new PartnerClient($_COOKIE['yaAccessToken']); |
||
11 | $market->setClientId($_COOKIE['yaClientId']); |
||
12 | $market->setLogin($settings['global']['marketLogin']); |
||
13 | |||
14 | try { |
||
15 | $campaigns = $market->getCampaigns(); |
||
16 | } catch (ForbiddenException $ex) { |
||
17 | $errorMessage = $ex->getMessage(); |
||
18 | $errorMessage .= '<p>Возможно, у приложения нет прав на доступ к ресурсу. Попробуйте ' |
||
19 | . '<a href="' . rtrim(str_replace($_SERVER['DOCUMENT_ROOT'], '', __DIR__), "/") . "/../OAuth/" . '">авторизироваться</a> и повторить.</p>'; |
||
20 | |||
21 | } catch (Exception $ex) { |
||
22 | $errorMessage = $ex->getMessage(); |
||
23 | } |
||
24 | } |
||
25 | ?> |
||
26 | <!doctype html> |
||
27 | <html lang="en-US"> |
||
28 | <head> |
||
29 | <meta charset="UTF-8"> |
||
30 | <title>Yandex PHP Library: Market Demo</title> |
||
31 | <link rel="stylesheet" href="//yandex.st/bootstrap/3.0.0/css/bootstrap.min.css"> |
||
32 | <link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet"> |
||
33 | <link rel="stylesheet" href="/examples/Disk/css/style.css"> |
||
34 | </head> |
||
35 | <body> |
||
36 | <div class="container"> |
||
37 | <div class="jumbotron"> |
||
38 | <h2><span class="glyphicon glyphicon-shopping-cart"></span> Пример работы с Яндекс Маркетом</h2> |
||
39 | </div> |
||
40 | <ol class="breadcrumb"> |
||
41 | <li><a href="/examples">Examples</a></li> |
||
42 | <li class="active">Market</li> |
||
43 | </ol> |
||
44 | <?php |
||
45 | if (!isset($_COOKIE['yaAccessToken']) || !isset($_COOKIE['yaClientId'])) : |
||
46 | ?> |
||
47 | <div class="alert alert-info"> |
||
48 | Для просмотра этой страници вам необходимо авторизироваться. |
||
49 | <a id="goToAuth" href="<?php echo rtrim(str_replace($_SERVER['DOCUMENT_ROOT'], '', __DIR__), "/") . '/../OAuth/'?>" class="alert-link">Перейти на страницу авторизации</a>. |
||
50 | </div> |
||
51 | <?php |
||
52 | elseif ($errorMessage) : |
||
0 ignored issues
–
show
|
|||
53 | ?> |
||
54 | <div class="alert alert-danger"> |
||
55 | <?= $errorMessage ?> |
||
56 | </div> |
||
57 | <?php |
||
58 | elseif (isset($market, $campaigns)) : |
||
59 | ?> |
||
60 | <div class="col-md-8"> |
||
61 | <h2>Кампании пользователя</h2> |
||
62 | <h3>Запрос:</h3> |
||
63 | <p> |
||
64 | <a href="http://api.yandex.ru/market/partner/doc/dg/reference/get-campaigns.xml"> |
||
65 | GET /campaigns |
||
66 | </a> |
||
67 | </p> |
||
68 | |||
69 | <h3>Ответ:</h3> |
||
70 | <?php |
||
71 | /** @var \Yandex\Market\Models\Campaign $campaign */ |
||
72 | if ($campaigns instanceof Traversable) { |
||
73 | |||
74 | $params = [ |
||
75 | 'status' => null, |
||
76 | 'fromDate' => null, |
||
77 | 'toDate' => null, |
||
78 | 'pageSize' => 50, |
||
79 | 'page' => 1 |
||
80 | ]; |
||
81 | |||
82 | $campaignId = $campaigns->current()->getId(); |
||
83 | $market->setCampaignId($campaignId); |
||
84 | $orders = $market->getOrders($params); |
||
85 | |||
86 | foreach ($campaigns as $campaign) { |
||
87 | echo '<pre>'; |
||
88 | print_r($campaign->toArray()); |
||
89 | echo '</pre>'; |
||
90 | } |
||
91 | } |
||
92 | ?> |
||
93 | |||
94 | <h2>Информация о запрашиваемых заказах</h2> |
||
95 | <h3>Запрос:</h3> |
||
96 | <p> |
||
97 | <a href="http://api.yandex.ru/market/partner/doc/dg/reference/get-campaigns-id-orders.xml"> |
||
98 | GET /campaigns/{campaignId}/orders |
||
99 | </a> |
||
100 | </p> |
||
101 | |||
102 | <h3>Ответ:</h3> |
||
103 | <div class="panel-group" id="accordion"> |
||
104 | <div class="panel panel-default"> |
||
105 | <div class="panel-heading"> |
||
106 | <h4 class="panel-title"> |
||
107 | <a data-toggle="collapse" data-parent="#accordion" href="#collapseOrdersLinks"> |
||
108 | Список заказов с ссылками на их просмотр |
||
109 | </a> |
||
110 | </h4> |
||
111 | </div> |
||
112 | <div id="collapseOrdersLinks" class="panel-collapse collapse in"> |
||
113 | <div class="panel-body"> |
||
114 | <?php |
||
115 | if ($orders instanceof Traversable) { |
||
116 | /** @var Yandex\Market\Models\Order $order */ |
||
117 | foreach ($orders as $order) { |
||
118 | ?> |
||
119 | <p> |
||
120 | <a href="view-order.php?orderId=<?= $order->getId(); |
||
121 | ?>&campaignId=<?= $campaignId ?>">Заказ №<?= $order->getId() ?></a> |
||
122 | </p> |
||
123 | <?php |
||
124 | } |
||
125 | } |
||
126 | ?> |
||
127 | </div> |
||
128 | </div> |
||
129 | </div> |
||
130 | <div class="panel panel-default"> |
||
131 | <div class="panel-heading"> |
||
132 | <h4 class="panel-title"> |
||
133 | <a data-toggle="collapse" data-parent="#accordion" href="#collapseAllResponse"> |
||
134 | Полный ответ Заказов |
||
135 | </a> |
||
136 | </h4> |
||
137 | </div> |
||
138 | <div id="collapseAllResponse" class="panel-collapse collapse"> |
||
139 | <div class="panel-body"> |
||
140 | <pre><?php |
||
141 | foreach ($orders as $order) { |
||
0 ignored issues
–
show
The expression
$orders of type object<Yandex\Market\Partner\Models\Orders>|null is not guaranteed to be traversable. How about adding an additional type check?
There are different options of fixing this problem.
Loading history...
|
|||
142 | echo '<pre>'; |
||
143 | print_r($order->toArray()); |
||
144 | echo '</pre>'; |
||
145 | } |
||
146 | ?></pre> |
||
147 | </div> |
||
148 | </div> |
||
149 | </div> |
||
150 | </div> |
||
151 | <?php |
||
152 | endif; |
||
153 | ?> |
||
154 | </div> |
||
155 | <script src="http://yandex.st/jquery/2.0.3/jquery.min.js"></script> |
||
156 | <script src="http://yandex.st/jquery/cookie/1.0/jquery.cookie.min.js"></script> |
||
157 | <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> |
||
158 | <script> |
||
159 | $(function () { |
||
160 | $('#goToAuth').click(function (e) { |
||
161 | $.cookie('back', location.href, { expires: 256, path: '/' }); |
||
162 | }); |
||
163 | }); |
||
164 | </script> |
||
165 | </body> |
||
166 | </html> |
||
167 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: