diff --git a/Api/Data/CustomersDataInterface.php b/Api/Data/CustomersDataInterface.php
new file mode 100644
index 0000000..7ba6ac1
--- /dev/null
+++ b/Api/Data/CustomersDataInterface.php
@@ -0,0 +1,28 @@
+
+ * 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 .
+ */
+
+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;
+}
diff --git a/Api/GetCustomersInterface.php b/Api/GetCustomersInterface.php
index 0fccd9c..f72b7dd 100644
--- a/Api/GetCustomersInterface.php
+++ b/Api/GetCustomersInterface.php
@@ -19,6 +19,7 @@
namespace SearchSpring\Feed\Api;
use Magento\Framework\Exception\LocalizedException;
+use SearchSpring\Feed\Api\Data\CustomersInterface;
interface GetCustomersInterface
{
@@ -26,9 +27,9 @@ 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;
}
diff --git a/Api/GetSalesInterface.php b/Api/GetSalesInterface.php
index 1e58dd6..044d63f 100644
--- a/Api/GetSalesInterface.php
+++ b/Api/GetSalesInterface.php
@@ -24,6 +24,7 @@
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use SearchSpring\Feed\Api\Data\CustomerResultsInterface;
+use SearchSpring\Feed\Api\Data\SalesInterface;
interface GetSalesInterface
{
@@ -31,9 +32,9 @@ 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;
}
diff --git a/Helper/Customer.php b/Helper/Customer.php
index 38139a0..abc7a3e 100755
--- a/Helper/Customer.php
+++ b/Helper/Customer.php
@@ -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();
@@ -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;
}
}
diff --git a/Helper/LogInfo.php b/Helper/LogInfo.php
new file mode 100644
index 0000000..37a567d
--- /dev/null
+++ b/Helper/LogInfo.php
@@ -0,0 +1,89 @@
+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;
+ }
+}
diff --git a/Helper/Sale.php b/Helper/Sale.php
index a100152..a129638 100644
--- a/Helper/Sale.php
+++ b/Helper/Sale.php
@@ -15,20 +15,30 @@
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Store\Model\StoresConfig;
use Magento\Sales\Model\ResourceModel\Order\Item\CollectionFactory;
+use SearchSpring\Feed\Api\Data\SalesDataInterface;
+use SearchSpring\Feed\Api\Data\SalesDataInterfaceFactory;
use DateTime;
class Sale extends AbstractHelper
{
protected $storesConfig;
protected $saleFactory;
+ protected $salesDataFactory;
- public function __construct(StoresConfig $storesConfig, CollectionFactory $saleFactory)
+ public function __construct(StoresConfig $storesConfig, CollectionFactory $saleFactory, SalesDataInterfaceFactory $salesDataFactory)
{
$this->storesConfig = $storesConfig;
$this->saleFactory = $saleFactory;
+ $this->salesDataFactory = $salesDataFactory;
}
- function getSales(string $dateRangeStr, string $rowRangeStr)
+ /**
+ * @param string $dateRangeStr
+ * @param string $rowRangeStr
+ *
+ * @return SalesDataInterface[]
+ */
+ function getSales(string $dateRangeStr, string $rowRangeStr): array
{
$result = [];
$collection = $this->saleFactory->create();
@@ -79,16 +89,17 @@ function getSales(string $dateRangeStr, string $rowRangeStr)
}
$createdAt = $dt->format('Y-m-d H:i:sP');
- $res = [
- 'order_id' => $orderID,
- 'customer_id' => $customerID,
- 'product_id' => $productID,
- 'quantity' => (string)$quantity,
- 'createdAt' => $createdAt,
- ];
- $result[] = $res;
+ $salesData = $this->salesDataFactory->create();
+
+ $salesData->setOrderId($orderID);
+ $salesData->setCustomerId($customerID);
+ $salesData->setProductId($productID);
+ $salesData->setQuantity((string)$quantity);
+ $salesData->setCreatedAt($createdAt);
+
+ $result[] = $salesData;
}
- return ['sales' => $result];
+ return $result;
}
/**
diff --git a/Helper/VersionInfo.php b/Helper/VersionInfo.php
index 34e8988..f952210 100644
--- a/Helper/VersionInfo.php
+++ b/Helper/VersionInfo.php
@@ -37,13 +37,20 @@ public function getVersion()
$version = $module['setup_version'];
}
+ $directory = $objectManager->get('\Magento\Framework\Filesystem\DirectoryList');
+
$result[] = [
- 'extension' => $version,
+ 'extensionVersion' => $version,
'magento' => $this->productMetadata->getName() . '/' . $this->productMetadata->getVersion() . ' (' . $this->productMetadata->getEdition() . ')',
'memLimit' => $this->getMemoryLimit(),
'OSType' => php_uname($mode = "s"),
'OSVersion' => php_uname($mode = "v"),
- 'maxExecutionTime' => ini_get("max_execution_time")
+ 'maxExecutionTime' => ini_get("max_execution_time"),
+ 'magentoName' => $this->productMetadata->getName(),
+ 'magentoVersion' => $this->productMetadata->getVersion(),
+ 'magentoEdition' => $this->productMetadata->getEdition(),
+ 'magentoRootPath' => $directory->getRoot(),
+ 'magentoLogPath' => $directory->getPath('log')
];
return $result;
diff --git a/Model/Customers.php b/Model/Customers.php
new file mode 100644
index 0000000..b626637
--- /dev/null
+++ b/Model/Customers.php
@@ -0,0 +1,27 @@
+customers;
+ }
+
+ /**
+ * @param $value CustomersDataInterface[]
+ */
+ public function setCustomers(array $value)
+ {
+ $this->customers = $value;
+ }
+}
\ No newline at end of file
diff --git a/Model/CustomersData.php b/Model/CustomersData.php
new file mode 100644
index 0000000..8e311eb
--- /dev/null
+++ b/Model/CustomersData.php
@@ -0,0 +1,43 @@
+id;
+ }
+
+ /**
+ * @return string
+ */
+ public function getEmail(): string
+ {
+ return $this->email;
+ }
+
+ /**
+ * @param $value string
+ */
+ public function setId(string $value)
+ {
+ $this->id = $value;
+ }
+
+ /**
+ * @param $value string
+ */
+ public function setEmail(string $value)
+ {
+ $this->email = $value;
+ }
+}
\ No newline at end of file
diff --git a/Model/Feed/DataProvider/AttributesProvider.php b/Model/Feed/DataProvider/AttributesProvider.php
index 20121ba..d91d67c 100644
--- a/Model/Feed/DataProvider/AttributesProvider.php
+++ b/Model/Feed/DataProvider/AttributesProvider.php
@@ -95,7 +95,14 @@ private function getProductData(Product $product) : array
$productData = $product->getData();
$result = [];
foreach ($productData as $key => $fieldValue) {
+ /*
+ For some reason the system fields does not show up
+ in the attribute list resulting in missing data.
+ To avoid the issue, we will include these in the
+ result without any additional processing
+ */
if (!isset($this->attributes[$key])) {
+ $result[$key] = $fieldValue;
continue;
}
/** @var Attribute $attribute */
diff --git a/Model/GetApplicationLog.php b/Model/GetApplicationLog.php
new file mode 100644
index 0000000..a6f8583
--- /dev/null
+++ b/Model/GetApplicationLog.php
@@ -0,0 +1,69 @@
+
+ * 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 .
+ */
+
+declare(strict_types=1);
+
+namespace SearchSpring\Feed\Model;
+
+use SearchSpring\Feed\Api\GetApplicationLogInterface;
+use SearchSpring\Feed\Exception\ValidationException;
+use SearchSpring\Feed\Helper\LogInfo;
+
+class GetApplicationLog implements GetApplicationLogInterface
+{
+ /** @var LogInfo */
+ private $helper;
+
+ /**
+ * @param LogInfo $helper
+ */
+ public function __construct(LogInfo $helper)
+ {
+ $this->helper = $helper;
+ }
+
+ /**
+ * @return string
+ */
+ public function getExtensionLog(bool $compressOutput = false) : string
+ {
+ return $this->helper->getExtensionLogFile($compressOutput);
+ }
+
+ /**
+ * @return bool
+ */
+ public function clearExtensionLog() : bool
+ {
+ return $this->helper->deleteExtensionLogFile();
+ }
+
+ /**
+ * @return string
+ */
+ public function getExceptionLog(bool $compressOutput = false) : string
+ {
+ return $this->helper->getExceptionLogFile($compressOutput);
+ }
+
+ /**
+ * @return bool
+ */
+ public function clearExceptionLog() : bool
+ {
+ return $this->helper->deleteExceptionLogFile();
+ }
+}
diff --git a/Model/GetCustomers.php b/Model/GetCustomers.php
index a1007ab..8aecffe 100644
--- a/Model/GetCustomers.php
+++ b/Model/GetCustomers.php
@@ -19,6 +19,8 @@
namespace SearchSpring\Feed\Model;
use SearchSpring\Feed\Api\GetCustomersInterface;
+use SearchSpring\Feed\Api\Data\CustomersInterface;
+use SearchSpring\Feed\Api\Data\CustomersInterfaceFactory;
use SearchSpring\Feed\Exception\ValidationException;
use SearchSpring\Feed\Helper\Customer;
use SearchSpring\Feed\Helper\Utils;
@@ -28,23 +30,28 @@ class GetCustomers implements GetCustomersInterface
/** @var Customer */
private $helper;
+ /** @var CustomersInterfaceFactory */
+ private $customersFactory;
+
/**
* @param Customer $helper
+ * @param CustomersInterfaceFactory $customersFactory
*/
- public function __construct(Customer $helper)
+ public function __construct(Customer $helper, CustomersInterfaceFactory $customersFactory)
{
$this->helper = $helper;
+ $this->customersFactory = $customersFactory;
}
/**
* @param string $dateRange
* @param string $rowRange
*
- * @return array
+ * @return CustomersInterface
*
* @throws ValidationException
*/
- public function getList(string $dateRange = "All", string $rowRange = "All")
+ public function getList(string $dateRange = "All", string $rowRange = "All"): CustomersInterface
{
$errors = [];
if (!Utils::validateDateRange($dateRange)){
@@ -59,6 +66,9 @@ public function getList(string $dateRange = "All", string $rowRange = "All")
throw new ValidationException($errors, 400);
}
- return $this->helper->getCustomers($dateRange, $rowRange);
+ $customers = $this->customersFactory->create();
+ $customers->setCustomers($this->helper->getCustomers($dateRange, $rowRange));
+
+ return $customers;
}
}
diff --git a/Model/GetSales.php b/Model/GetSales.php
index e29e91a..079acb9 100644
--- a/Model/GetSales.php
+++ b/Model/GetSales.php
@@ -19,6 +19,8 @@
namespace SearchSpring\Feed\Model;
use SearchSpring\Feed\Api\GetSalesInterface;
+use SearchSpring\Feed\Api\Data\SalesInterface;
+use SearchSpring\Feed\Api\Data\SalesInterfaceFactory;
use SearchSpring\Feed\Exception\ValidationException;
use SearchSpring\Feed\Helper\Sale;
use SearchSpring\Feed\Helper\Utils;
@@ -28,23 +30,27 @@ class GetSales implements GetSalesInterface
/** @var Sale */
private $helper;
+ /** @var SalesInterfaceFactory */
+ private $salesFactory;
+
/**
* @param Sale $helper
*/
- public function __construct(Sale $helper)
+ public function __construct(Sale $helper, SalesInterfaceFactory $salesFactory)
{
$this->helper = $helper;
+ $this->salesFactory = $salesFactory;
}
/**
* @param string $dateRange
* @param string $rowRange
*
- * @return array
+ * @return SalesInterface
*
* @throws ValidationException
*/
- public function getList(string $dateRange = "All", string $rowRange = "All")
+ public function getList(string $dateRange = "All", string $rowRange = "All"): SalesInterface
{
$errors = [];
if (!Utils::validateDateRange($dateRange)){
@@ -59,6 +65,9 @@ public function getList(string $dateRange = "All", string $rowRange = "All")
throw new ValidationException($errors, 400);
}
- return $this->helper->getSales($dateRange, $rowRange);
+ $sales = $this->salesFactory->create();
+ $sales->setSales($this->helper->getSales($dateRange, $rowRange));
+
+ return $sales;
}
}
diff --git a/Model/Sales.php b/Model/Sales.php
new file mode 100644
index 0000000..a81cd22
--- /dev/null
+++ b/Model/Sales.php
@@ -0,0 +1,26 @@
+sales;
+ }
+
+ /**
+ * @param $value SalesDataInterface[]
+ */
+ public function setSales(array $value)
+ {
+ $this->sales = $value;
+ }
+}
\ No newline at end of file
diff --git a/Model/SalesData.php b/Model/SalesData.php
new file mode 100644
index 0000000..7f35cfa
--- /dev/null
+++ b/Model/SalesData.php
@@ -0,0 +1,94 @@
+order_id;
+ }
+
+ /**
+ * @return string
+ */
+ public function getCustomerId(): string
+ {
+ return $this->customer_id;
+ }
+
+ /**
+ * @return string
+ */
+ public function getProductId(): string
+ {
+ return $this->product_id;
+ }
+
+ /**
+ * @return string
+ */
+ public function getQuantity(): string
+ {
+ return $this->quantity;
+ }
+
+ /**
+ * @return string
+ */
+ public function getCreatedAt(): string
+ {
+ return $this->createdAt;
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setOrderId(string $value)
+ {
+ $this->order_id = $value;
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setCustomerId(string $value)
+ {
+ $this->customer_id = $value;
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setProductId(string $value)
+ {
+ $this->product_id = $value;
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setQuantity(string $value)
+ {
+ $this->quantity = $value;
+ }
+
+ /**
+ * @param string $value
+ */
+ public function setCreatedAt(string $value)
+ {
+ $this->createdAt = $value;
+ }
+}
\ No newline at end of file
diff --git a/composer.json b/composer.json
index 968fb22..de39fb9 100644
--- a/composer.json
+++ b/composer.json
@@ -1,7 +1,7 @@
{
"name": "searchspring/magento2-module",
"type": "magento2-module",
- "version": "1.1.0",
+ "version": "2.0.0",
"license": "GPL-3.0-only",
"require": {
"magento/module-customer": "^103.0"
diff --git a/etc/di.xml b/etc/di.xml
index 188646f..5baa1d8 100644
--- a/etc/di.xml
+++ b/etc/di.xml
@@ -13,6 +13,14 @@
type="SearchSpring\Feed\Model\Feed\Specification\Feed"/>
+
+
+
+
+
-
+
diff --git a/etc/webapi.xml b/etc/webapi.xml
index 53a079d..e94953d 100644
--- a/etc/webapi.xml
+++ b/etc/webapi.xml
@@ -8,6 +8,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+