Skip to content

Commit

Permalink
Remove dependence on Magento Framework Curl (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyfromspace authored Jun 18, 2018
1 parent 321f6eb commit f0bc1ba
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM alexcheng/magento2:2.2.2-integrator
FROM alexcheng/magento2:2.1-developer

ADD . app/code/Kustomer/KustomerIntegration

Expand Down
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
### Kustomer Integration for Magento Update History

#### 1.1.3

- Remove use of `\Magento\Framework\HTTP\Client\Curl`

#### 1.1.2

- Minor internal changes that should have no functional impact
Expand Down
44 changes: 26 additions & 18 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Magento\Quote\Model\Quote\Address as QuoteAddress;
use Magento\Store\Model\Store;
use Magento\Store\Model\ScopeInterface;
use Magento\Framework\HTTP\Client\Curl;
use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Store\Model\StoreManagerInterface;

Expand All @@ -35,24 +34,21 @@ class Data extends AbstractHelper
public $storeManagerInterface;
public $quoteRepository;
public $pricingHelper;
public $curl;
public $logger;

public function __construct(
Context $context,
StoreManagerInterface $storeManagerInterface,
CustomerRepositoryInterface $customerRepository,
QuoteRepository $quoteRepository,
PricingHelper $pricingHelper,
Curl $curl
PricingHelper $pricingHelper
)
{
parent::__construct($context);
$this->quoteRepository = $quoteRepository;
$this->pricingHelper = $pricingHelper;
$this->storeManagerInterface = $storeManagerInterface;
$this->customerRepository = $customerRepository;
$this->curl = $curl;
$this->logger = $context->getLogger();
}

Expand Down Expand Up @@ -350,25 +346,37 @@ public function request($uri, $body = null, $store = null)
{
$authToken = $this->getKustomerApiKey($store);
$headers = array(
'Authorization' => 'Bearer '.$authToken,
'User-Agent' => self::USER_AGENT.self::VERSION,
'Accept' => self::ACCEPT_HEADER,
'Content-Type' => self::CONTENT_TYPE,
'Authorization: Bearer '.$authToken,
'User-Agent: '.self::USER_AGENT.self::VERSION,
'Accept: '.self::ACCEPT_HEADER,
'Content-Type: '.self::CONTENT_TYPE,
);

$this->curl->setHeaders($headers);
try {
$this->curl->post($uri, $body);
} catch (\Exception $e) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 3000);

// $this->curl->setHeaders($headers);
$res = curl_exec($ch);
$e = curl_error($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$bodyMessage = substr($res, $header_size);

if ($e)
{
return [
'success' => false,
'error' => $e->getCode().': '.$e->getMessage()
'success' => false,
'error' => $e,
];
}

$statusCode = $this->curl->getStatus();
$bodyMessage = $this->curl->getBody();

if ($statusCode >= 400)
{
return [
Expand Down
10 changes: 0 additions & 10 deletions Test/Unit/Helper/DataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ class DataTest extends \PHPUnit\Framework\TestCase
*/
protected $pricingHelper;

/**
* @var \Magento\Framework\HTTP\Client\Curl | \PHPUnit_Framework_MockObject_MockObject
*/
protected $curl;

/**
* @var \Psr\Log\LoggerInterface | \PHPUnit_Framework_MockObject_MockObject
*/
Expand Down Expand Up @@ -74,10 +69,6 @@ protected function setUp()
->disableOriginalConstructor()
->getMock();

$this->curl = $this->getMockBuilder(\Magento\Framework\HTTP\Client\Curl::class)
->disableOriginalConstructor()
->getMock();

$this->logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)
->disableOriginalConstructor()
->getMock();
Expand All @@ -88,7 +79,6 @@ protected function setUp()
$this->customerRepository,
$this->quoteRepository,
$this->pricingHelper,
$this->curl,
$this->logger
);
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "kustomer/kustomer-integration",
"description": "Integrate Magento eCommerce site with Kustomer service",
"type": "magento2-module",
"version": "1.1.2",
"version": "1.1.3",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Kustomer_KustomerIntegration" setup_version="1.1.2">
<module name="Kustomer_KustomerIntegration" setup_version="1.1.3">
<sequence>
<module name="Magento_Store"/>
</sequence>
Expand Down

0 comments on commit f0bc1ba

Please sign in to comment.