Skip to content

Commit

Permalink
release Drip Connect 2.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
diegodrip committed Nov 24, 2024
1 parent f246b7d commit ac98b74
Show file tree
Hide file tree
Showing 22 changed files with 277 additions and 148 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
/vendor
/htdocs
node_modules
devtools_m2/vendor
devtools_m2/devbox.d
19 changes: 9 additions & 10 deletions Api/ProductDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class ProductDetails
protected $responseFactory;

/**
* @var \Magento\ConfigurableProduct\Model\Product\Type\Configurable
*/
* @var \Magento\ConfigurableProduct\Model\Product\Type\Configurable
*/
protected $configurable;

public function __construct(
Expand Down Expand Up @@ -56,11 +56,10 @@ public function showDetails($productId)
$productImage = $product->getImage();
if (!empty($productImage)) {
$productImage = $this->catalogProductMediaConfigFactory->create()->getMediaUrl($productImage);
}
else {
if ($product->getTypeId() != 'configurable'){
} else {
if ($product->getTypeId() != 'configurable') {
$parentProductId = $this->getParentId($productId);
if ($parentProductId){
if ($parentProductId) {
$parentProduct = $this->catalogProductFactory->create()->load($parentProductId);
$productImage = $parentProduct->getImage();
if (!empty($productImage)) {
Expand All @@ -84,9 +83,9 @@ public function showDetails($productId)
private function getParentId($childId)
{
$parentConfigObject = $this->configurable->getParentIdsByChild($childId);
if($parentConfigObject) {
return $parentConfigObject[0];
}
return false;
if ($parentConfigObject) {
return $parentConfigObject[0];
}
return false;
}
}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

* Add changelog here.

## 2.0.7

* Switch to Laminas HTTP Client: Replaced the existing HTTP client with Laminas for better compatibility and maintainability.
* Code Style and Deprecation Fixes: Applied PHP code style improvements and resolved deprecation warnings to align with modern PHP standards.
* Security Enhancement: Updated security settings to allow JavaScript loading from Drip while maintaining application security.

## 2.0.6

* In extension's endpoint (drip/product/:id) fetch configurable product image url when child products don't have one assigned
Expand Down
61 changes: 41 additions & 20 deletions Model/ApiCalls/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@

namespace Drip\Connect\Model\ApiCalls;

use \Drip\Connect\Model\Restapi\RestapiAbstract;
use Drip\Connect\Logger\Logger;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Config\Storage\WriterInterface;
use Magento\Framework\ArchiveFactory;
use Magento\Framework\Filesystem\DirectoryList;
use Magento\Store\Model\StoreManagerInterface;
use Drip\Connect\Model\Http\ClientFactory;
use Drip\Connect\Model\Configuration;
use Laminas\Http\Response;
use Laminas\Http\Client\Exception\ExceptionInterface;

/**
* Restapi base class
Expand All @@ -11,16 +20,16 @@ class Base extends RestapiAbstract
{

/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
* @var ScopeConfigInterface
*/
protected $scopeConfig;

/**
* @var \Drip\Connect\Model\Http\ClientFactory
* @var ClientFactory
*/
protected $connectHttpClientFactory;

/** @var \Magento\Store\Model\StoreManagerInterface */
/** @var StoreManagerInterface */
protected $storeManager;

/**
Expand All @@ -37,14 +46,14 @@ class Base extends RestapiAbstract
* @param String $v3 API version
*/
public function __construct(
\Drip\Connect\Logger\Logger $logger,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Framework\App\Config\Storage\WriterInterface $configWriter,
\Magento\Framework\ArchiveFactory $archiveFactory,
\Magento\Framework\Filesystem\DirectoryList $directory,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Drip\Connect\Model\Http\ClientFactory $connectHttpClientFactory,
\Drip\Connect\Model\Configuration $config,
Logger $logger,
ScopeConfigInterface $scopeConfig,
WriterInterface $configWriter,
ArchiveFactory $archiveFactory,
DirectoryList $directory,
StoreManagerInterface $storeManager,
ClientFactory $connectHttpClientFactory,
Configuration $config,
$endpoint,
$v3 = false
) {
Expand All @@ -55,17 +64,17 @@ public function __construct(
$archiveFactory,
$directory
);
/*
/*
* Since the Drip extension is sending data through the WooBase class
* we are clearing this to prevent issues in other parts of the codebase.
* we are clearing this to prevent issues in other parts of the codebase.
*/
}

/**
* Call the API
*
* @param \Drip\Connect\Model\Restapi\Request $request
* @throws \Zend_Http_Client_Exception
* @throws ExceptionInterface
*/
protected function _callApi($request)
{
Expand All @@ -76,39 +85,51 @@ protected function _callApi($request)
$this->_httpClient->setParameterPost($request->getParametersPost());
}
if (!empty($request->getRawData())) {
$this->_httpClient->setRawData($request->getRawData());
$this->_httpClient->setRawBody($request->getRawData());
}

$response = $this->_httpClient->request($request->getMethod());

$this->_lastRequestUrl = $this->_httpClient->getUri();
$this->_lastRequest = $this->_httpClient->getLastRequest();
$this->_lastRequest = $this->_httpClient->getRequest();

return $response;
}

protected function _forceValidResponse($request)
{
return new \Zend_Http_Response(200, ["Content-type" => "application/json; charset=utf-8"], json_encode([
$response = new Response();
$response->setStatusCode(200);
$response->getHeaders()->addHeaderLine("Content-Type", "application/json; charset=utf-8");
$response->setContent(json_encode([
"Status" => "OK",
"Message" => "Forced Valid Response"
]));
return $response;
}

protected function _forceInvalidResponse($request)
{
return new \Zend_Http_Response(200, ["Content-type" => "application/json; charset=utf-8"], json_encode([
$response = new Response();
$response->setStatusCode(200);
$response->getHeaders()->addHeaderLine("Content-Type", "application/json; charset=utf-8");
$response->setContent(json_encode([
"Status" => "OK",
"Message" => "Forced Invalid Response"
]));
return $response;
}

protected function _forceError($request)
{
return new \Zend_Http_Response(500, ["Content-type" => "application/json; charset=utf-8"], json_encode([
$response = new Response();
$response->setStatusCode(500);
$response->getHeaders()->addHeaderLine("Content-Type", "application/json; charset=utf-8");
$response->setContent(json_encode([
"Status" => "Error",
"Message" => "Forced Error Message"
]));
return $response;
}

/**
Expand Down
13 changes: 9 additions & 4 deletions Model/ApiCalls/Helper/CreateUpdateSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@

namespace Drip\Connect\Model\ApiCalls\Helper;

use \Drip\Connect\Model\ApiCalls\BaseFactory;
use \Drip\Connect\Model\ApiCalls\Request\BaseFactory as RequestBaseFactory;
use \Drip\Connect\Model\Configuration;
use \Laminas\Http\Request;

/**
* Create or update a subscriber.
*/
class CreateUpdateSubscriber extends \Drip\Connect\Model\ApiCalls\Helper
{
public function __construct(
\Drip\Connect\Model\ApiCalls\BaseFactory $connectApiCallsBaseFactory,
\Drip\Connect\Model\ApiCalls\Request\BaseFactory $connectApiCallsRequestBaseFactory,
\Drip\Connect\Model\Configuration $config,
BaseFactory $connectApiCallsBaseFactory,
RequestBaseFactory $connectApiCallsRequestBaseFactory,
Configuration $config,
$data = []
) {
$this->apiClient = $connectApiCallsBaseFactory->create([
Expand All @@ -25,7 +30,7 @@ public function __construct(
];

$this->request = $connectApiCallsRequestBaseFactory->create()
->setMethod(\Zend_Http_Client::POST)
->setMethod(Request::METHOD_POST)
->setRawData(json_encode($subscribersInfo));
}
}
18 changes: 13 additions & 5 deletions Model/ApiCalls/Helper/GetProjectList.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,25 @@

namespace Drip\Connect\Model\ApiCalls\Helper;

use Drip\Connect\Model\ApiCalls\BaseFactory;
use Drip\Connect\Model\ApiCalls\Request\BaseFactory as RequestBaseFactory;
use Drip\Connect\Model\Configuration;
use Laminas\Http\Request;

/**
* Get project list helper
*
* @todo This class doesn't seem to be called from anywhere. Confirm that it is dead.
*/
class GetProjectList extends \Drip\Connect\Model\ApiCalls\Helper
class GetProjectList extends Helper
{
protected $apiClient;
protected $request;

public function __construct(
\Drip\Connect\Model\ApiCalls\BaseFactory $connectApiCallsBaseFactory,
\Drip\Connect\Model\ApiCalls\Request\BaseFactory $connectApiCallsRequestBaseFactory,
\Drip\Connect\Model\Configuration $config,
BaseFactory $connectApiCallsBaseFactory,
RequestBaseFactory $connectApiCallsRequestBaseFactory,
Configuration $config,
$data = []
) {
$this->apiClient = $connectApiCallsBaseFactory->create([
Expand All @@ -21,6 +29,6 @@ public function __construct(
]);

$this->request = $connectApiCallsRequestBaseFactory->create()
->setMethod(\Zend_Http_Client::GET);
->setMethod(Request::METHOD_GET);
}
}
16 changes: 12 additions & 4 deletions Model/ApiCalls/Helper/GetSubscriberList.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,25 @@

namespace Drip\Connect\Model\ApiCalls\Helper;

use Drip\Connect\Model\ApiCalls\BaseFactory;
use Drip\Connect\Model\ApiCalls\Request\BaseFactory as RequestBaseFactory;
use Drip\Connect\Model\Configuration;
use Laminas\Http\Request;

/**
* Get the subscriber list
*
* @todo This class doesn't seem to be called from anywhere. Confirm that it is dead.
*/
class GetSubscriberList extends \Drip\Connect\Model\ApiCalls\Helper
{
protected $apiClient;
protected $request;

public function __construct(
\Drip\Connect\Model\ApiCalls\BaseFactory $connectApiCallsBaseFactory,
\Drip\Connect\Model\ApiCalls\Request\BaseFactory $connectApiCallsRequestBaseFactory,
\Drip\Connect\Model\Configuration $config,
BaseFactory $connectApiCallsBaseFactory,
RequestBaseFactory $connectApiCallsRequestBaseFactory,
Configuration $config,
$data = []
) {
$data = array_merge([
Expand All @@ -30,7 +38,7 @@ public function __construct(
]);

$this->request = $connectApiCallsRequestBaseFactory->create()
->setMethod(\Zend_Http_Client::GET)
->setMethod(Request::METHOD_GET)
->setParametersGet([
'status' => $data['status'],
'tags' => $data['tags'],
Expand Down
16 changes: 11 additions & 5 deletions Model/ApiCalls/Helper/RecordAnEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

namespace Drip\Connect\Model\ApiCalls\Helper;

use Drip\Connect\Model\ApiCalls\BaseFactory;
use Drip\Connect\Model\ApiCalls\Request\BaseFactory as RequestBaseFactory;
use Drip\Connect\Helper\Data;
use Drip\Connect\Model\Configuration;
use Laminas\Http\Request;

/**
* Record a subscriber event
*/
Expand All @@ -19,10 +25,10 @@ class RecordAnEvent extends \Drip\Connect\Model\ApiCalls\Helper
const EVENT_WISHLIST_REMOVE_PRODUCT = 'Removed item from wishlist';

public function __construct(
\Drip\Connect\Model\ApiCalls\BaseFactory $connectApiCallsBaseFactory,
\Drip\Connect\Model\ApiCalls\Request\BaseFactory $connectApiCallsRequestBaseFactory,
\Drip\Connect\Helper\Data $connectHelper,
\Drip\Connect\Model\Configuration $config,
BaseFactory $connectApiCallsBaseFactory,
RequestBaseFactory $connectApiCallsRequestBaseFactory,
Data $connectHelper,
Configuration $config,
array $data
) {
$this->apiClient = $connectApiCallsBaseFactory->create([
Expand All @@ -43,7 +49,7 @@ public function __construct(
];

$this->request = $connectApiCallsRequestBaseFactory->create()
->setMethod(\Zend_Http_Client::POST)
->setMethod(Request::METHOD_POST)
->setRawData(json_encode($eventsInfo));
}
}
18 changes: 12 additions & 6 deletions Model/ApiCalls/Helper/SendEventPayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@

namespace Drip\Connect\Model\ApiCalls\Helper;

use Drip\Connect\Model\ApiCalls\WooBaseFactory;
use Drip\Connect\Model\ApiCalls\Request\BaseFactory;
use Drip\Connect\Model\Configuration;
use Laminas\Http\Request;

/**
* Send payload for events
*/
class SendEventPayload extends \Drip\Connect\Model\ApiCalls\Helper
{
/** @var \Drip\Connect\Model\Configuration */
/** @var Configuration */
protected $config;

public function __construct(
\Drip\Connect\Model\ApiCalls\WooBaseFactory $connectApiCallsWooBaseFactory,
\Drip\Connect\Model\ApiCalls\Request\BaseFactory $connectApiCallsRequestBaseFactory,
\Drip\Connect\Model\Configuration $config,
WooBaseFactory $connectApiCallsWooBaseFactory,
BaseFactory $connectApiCallsRequestBaseFactory,
Configuration $config,
array $payload
) {
$this->config = $config;
Expand All @@ -24,7 +29,7 @@ public function __construct(
]);

$this->request = $connectApiCallsRequestBaseFactory->create()
->setMethod(\Zend_Http_Client::POST)
->setMethod(Request::METHOD_POST)
->setRawData(json_encode($payload));
}

Expand All @@ -33,11 +38,12 @@ private function integrationUrl()
$accountId = $this->config->getAccountParam();
$integrationParam = $this->config->getIntegrationToken();
$endpoint = "https://external-production.woo.drip.sh";
# $endpoint = "https://external-staging.woo.drip.sh";

if ($this->config->getTestMode()) {
$endpoint = "http://mock:1080";
}

return "${endpoint}/${accountId}/integrations/${integrationParam}/events";
return "{$endpoint}/{$accountId}/integrations/{$integrationParam}/events";
}
}
Loading

0 comments on commit ac98b74

Please sign in to comment.