Skip to content

Commit

Permalink
PLUGINRANGERS-24 | Point update on save to Dooplugins (#293)
Browse files Browse the repository at this point in the history
* feat: point update on save to Dooplugins

* feat: modified Magento update on save paths
  • Loading branch information
davidmolinacano committed Nov 13, 2023
1 parent aab03f6 commit 95c704e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
7 changes: 7 additions & 0 deletions ApiClient/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class Client
/** Search API type */
public const SEARCH_API = 'search';

/** Dooplugins type */
public const DOOPLUGINS = 'dooplugins';

/** @var StoreConfig */
private $storeConfig;

Expand Down Expand Up @@ -270,6 +273,10 @@ private function setApiTokenRegion(?string $apiKey)
*/
private function getApiBaseURL(): string
{
if ($this->apiType === self::DOOPLUGINS)
{
return sprintf("https://%s-plugins.doofinder.com", $this->clusterRegion);
}
return sprintf("https://%s-%s.doofinder.com", $this->clusterRegion, $this->apiType);
}

Expand Down
8 changes: 4 additions & 4 deletions ApiClient/ManagementClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class ManagementClient
{
private const ENDPOINT_SEARCH_ENGINES = '/api/v2/search_engines';
private const ENDPOINT_UPDATE_ON_SAVE = '/plugins/magento2';
private const ENDPOINT_UPDATE_ON_SAVE = '/item';

/** @var Client */
private $client;
Expand Down Expand Up @@ -166,7 +166,7 @@ public function getSearchEngine(string $hashid): array
*/
public function createItemsInBulk(array $items, string $hashId, string $indice)
{
$path = self::ENDPOINT_UPDATE_ON_SAVE . "/{$hashId}/$indice/product_create";
$path = self::ENDPOINT_UPDATE_ON_SAVE . "/{$hashId}/$indice?action=create&platform=magento2";
$response = $this->client->post($path, $items);

return json_decode($response, true);
Expand All @@ -191,7 +191,7 @@ public function createItemsInBulk(array $items, string $hashId, string $indice)
*/
public function updateItemsInBulk(array $items, string $hashId, string $indice)
{
$path = self::ENDPOINT_UPDATE_ON_SAVE . "/{$hashId}/$indice/product_update";
$path = self::ENDPOINT_UPDATE_ON_SAVE . "/{$hashId}/$indice?action=update&platform=magento2";
$response = $this->client->post($path, $items);

return json_decode($response, true);
Expand All @@ -217,7 +217,7 @@ public function updateItemsInBulk(array $items, string $hashId, string $indice)
*/
public function deleteItemsInBulk(array $items, string $hashId, string $indice)
{
$path = self::ENDPOINT_UPDATE_ON_SAVE . "/{$hashId}/$indice/product_delete";
$path = self::ENDPOINT_UPDATE_ON_SAVE . "/{$hashId}/$indice?action=delete&platform=magento2";
$response = $this->client->delete($path, $items);

return json_decode($response, true);
Expand Down
3 changes: 2 additions & 1 deletion Helper/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Doofinder\Feed\Helper;

use Doofinder\Feed\Api\Data\ChangedItemInterface;
use Doofinder\Feed\ApiClient\Client;
use Doofinder\Feed\ApiClient\ManagementClientFactory;
use Doofinder\Feed\Errors\BadRequest;
use Doofinder\Feed\Errors\IndexingInProgress;
Expand Down Expand Up @@ -155,7 +156,7 @@ private function processItemsInBulk(array $items, StoreInterface $store, string
$hashId = $searchEngine['hashid'];
$this->validateIndice($searchEngine, $indice);
$managementClient = $this->throttleFactory->create([
'obj' => $this->managementClientFactory->create(['apiType' => 'admin']),
'obj' => $this->managementClientFactory->create(['apiType' => Client::DOOPLUGINS]),
]);

switch ($type) {
Expand Down

0 comments on commit 95c704e

Please sign in to comment.