{"id":232603,"date":"2014-08-07T17:30:04","date_gmt":"2014-08-07T13:30:04","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=232603"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=232603","title":{"rendered":"<span class=\"post_title\">Magento \u0448\u0430\u0433 \u0437\u0430 \u0448\u0430\u0433\u043e\u043c: REST API<\/span>"},"content":{"rendered":"<div class=\"content html_format\">     \t\u0412 <a href=\"http:\/\/habrahabr.ru\/post\/230957\/\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u00ab\u0441\u043a\u0435\u043b\u0435\u0442\u0430\u00bb \u0434\u043b\u044f \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0430 \u0437\u0430\u043a\u0430\u0437\u043e\u0432. \u0412 \u044d\u0442\u043e\u0439 \u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u0438\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0430\u043a\u043e\u0433\u043e \u0436\u0435 \u0441\u043a\u0435\u043b\u0435\u0442\u0430, \u043d\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u0447\u0435\u0440\u0435\u0437 REST API.<\/p>\n<p>  \u0421 \u0412\u0438\u043a\u0438: REST (\u0441\u043e\u043a\u0440. \u043e\u0442 \u0430\u043d\u0433\u043b. Representational State Transfer \u2014 \u00ab\u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0440\u0435\u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0430\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u00bb) \u2014 \u0432 \u0431\u043e\u043b\u0435\u0435 \u0443\u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u043c \u0443\u0437\u043a\u043e\u043c \u0441\u043c\u044b\u0441\u043b\u0435 \u043f\u043e\u0434 REST \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 \u0441\u0435\u0442\u0438 \u0418\u043d\u0442\u0435\u0440\u043d\u0435\u0442, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0432\u044b\u0437\u043e\u0432 \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 HTTP-\u0437\u0430\u043f\u0440\u043e\u0441 (\u043e\u0431\u044b\u0447\u043d\u043e GET \u0438\u043b\u0438 POST; \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 REST-\u0437\u0430\u043f\u0440\u043e\u0441), \u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u042d\u0442\u043e\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043e\u0439 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u0430\u043c, \u0442\u0430\u043a\u0438\u043c \u043a\u0430\u043a SOAP, CORBA \u0438 RPC.<br \/>  <a name=\"habracut\"><\/a><\/p>\n<p>  \u041f\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u043c\u0443 htaccess Magento, \u0432\u0441\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u043e\u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \/api\/ \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043d\u0430 api.php:  <\/p>\n<pre><code class=\"apache\">RewriteRule ^api\/([a-z][0-9a-z_]+)\/?$ api.php?type=$1 [QSA,L]  <\/code><\/pre>\n<p>  \u041f\u043e\u0447\u0435\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u0441\u0442\u043e\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 API? \u041f\u043e\u043c\u0438\u043c\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u0443\u0436\u0435 \u0432\u0441\u0435 \u0433\u043e\u0442\u043e\u0432\u043e, API-\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u044e\u0442\u0441\u044f \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430 (Mage::app()-&gt;getStore()-&gt;isAdmin() === true), \u0447\u0442\u043e \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442 \u043a\u0430\u043a \u044f\u0437\u044b\u043a\u043e\u0432\u0443\u044e \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u0434\u043b\u044f EAV-\u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432, \u0442\u0430\u043a \u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0438\u0437 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 frontend.<br \/>  \u0417\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e REST \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b api2.xml \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 etc \u043c\u043e\u0434\u0443\u043b\u044f, \u043d\u043e\u0434\u0430 <b>api2<\/b>.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0435\u0449\u0435 \u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u043e\u043c.<br \/>  \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0444\u043e\u0440\u043c\u0430\u0442 \u0432\u0432\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a\u043e\u0432:  <\/p>\n<pre><code class=\"xml\">&lt;orders&gt;   &lt;order&gt;     &lt;id&gt;145000003&lt;\/id&gt;     &lt;shipment&gt;      &lt;tracking&gt;uiwq12889124&lt;\/tracking&gt;      &lt;items&gt;       &lt;item&gt;         &lt;sku&gt;21&lt;\/sku&gt;         &lt;qty&gt;1&lt;\/qty&gt;       &lt;\/item&gt;      &lt;\/items&gt;     &lt;\/shipment&gt;   &lt;\/order&gt;   &lt;order&gt;     &lt;id&gt;145000003ZZZ&lt;\/id&gt;     &lt;shipment&gt;      &lt;tracking&gt;uiwq128zzz89124&lt;\/tracking&gt;      &lt;items&gt;       &lt;item&gt;         &lt;sku&gt;21&lt;\/sku&gt;         &lt;qty&gt;1&lt;\/qty&gt;       &lt;\/item&gt;      &lt;\/items&gt;     &lt;\/shipment&gt;   &lt;\/order&gt; &lt;\/orders&gt; <\/code><\/pre>\n<p>  \u0412 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043e\u0434\u0438\u043d \u0437\u0430\u043a\u0430\u0437 \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u043c, \u0432\u0442\u043e\u0440\u043e\u0439 \u2014 \u043d\u0435\u0442.<\/p>\n<p>  <b>app\/code\/local\/Easy\/Interfacing\/etc\/api2.xml<\/b>  <\/p>\n<pre><code class=\"xml\">&lt;?xml version=&quot;1.0&quot;?&gt; &lt;config&gt;     &lt;api2&gt;         &lt;resource_groups&gt;             &lt;easy_interfacing translate=&quot;title&quot; module=&quot;api2&quot;&gt;                 &lt;title&gt;Easy Interfacing REST&lt;\/title&gt;                 &lt;sort_order&gt;30&lt;\/sort_order&gt;                 &lt;children&gt;                     &lt;easy_interfacing_orders translate=&quot;title&quot; module=&quot;api2&quot;&gt;                         &lt;title&gt;Orders&lt;\/title&gt;                         &lt;sort_order&gt;50&lt;\/sort_order&gt;                     &lt;\/easy_interfacing_orders&gt;                 &lt;\/children&gt;             &lt;\/easy_interfacing&gt;         &lt;\/resource_groups&gt;         &lt;resources&gt;             &lt;easy_interfacing_orders translate=&quot;title&quot; module=&quot;api2&quot;&gt;                 &lt;group&gt;easy_interfacing&lt;\/group&gt;                 &lt;model&gt;easy_interfacing\/api2_order&lt;\/model&gt;                 &lt;filter&gt;easy_interfacing\/api2_order_filter&lt;\/filter&gt;                 &lt;title&gt;Orders&lt;\/title&gt;                 &lt;sort_order&gt;10&lt;\/sort_order&gt;                 &lt;versions&gt;1&lt;\/versions&gt;                 &lt;routes&gt;                     &lt;route_collection&gt;                         &lt;route&gt;\/easy_interfacing\/order&lt;\/route&gt;                         &lt;action_type&gt;collection&lt;\/action_type&gt;                     &lt;\/route_collection&gt;                 &lt;\/routes&gt;                 &lt;privileges&gt;                     &lt;guest&gt;                         &lt;update&gt;1&lt;\/update&gt;                     &lt;\/guest&gt;                 &lt;\/privileges&gt;                 &lt;attributes translate=&quot;id shipment&quot; module=&quot;easy_interfacing&quot;&gt;                     &lt;id&gt;Order ID&lt;\/id&gt;                     &lt;shipment&gt;Shipment data&lt;\/shipment&gt;                 &lt;\/attributes&gt;             &lt;\/easy_interfacing_orders&gt;         &lt;\/resources&gt;     &lt;\/api2&gt; &lt;\/config&gt; <\/code><\/pre>\n<p>  \u041d\u043e\u0434\u0430 <b>resource_groups<\/b> \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 ACL \u0432 <b>System &gt; Web Services &gt; REST Roles<\/b>. \u0412 \u0441\u0430\u043c\u0438\u0445 \u0436\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u0445 REST API \u043c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0433\u0440\u0443\u043f\u043f\u0443 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u0438 easy_interfacing \u0438 \u043c\u043e\u0434\u0435\u043b\u044c api2_order, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u0437\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b.<br \/>  \u041f\u0443\u0442\u044c \u043a \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0443 \u0443\u043a\u0430\u0430\u0437\u043d \u0432 route_collection, \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u0435\u0441\u0442\u0438\u0441\u044c \u043d\u0430 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 (action_type = route_collection). \u0412 \u043d\u0430\u0448\u0435\u043c REST API \u043c\u044b \u0432\u0441\u0435 \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0430 \u0433\u043e\u0441\u0442\u0435\u0432\u043e\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u0435, \u0447\u0442\u043e\u0431 \u043d\u0435 \u043c\u0443\u0447\u0430\u0442\u044c\u0441\u044f \u0441 \u043f\u0430\u0440\u043e\u043b\u044f\u043c\u0438 \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f: \u0432 \u043a\u043e\u0434\u0435 \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0431\u0443\u0434\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u0430.<br \/>  \u041d\u043e\u0434\u0430 <b>attributes<\/b> \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 ACL \u0444\u0438\u043b\u044c\u0442\u0440 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 (Mage_Api2_Model_Acl_Filter). \u0422\u0430\u043a \u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0444\u043e\u0440\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0441\u043f\u0438\u0441\u043a\u0430 \u0432 \u043d\u043e\u0434\u0443 forced_attributes. \u0412\u0441\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 api2.xml \u043b\u044e\u0431\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0435\u0433\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0438\u043c\u043f\u043e\u0440\u0442\/\u044d\u043a\u0441\u043f\u043e\u0440\u0442 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, Mage_Sales \u0438\u043b\u0438 Mage_Catalog.<\/p>\n<p>  \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432\u0441\u0435 \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432\u0430\u043c\u0438, \u0447\u0442\u043e \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u0434 \u043d\u0430\u0448 \u0444\u043e\u0440\u043c\u0430\u0442 (shipment \u2014 \u043c\u0430\u0441\u0441\u0438\u0432), \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0444\u0438\u043b\u044c\u0442\u0440, \u0433\u0434\u0435 \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u043c \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 Mage_Api2_Model_Acl_Filter::collectionIn:<\/p>\n<p>  <b>app\/code\/local\/Easy\/Interfacing\/Model\/Api2\/Order\/Filter.php<\/b>  <\/p>\n<pre><code class=\"php\">class Easy_Interfacing_Model_Api2_Order_Filter extends Mage_Api2_Model_Acl_Filter {     public function collectionIn($items)     {         $nodeName = key($items);         if (!is_numeric(key($items[$nodeName]))) {             $items[$nodeName] = array($items[$nodeName]);         }         if (is_array($items[$nodeName])) {             foreach ($items[$nodeName] as &$item) {                 $item = $this-&gt;in($item);             }         }         return $items[$nodeName];     }  } <\/code><\/pre>\n<p>  \u041d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c ACL \u0434\u043e\u0441\u0442\u0443\u043f\u044b \u0432 <b>System &gt; Web services &gt; REST \u2014 Roles<\/b>:<br \/>  <img decoding=\"async\" src=\"\/\/habrastorage.org\/files\/ec3\/ac0\/098\/ec3ac009876c4b3b9bc266b0026b244b.png\"\/><br \/>  \u0438 \u0432 <b>System &gt; Web services &gt; REST \u2014 Attributes<\/b>:<br \/>  <img decoding=\"async\" src=\"\/\/habrastorage.org\/files\/84e\/c04\/714\/84ec047148ae4af287e63d02577e5e0c.png\"\/><\/p>\n<p>  \u0418, \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0430\u043c \u043a\u043b\u0430\u0441\u0441 API:<br \/>  <b>app\/code\/local\/Easy\/Interfacing\/Model\/Api2\/Order.php<\/b>  <\/p>\n<pre><code class=\"php\">class Easy_Interfacing_Model_Api2_Order extends Mage_Api2_Model_Resource {     const RESULT_ERROR_NOT_FOUND = 404;     const RESULT_ERROR_IMPORT = 500;     const RESULT_SUCCESS = 200;     protected $_responseItems = array();          protected function _addResult(array $item, $errorCode, $errorMessage)     {         $result = array('result' =&gt; $errorCode, 'id' =&gt; $item['id']);         if ($errorMessage) {             $result['error'] = $errorMessage;         }         $this-&gt;_responseItems[] = $result;     } } <\/code><\/pre>\n<p>  \u0412 \u043d\u0435\u043c \u043d\u0430\u043c \u043e\u0441\u043e\u0431\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043d\u0443\u0436\u043d\u043e, \u0442\u043e\u043b\u044c\u043a\u043e _addResult \u0438 \u043f\u0430\u0440\u0430 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442 \u043a\u043e\u0434\u043e\u0432 \u043e\u0448\u0438\u0431\u043e\u043a. \u0422\u0430\u043a \u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c REST-\u043a\u043b\u0430\u0441\u0441, \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043e\u0442 \u044d\u0442\u043e\u0433\u043e:<br \/>  <b>app\/code\/local\/Easy\/Interfacing\/Model\/Api2\/Order\/Rest.php<\/b>  <\/p>\n<pre><code class=\"php\">class Easy_Interfacing_Model_Api2_Order_Rest extends Easy_Interfacing_Model_Api2_Order {     public function dispatch()     {         $this-&gt;_filter = Mage::getModel('easy_interfacing\/api2_order_filter', $this);         parent::dispatch();         $this-&gt;_render($this-&gt;_responseItems);     }      protected function _multiUpdate(array $filteredData)     {         foreach ($filteredData as $item) {             $order = Mage::getModel('sales\/order')-&gt;loadByIncrementId($item['id']);             \/* @var $order Mage_Sales_Model_Order *\/             if (!$order-&gt;getId()) {                 $this-&gt;_addResult($item, self::RESULT_ERROR_NOT_FOUND);                 continue;             }             try {                 Mage::getSingleton('easy_interfacing\/order')-&gt;import($order, $item);                 $this-&gt;_addResult($item, self::RESULT_SUCCESS);             } catch (Exception $ex) {                 $order-&gt;addStatusHistoryComment('Failed importing order: ' . $ex-&gt;getMessage())-&gt;save();                 $this-&gt;_addResult($item, self::RESULT_ERROR_IMPORT, $ex-&gt;getMessage());             }         }     } } <\/code><\/pre>\n<p>  \u0412 \u043d\u0435\u043c \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043c\u0435\u0442\u043e\u0434 dispatch, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0434\u043c\u0435\u043d\u0438\u0442\u044c \u0444\u0438\u043b\u044c\u0442\u0440 \u043d\u0430 \u043d\u0430\u0448 \u0438 \u0441\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e Magento \u0432\u044b\u0434\u0430\u0441\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043a\u0440\u0438\u0432\u043e\u0439 \u043e\u0442\u0432\u0435\u0442, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0438\u0437 getResponse().<br \/>  \u0422\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u0438 action_type=collection, \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043c\u0435\u0442\u043e\u0434 _multiUpdate. \u0412 $filteredData \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0443\u0436\u0435 \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 (\u0435\u0441\u043b\u0438 \u0438\u0437 ACL \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u0443\u0431\u0440\u0430\u0442\u044c ID, \u0442\u043e Easy_Interfacing_Model_Order::import \u0431\u0440\u043e\u0441\u0438\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u043a\u0440\u044d\u0448\u043d\u0435\u0442\u0441\u044f).<br \/>  <b>app\/code\/local\/Easy\/Interfacing\/Model\/Api2\/Order\/Rest\/Guest\/V1.php<\/b>  <\/p>\n<pre><code class=\"php\">class Easy_Interfacing_Model_Api2_Order_Rest_Guest_V1 extends Easy_Interfacing_Model_Api2_Order_Rest  {      } <\/code><\/pre>\n<p>  Guest-\u043a\u043b\u0430\u0441\u0441 API \u0442\u0430\u043a \u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c, \u0442.\u043a. \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d \u043f\u0440\u0438 \u0433\u043e\u0441\u0442\u0435\u0432\u043e\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u0435 \u043a REST.<br \/>  \u0412 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435, \u0435\u0441\u043b\u0438 \u0412\u044b \u0432\u0441\u0435 \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u043f\u0440\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043d\u0430 http:\/\/\/api\/rest\/easy_interfacing\/order\/ \u043c\u0435\u0442\u043e\u0434\u043e\u043c PUT \u0447\u0435\u0440\u0435\u0437 \u043b\u044e\u0431\u043e\u0439 REST-\u043a\u043b\u0438\u0435\u043d\u0442 \u0432\u0432\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435, \u043f\u0440\u0438\u0434\u0435\u0442 \u043e\u0442\u0432\u0435\u0442 \u0432\u0438\u0434\u0430:  <\/p>\n<pre><code class=\"xml\">&lt;?xml version=&quot;1.0&quot; ?&gt;  &lt;magento_api&gt;  &lt;data_item&gt; &lt;result&gt;500&lt;\/result&gt; &lt;id&gt;145000003&lt;\/id&gt; &lt;error&gt;Not implemented&lt;\/error&gt;  &lt;\/data_item&gt;  &lt;data_item&gt; &lt;result&gt;404&lt;\/result&gt; &lt;id&gt;14501100003&lt;\/id&gt;  &lt;\/data_item&gt;  &lt;\/magento_api&gt; <\/code><\/pre>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/232603\/\"> http:\/\/habrahabr.ru\/post\/232603\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">     \t\u0412 <a href=\"http:\/\/habrahabr.ru\/post\/230957\/\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u00ab\u0441\u043a\u0435\u043b\u0435\u0442\u0430\u00bb \u0434\u043b\u044f \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0430 \u0437\u0430\u043a\u0430\u0437\u043e\u0432. \u0412 \u044d\u0442\u043e\u0439 \u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u0438\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0430\u043a\u043e\u0433\u043e \u0436\u0435 \u0441\u043a\u0435\u043b\u0435\u0442\u0430, \u043d\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u0447\u0435\u0440\u0435\u0437 REST API.<\/p>\n<p>  \u0421 \u0412\u0438\u043a\u0438: REST (\u0441\u043e\u043a\u0440. \u043e\u0442 \u0430\u043d\u0433\u043b. Representational State Transfer \u2014 \u00ab\u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0440\u0435\u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0430\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u00bb) \u2014 \u0432 \u0431\u043e\u043b\u0435\u0435 \u0443\u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u043c \u0443\u0437\u043a\u043e\u043c \u0441\u043c\u044b\u0441\u043b\u0435 \u043f\u043e\u0434 REST \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 \u0441\u0435\u0442\u0438 \u0418\u043d\u0442\u0435\u0440\u043d\u0435\u0442, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0432\u044b\u0437\u043e\u0432 \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 HTTP-\u0437\u0430\u043f\u0440\u043e\u0441 (\u043e\u0431\u044b\u0447\u043d\u043e GET \u0438\u043b\u0438 POST; \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 REST-\u0437\u0430\u043f\u0440\u043e\u0441), \u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u042d\u0442\u043e\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043e\u0439 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u0430\u043c, \u0442\u0430\u043a\u0438\u043c \u043a\u0430\u043a SOAP, CORBA \u0438 RPC.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-232603","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/232603","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=232603"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/232603\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=232603"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=232603"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=232603"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}