Skip to content

Commit efecadd

Browse files
Merge pull request #10 from searchspring/personalization-response-format-change
Personalization response format change
2 parents faf3839 + 62a7a92 commit efecadd

23 files changed

Lines changed: 659 additions & 34 deletions
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace SearchSpring\Feed\Api\Data;
4+
5+
interface CustomersDataInterface
6+
{
7+
/**
8+
* @return string
9+
*/
10+
public function getId(): string;
11+
12+
/**
13+
* @return string
14+
*/
15+
public function getEmail(): string;
16+
17+
/**
18+
* @param string $value
19+
* @return null
20+
*/
21+
public function setId(string $value);
22+
23+
/**
24+
* @param string $value
25+
* @return null
26+
*/
27+
public function setEmail(string $value);
28+
}

Api/Data/CustomersInterface.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace SearchSpring\Feed\Api\Data;
4+
5+
interface CustomersInterface
6+
{
7+
/**
8+
* @return \SearchSpring\Feed\Api\Data\CustomersDataInterface[]
9+
*/
10+
public function getCustomers(): array;
11+
12+
/**
13+
* @param $value \SearchSpring\Feed\Api\Data\CustomersDataInterface[]
14+
* @return null
15+
*/
16+
public function setCustomers(array $value);
17+
}

Api/Data/SalesDataInterface.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace SearchSpring\Feed\Api\Data;
4+
5+
interface SalesDataInterface
6+
{
7+
/**
8+
* @return string
9+
*/
10+
public function getOrderId(): string;
11+
12+
/**
13+
* @return string
14+
*/
15+
public function getCustomerId(): string;
16+
17+
/**
18+
* @return string
19+
*/
20+
public function getProductId(): string;
21+
22+
/**
23+
* @return string
24+
*/
25+
public function getQuantity(): string;
26+
27+
/**
28+
* @return string
29+
* @return null
30+
*/
31+
public function getCreatedAt(): string;
32+
33+
/**
34+
* @param string $value
35+
* @return null
36+
*/
37+
public function setOrderId(string $value);
38+
39+
/**
40+
* @param string $value
41+
* @return null
42+
*/
43+
public function setCustomerId(string $value);
44+
45+
/**
46+
* @param string $value
47+
* @return null
48+
*/
49+
public function setProductId(string $value);
50+
51+
/**
52+
* @param string $value
53+
* @return null
54+
*/
55+
public function setQuantity(string $value);
56+
57+
/**
58+
* @param string $value
59+
* @return null
60+
*/
61+
public function setCreatedAt(string $value);
62+
}

Api/Data/SalesInterface.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace SearchSpring\Feed\Api\Data;
4+
5+
interface SalesInterface
6+
{
7+
/**
8+
* @return \SearchSpring\Feed\Api\Data\SalesDataInterface[]
9+
*/
10+
public function getSales(): array;
11+
12+
/**
13+
* @param $value \SearchSpring\Feed\Api\Data\SalesDataInterface[]
14+
* @return null
15+
*/
16+
public function setSales(array $value);
17+
}

Api/GetApplicationLogInterface.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* Copyright (C) 2023 Searchspring <https://searchspring.com>
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, version 3 of the License.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
17+
declare(strict_types=1);
18+
19+
namespace SearchSpring\Feed\Api;
20+
21+
use Magento\Framework\Api\SearchCriteriaInterface;
22+
use Magento\Framework\Exception\CouldNotDeleteException;
23+
use Magento\Framework\Exception\CouldNotSaveException;
24+
use Magento\Framework\Exception\LocalizedException;
25+
use Magento\Framework\Exception\NoSuchEntityException;
26+
use SearchSpring\Feed\Api\Data\CustomerResultsInterface;
27+
28+
interface GetApplicationLogInterface
29+
{
30+
/**
31+
* @param bool $compressOutput
32+
*
33+
* @return string
34+
*
35+
* @throws LocalizedException
36+
*/
37+
public function getExtensionLog(bool $compressOutput = false) : string;
38+
39+
/**
40+
* @return bool
41+
*
42+
* @throws LocalizedException
43+
*/
44+
public function clearExtensionLog() : bool;
45+
46+
/**
47+
* @param bool $compressOutput
48+
*
49+
* @return string
50+
*
51+
* @throws LocalizedException
52+
*/
53+
public function getExceptionLog(bool $compressOutput = false) : string;
54+
55+
/**
56+
* @return bool
57+
*
58+
* @throws LocalizedException
59+
*/
60+
public function clearExceptionLog() : bool;
61+
}

Api/GetCustomersInterface.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@
1919
namespace SearchSpring\Feed\Api;
2020

2121
use Magento\Framework\Exception\LocalizedException;
22+
use SearchSpring\Feed\Api\Data\CustomersInterface;
2223

2324
interface GetCustomersInterface
2425
{
2526
/**
2627
* @param string $dateRange
2728
* @param string $rowRange
2829
*
29-
* @return array
30+
* @return CustomersInterface
3031
*
3132
* @throws LocalizedException
3233
*/
33-
public function getList(string $dateRange = "All", string $rowRange = "All");
34+
public function getList(string $dateRange = "All", string $rowRange = "All"): CustomersInterface;
3435
}

Api/GetSalesInterface.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,17 @@
2424
use Magento\Framework\Exception\LocalizedException;
2525
use Magento\Framework\Exception\NoSuchEntityException;
2626
use SearchSpring\Feed\Api\Data\CustomerResultsInterface;
27+
use SearchSpring\Feed\Api\Data\SalesInterface;
2728

2829
interface GetSalesInterface
2930
{
3031
/**
3132
* @param string $dateRange
3233
* @param string $rowRange
3334
*
34-
* @return array
35+
* @return SalesInterface
3536
*
3637
* @throws LocalizedException
3738
*/
38-
public function getList(string $dateRange = "All", string $rowRange = "All");
39+
public function getList(string $dateRange = "All", string $rowRange = "All"): SalesInterface;
3940
}

Helper/Customer.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,28 @@
1111
namespace SearchSpring\Feed\Helper;
1212

1313
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory;
14+
use SearchSpring\Feed\Api\Data\CustomersDataInterface;
15+
use SearchSpring\Feed\Api\Data\CustomersDataInterfaceFactory;
1416
use Magento\Framework\App\Helper\AbstractHelper;
1517

1618
class Customer extends AbstractHelper
1719
{
1820
protected $customerFactory;
21+
protected $customersDataFactory;
1922

20-
public function __construct(CollectionFactory $customerFactory)
23+
public function __construct(CollectionFactory $customerFactory, CustomersDataInterfaceFactory $customersDataFactory)
2124
{
2225
$this->customerFactory = $customerFactory;
26+
$this->customersDataFactory = $customersDataFactory;
2327
}
2428

25-
public function getCustomers(string $dateRangeStr, string $rowRangeStr)
29+
/**
30+
* @param string $dateRangeStr
31+
* @param string $rowRangeStr
32+
*
33+
* @return CustomersDataInterface[]
34+
*/
35+
public function getCustomers(string $dateRangeStr, string $rowRangeStr): array
2636
{
2737
$result = [];
2838
$customerCollection = $this->customerFactory->create();
@@ -58,12 +68,14 @@ public function getCustomers(string $dateRangeStr, string $rowRangeStr)
5868

5969
$items = $customerCollection->getItems(); // Make query
6070
foreach ($items as $item) {
61-
$result[] = [
62-
'id' => $item->getId(),
63-
'email' => $item->getEmail()
64-
];
71+
$customersData = $this->customersDataFactory->create();
72+
73+
$customersData->setId($item->getId());
74+
$customersData->setEmail($item->getEmail());
75+
76+
$result[] = $customersData;
6577
}
6678

67-
return ['customers' => $result];
79+
return $result;
6880
}
6981
}

Helper/LogInfo.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
/**
3+
* Helper to fetch version data.
4+
*
5+
* This file is part of SearchSpring/Feed.
6+
*
7+
* For the full copyright and license information, please view the LICENSE.txt
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace SearchSpring\Feed\Helper;
12+
13+
use Magento\Framework\App\Helper\AbstractHelper;
14+
use Magento\Framework\App\ObjectManager;
15+
16+
class LogInfo extends AbstractHelper
17+
{
18+
public function __construct()
19+
{
20+
}
21+
22+
public function deleteExtensionLogFile() : bool
23+
{
24+
$objectManager = ObjectManager::getInstance();
25+
$directory = $objectManager->get('\Magento\Framework\Filesystem\DirectoryList');
26+
$logPath = $directory->getPath('log');
27+
$logFile = $logPath . '/searchspring_feed.log';
28+
29+
if (file_exists($logFile)) {
30+
unlink($logFile);
31+
}
32+
33+
return true;
34+
}
35+
36+
public function getExtensionLogFile(bool $compressOutput = false) : string
37+
{
38+
$result = '';
39+
40+
$objectManager = ObjectManager::getInstance();
41+
$directory = $objectManager->get('\Magento\Framework\Filesystem\DirectoryList');
42+
$logPath = $directory->getPath('log');
43+
$logFile = $logPath . '/searchspring_feed.log';
44+
45+
if (file_exists($logFile)) {
46+
$result = file_get_contents($logFile);
47+
48+
if (strlen($result) > 0 and $compressOutput){
49+
$result = rtrim(strtr(base64_encode(gzdeflate($result, 9)), '+/', '-_'), '=');
50+
}
51+
}
52+
53+
return $result;
54+
}
55+
56+
public function deleteExceptionLogFile() : bool
57+
{
58+
$objectManager = ObjectManager::getInstance();
59+
$directory = $objectManager->get('\Magento\Framework\Filesystem\DirectoryList');
60+
$logPath = $directory->getPath('log');
61+
$logFile = $logPath . '/exception.log';
62+
63+
if (file_exists($logFile)) {
64+
unlink($logFile);
65+
}
66+
67+
return true;
68+
}
69+
70+
public function getExceptionLogFile(bool $compressOutput = false) : string
71+
{
72+
$result = '';
73+
74+
$objectManager = ObjectManager::getInstance();
75+
$directory = $objectManager->get('\Magento\Framework\Filesystem\DirectoryList');
76+
$logPath = $directory->getPath('log');
77+
$logFile = $logPath . '/exception.log';
78+
79+
if (file_exists($logFile)) {
80+
$result = file_get_contents($logFile);
81+
82+
if (strlen($result) > 0 and $compressOutput){
83+
$result = rtrim(strtr(base64_encode(gzdeflate($result, 9)), '+/', '-_'), '=');
84+
}
85+
}
86+
87+
return $result;
88+
}
89+
}

0 commit comments

Comments
 (0)