Skip to content

Commit

Permalink
1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrii-fediuk committed May 10, 2019
1 parent 04804bc commit faad4fe
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion T/Basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function t01_orders() {print_r(df_json_encode(df_oro_get_list(
function t02_orders_stripe() {
$customers = df_map_r(function(array $a) {return [
$a['id'], $a['country']
];}, df_oro_get_list('customers', [], [], true, false));
];}, df_oro_get_list('customers', [], [], true));
$websites = array_values(df_map(
df_sort_names(
array_filter(
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mage2pro/oro"
,"version": "1.0.3"
,"version": "1.1.0"
,"description": "Oro Platform integration with Magento 2"
,"type": "magento2-module"
,"homepage": "https://ocrm.pro"
Expand All @@ -11,6 +11,6 @@
"homepage": "https://mage2.pro/users/dmitry_fedyuk",
"role": "Developer"
}]
,"require": {"mage2pro/core": ">=2.12.21"}
,"require": {"mage2pro/core": ">=4.4.0"}
,"autoload": {"files": ["registration.php"], "psr-4": {"Df\\Oro\\": ""}}
}
20 changes: 11 additions & 9 deletions lib/main.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php
use Df\Core\Exception as DFE;
use Df\Oro\Settings\General as S;
use Zend_Http_Client as C;
/**
* 2017-06-04
* @used-by dfe_portal_stripe_customers()
* @param string $entity
* «How to apply a filter to a «get list» Web API request?» https://oplatform.club/t/103
* @param array(string => mixed) $filter [optional]
Expand All @@ -12,12 +14,10 @@
* @param bool $local [optional]
* «What is the difference between the «application/json» and «application/vnd.api+json»
* content types of a Web API response?» https://oplatform.club/t/104
* @param bool $vnd [optional]
* @return array(string => mixed)
* @throws DFE
*/
function df_oro_get_list(
$entity, array $filter = [], array $include = [], $local = false, $vnd = true
) {
function df_oro_get_list($entity, array $filter = [], array $include = [], $local = false) {
// 2017-06-28
// Due to a Oro Platform bug, a Web API request can randomly fail
// with the «Unauthorized» response message.
Expand All @@ -27,23 +27,25 @@ function df_oro_get_list(
$c = null; /** @var C $c */
while (!$raw && $attempt++ <= $maxAttempts) {
$c = df_zf_http('https://'
. ($local ? 'localhost.com:848/app_dev.php' : 'erp.mage2.pro')
. ($local ? 'localhost.com:848/index_dev.php' : 'erp.mage2.pro')
. "/api/extenddf$entity"
)
// 2017-06-28
// Due to a Oro Platform bug, the «content-type» headers is required for the «vnd» case,
// even it does not have any sense here.
// «Difference between the Accept and Content-Type HTTP headers»
// https://webmasters.stackexchange.com/questions/31212
->setHeaders(df_oro_headers() + (!$vnd ? ['accept' => 'application/json'] : array_fill_keys(
->setHeaders(df_oro_headers() + (array_fill_keys(
['accept', 'content-type'], 'application/vnd.api+json'
)))
->setParameterGet(df_clean(['filter' => $filter, 'include' => df_csv($include)]))
->setParameterGet(df_clean([
'filter' => $filter, 'include' => df_csv($include), 'page' => ['size' => -1]
]))
;
$raw = $c->request()->getBody();
}
if (!$raw) {
$res = $c->getLastResponse(); /** @var \Zend_Http_Response $res */
$res = $c->getLastResponse(); /** @var \Zend_Http_Response $res */
if (!$raw || $res->isError()) {
df_error("The last Oro Web API request fails with the message «{$res->getMessage()}».\n"
."The response headers:\n%s\n.The request:\n%s\n."
,$res->getHeadersAsString(), $c->getLastRequest()
Expand Down

0 comments on commit faad4fe

Please sign in to comment.