From ee1da88e991bd94a2553ae7dd7ce7523874cfcfe Mon Sep 17 00:00:00 2001 From: ade Date: Thu, 26 Sep 2019 14:22:36 +0200 Subject: [PATCH 1/3] new edit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fa70541..86b72ae 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ This repo contains the Magento Extension that allows connection to the Everlytic - Visit, System > Web Services > Rest Attributes. Choose the User Type, advisably Admin and choose the attributes to give access to. ##### Compatibility - Compatibility: 1.9 + Compatibility: 1.9 Support ------- From b15039a4e437fc2368704b59c6434720a1722daa Mon Sep 17 00:00:00 2001 From: ade Date: Mon, 14 Oct 2019 11:44:46 +0200 Subject: [PATCH 2/3] Update-10-2-2019 - Fix to allow for search, if no search return empty and limit search result to 10 --- .../Model/Api2/Product/Rest/Admin/V1.php | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/app/code/local/Everlytic/Productapi/Model/Api2/Product/Rest/Admin/V1.php b/app/code/local/Everlytic/Productapi/Model/Api2/Product/Rest/Admin/V1.php index 2c99c62..b7c4956 100644 --- a/app/code/local/Everlytic/Productapi/Model/Api2/Product/Rest/Admin/V1.php +++ b/app/code/local/Everlytic/Productapi/Model/Api2/Product/Rest/Admin/V1.php @@ -61,18 +61,7 @@ protected function _prepareProductForResponse(Mage_Catalog_Model_Product $produc */ protected function _retrieveCollection() { - /** @var $collection Mage_Catalog_Model_Resource_Product_Collection */ - $collection = Mage::getResourceModel('catalog/product_collection'); - $collection->addAttributeToSelect(array_keys( - $this->getAvailableAttributes($this->getUserType(), Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_READ) - )); - $products = $collection->load(); - - foreach ($products as $product) { - $this->_prepareProductForResponse($product); - } - - return $products->toArray(); + return (isset($_GET['search_query']) && ($_GET['search_query'] !== '')) ? $this->handleSearch() : array(); } /** @@ -88,4 +77,29 @@ private function getGalleryFromProduct(Mage_Catalog_Model_Product $product) } return $gallery; } + + /** + * @return mixed + */ + private function handleSearch() + { + $collection = Mage::getResourceModel('catalog/product_collection'); + $collection->addAttributeToSelect(array_keys( + $this->getAvailableAttributes($this->getUserType(), Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_READ) + )); + $searchQuery = $_GET['search_query']; + $collection->addFieldToFilter(array( + array('attribute' => 'name', array('like' => '%' . $searchQuery . '%')), + array('attribute' => 'sku', array('like' => '%' . $searchQuery . '%')) + ) + ); + $collection->setPageSize(10)->setCurPage(1); + $products = $collection->load(); + + foreach ($products as $product) { + $this->_prepareProductForResponse($product); + } + + return $products->toArray(); + } } From 70722c8bf00f71df1caa17bde50a5acd90274f66 Mon Sep 17 00:00:00 2001 From: ade Date: Tue, 15 Oct 2019 11:45:38 +0200 Subject: [PATCH 3/3] Update-10-2-2019 - Made Changes from review by albert --- .../Productapi/Model/Api2/Product/Rest/Admin/V1.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/local/Everlytic/Productapi/Model/Api2/Product/Rest/Admin/V1.php b/app/code/local/Everlytic/Productapi/Model/Api2/Product/Rest/Admin/V1.php index b7c4956..d6bf0f2 100644 --- a/app/code/local/Everlytic/Productapi/Model/Api2/Product/Rest/Admin/V1.php +++ b/app/code/local/Everlytic/Productapi/Model/Api2/Product/Rest/Admin/V1.php @@ -61,7 +61,7 @@ protected function _prepareProductForResponse(Mage_Catalog_Model_Product $produc */ protected function _retrieveCollection() { - return (isset($_GET['search_query']) && ($_GET['search_query'] !== '')) ? $this->handleSearch() : array(); + return (isset($_GET['search_query']) && ($_GET['search_query'] !== '')) ? $this->handleSearch($_GET['search_query']) : array(); } /** @@ -79,15 +79,15 @@ private function getGalleryFromProduct(Mage_Catalog_Model_Product $product) } /** + * @param $searchQuery * @return mixed */ - private function handleSearch() + private function handleSearch($searchQuery) { $collection = Mage::getResourceModel('catalog/product_collection'); $collection->addAttributeToSelect(array_keys( $this->getAvailableAttributes($this->getUserType(), Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_READ) )); - $searchQuery = $_GET['search_query']; $collection->addFieldToFilter(array( array('attribute' => 'name', array('like' => '%' . $searchQuery . '%')), array('attribute' => 'sku', array('like' => '%' . $searchQuery . '%'))