Skip to content

Commit

Permalink
Merge pull request #10 from searchspring/personalization-response-for…
Browse files Browse the repository at this point in the history
…mat-change

Personalization response format change
  • Loading branch information
maheshganjalagunte authored Sep 11, 2023
2 parents faf3839 + 62a7a92 commit efecadd
Show file tree
Hide file tree
Showing 23 changed files with 659 additions and 34 deletions.
28 changes: 28 additions & 0 deletions Api/Data/CustomersDataInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace SearchSpring\Feed\Api\Data;

interface CustomersDataInterface
{
/**
* @return string
*/
public function getId(): string;

/**
* @return string
*/
public function getEmail(): string;

/**
* @param string $value
* @return null
*/
public function setId(string $value);

/**
* @param string $value
* @return null
*/
public function setEmail(string $value);
}
17 changes: 17 additions & 0 deletions Api/Data/CustomersInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace SearchSpring\Feed\Api\Data;

interface CustomersInterface
{
/**
* @return \SearchSpring\Feed\Api\Data\CustomersDataInterface[]
*/
public function getCustomers(): array;

/**
* @param $value \SearchSpring\Feed\Api\Data\CustomersDataInterface[]
* @return null
*/
public function setCustomers(array $value);
}
62 changes: 62 additions & 0 deletions Api/Data/SalesDataInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace SearchSpring\Feed\Api\Data;

interface SalesDataInterface
{
/**
* @return string
*/
public function getOrderId(): string;

/**
* @return string
*/
public function getCustomerId(): string;

/**
* @return string
*/
public function getProductId(): string;

/**
* @return string
*/
public function getQuantity(): string;

/**
* @return string
* @return null
*/
public function getCreatedAt(): string;

/**
* @param string $value
* @return null
*/
public function setOrderId(string $value);

/**
* @param string $value
* @return null
*/
public function setCustomerId(string $value);

/**
* @param string $value
* @return null
*/
public function setProductId(string $value);

/**
* @param string $value
* @return null
*/
public function setQuantity(string $value);

/**
* @param string $value
* @return null
*/
public function setCreatedAt(string $value);
}
17 changes: 17 additions & 0 deletions Api/Data/SalesInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace SearchSpring\Feed\Api\Data;

interface SalesInterface
{
/**
* @return \SearchSpring\Feed\Api\Data\SalesDataInterface[]
*/
public function getSales(): array;

/**
* @param $value \SearchSpring\Feed\Api\Data\SalesDataInterface[]
* @return null
*/
public function setSales(array $value);
}
61 changes: 61 additions & 0 deletions Api/GetApplicationLogInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* Copyright (C) 2023 Searchspring <https://searchspring.com>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

declare(strict_types=1);

namespace SearchSpring\Feed\Api;

use Magento\Framework\Api\SearchCriteriaInterface;
use Magento\Framework\Exception\CouldNotDeleteException;
use Magento\Framework\Exception\CouldNotSaveException;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use SearchSpring\Feed\Api\Data\CustomerResultsInterface;

interface GetApplicationLogInterface
{
/**
* @param bool $compressOutput
*
* @return string
*
* @throws LocalizedException
*/
public function getExtensionLog(bool $compressOutput = false) : string;

/**
* @return bool
*
* @throws LocalizedException
*/
public function clearExtensionLog() : bool;

/**
* @param bool $compressOutput
*
* @return string
*
* @throws LocalizedException
*/
public function getExceptionLog(bool $compressOutput = false) : string;

/**
* @return bool
*
* @throws LocalizedException
*/
public function clearExceptionLog() : bool;
}
5 changes: 3 additions & 2 deletions Api/GetCustomersInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@
namespace SearchSpring\Feed\Api;

use Magento\Framework\Exception\LocalizedException;
use SearchSpring\Feed\Api\Data\CustomersInterface;

interface GetCustomersInterface
{
/**
* @param string $dateRange
* @param string $rowRange
*
* @return array
* @return CustomersInterface
*
* @throws LocalizedException
*/
public function getList(string $dateRange = "All", string $rowRange = "All");
public function getList(string $dateRange = "All", string $rowRange = "All"): CustomersInterface;
}
5 changes: 3 additions & 2 deletions Api/GetSalesInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use SearchSpring\Feed\Api\Data\CustomerResultsInterface;
use SearchSpring\Feed\Api\Data\SalesInterface;

interface GetSalesInterface
{
/**
* @param string $dateRange
* @param string $rowRange
*
* @return array
* @return SalesInterface
*
* @throws LocalizedException
*/
public function getList(string $dateRange = "All", string $rowRange = "All");
public function getList(string $dateRange = "All", string $rowRange = "All"): SalesInterface;
}
26 changes: 19 additions & 7 deletions Helper/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,28 @@
namespace SearchSpring\Feed\Helper;

use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory;
use SearchSpring\Feed\Api\Data\CustomersDataInterface;
use SearchSpring\Feed\Api\Data\CustomersDataInterfaceFactory;
use Magento\Framework\App\Helper\AbstractHelper;

class Customer extends AbstractHelper
{
protected $customerFactory;
protected $customersDataFactory;

public function __construct(CollectionFactory $customerFactory)
public function __construct(CollectionFactory $customerFactory, CustomersDataInterfaceFactory $customersDataFactory)
{
$this->customerFactory = $customerFactory;
$this->customersDataFactory = $customersDataFactory;
}

public function getCustomers(string $dateRangeStr, string $rowRangeStr)
/**
* @param string $dateRangeStr
* @param string $rowRangeStr
*
* @return CustomersDataInterface[]
*/
public function getCustomers(string $dateRangeStr, string $rowRangeStr): array
{
$result = [];
$customerCollection = $this->customerFactory->create();
Expand Down Expand Up @@ -58,12 +68,14 @@ public function getCustomers(string $dateRangeStr, string $rowRangeStr)

$items = $customerCollection->getItems(); // Make query
foreach ($items as $item) {
$result[] = [
'id' => $item->getId(),
'email' => $item->getEmail()
];
$customersData = $this->customersDataFactory->create();

$customersData->setId($item->getId());
$customersData->setEmail($item->getEmail());

$result[] = $customersData;
}

return ['customers' => $result];
return $result;
}
}
89 changes: 89 additions & 0 deletions Helper/LogInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/**
* Helper to fetch version data.
*
* This file is part of SearchSpring/Feed.
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

namespace SearchSpring\Feed\Helper;

use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\ObjectManager;

class LogInfo extends AbstractHelper
{
public function __construct()
{
}

public function deleteExtensionLogFile() : bool
{
$objectManager = ObjectManager::getInstance();
$directory = $objectManager->get('\Magento\Framework\Filesystem\DirectoryList');
$logPath = $directory->getPath('log');
$logFile = $logPath . '/searchspring_feed.log';

if (file_exists($logFile)) {
unlink($logFile);
}

return true;
}

public function getExtensionLogFile(bool $compressOutput = false) : string
{
$result = '';

$objectManager = ObjectManager::getInstance();
$directory = $objectManager->get('\Magento\Framework\Filesystem\DirectoryList');
$logPath = $directory->getPath('log');
$logFile = $logPath . '/searchspring_feed.log';

if (file_exists($logFile)) {
$result = file_get_contents($logFile);

if (strlen($result) > 0 and $compressOutput){
$result = rtrim(strtr(base64_encode(gzdeflate($result, 9)), '+/', '-_'), '=');
}
}

return $result;
}

public function deleteExceptionLogFile() : bool
{
$objectManager = ObjectManager::getInstance();
$directory = $objectManager->get('\Magento\Framework\Filesystem\DirectoryList');
$logPath = $directory->getPath('log');
$logFile = $logPath . '/exception.log';

if (file_exists($logFile)) {
unlink($logFile);
}

return true;
}

public function getExceptionLogFile(bool $compressOutput = false) : string
{
$result = '';

$objectManager = ObjectManager::getInstance();
$directory = $objectManager->get('\Magento\Framework\Filesystem\DirectoryList');
$logPath = $directory->getPath('log');
$logFile = $logPath . '/exception.log';

if (file_exists($logFile)) {
$result = file_get_contents($logFile);

if (strlen($result) > 0 and $compressOutput){
$result = rtrim(strtr(base64_encode(gzdeflate($result, 9)), '+/', '-_'), '=');
}
}

return $result;
}
}
Loading

0 comments on commit efecadd

Please sign in to comment.