From 7b1e1a8725354e1b6ef4e4948a393d9a581c1281 Mon Sep 17 00:00:00 2001 From: Massimiliano Monaro Date: Thu, 19 Nov 2020 10:59:55 +0100 Subject: [PATCH 1/2] Fix for json_encode to prevent casting numeric values --- Model/Api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Model/Api.php b/Model/Api.php index ce8fb6c..93ba7d2 100644 --- a/Model/Api.php +++ b/Model/Api.php @@ -90,7 +90,7 @@ private function post($endpoint, $params = []) /** @var \Magento\Framework\HTTP\ZendClient $httpClient */ $httpClient = $this->httpClientFactory->create(); $httpClient->setUri($this->baseurl . $endpoint); - $httpClient->setRawData(json_encode($params), 'application/json'); + $httpClient->setRawData(json_encode($params, JSON_NUMERIC_CHECK), 'application/json'); $result = $httpClient->request('POST'); From 073d6d8f13b356e860211b3a23c9b7e531d1ed1a Mon Sep 17 00:00:00 2001 From: Massimiliano Monaro Date: Thu, 19 Nov 2020 11:03:58 +0100 Subject: [PATCH 2/2] Improved field handlers for specific fields - force cast id to integer - remove html tags from product's description - force cast category id to integer --- Model/Adapter/Product.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/Model/Adapter/Product.php b/Model/Adapter/Product.php index 6f89b99..8c988f0 100644 --- a/Model/Adapter/Product.php +++ b/Model/Adapter/Product.php @@ -171,6 +171,30 @@ protected function addFieldHandlers() try { + //Add id fieldhandler + $this->addFieldHandler('id', function ($item) { + try { + /** + * @var \Magento\Catalog\Model\Product $item + */ + return intval($item->getId()); + } catch (\Exception $e) { + return 0; + } + }); + + //Add description fieldhandler + $this->addFieldHandler('description', function ($item) { + try { + /** + * @var \Magento\Catalog\Model\Product $item + */ + return strip_tags($item->getDescription()); + } catch (\Exception $e) { + return ''; + } + }); + //Add price fieldhandler $this->addFieldHandler('price', function ($item) { try { @@ -229,7 +253,7 @@ protected function addFieldHandlers() //Add categories fieldhandler $this->addFieldHandler('categories', function ($item) { - return $item->getCategoryIds(); + return array_map('intval', $item->getCategoryIds()); }); //Add age fieldhandler