diff --git a/MAHO_COMMERCE_COMPATIBILITY.md b/MAHO_COMMERCE_COMPATIBILITY.md new file mode 100644 index 00000000..d9bac29b --- /dev/null +++ b/MAHO_COMMERCE_COMPATIBILITY.md @@ -0,0 +1,86 @@ +# Maho Commerce Compatibility + +This fork includes modifications to make the Algolia Search extension compatible with Maho Commerce. + +## Changes Made + +### 1. Helper Class Compatibility +- Modified `app/code/community/Algolia/Algoliasearch/Helper/Entity/Helper.php` to extend from `Mage_Core_Helper_Abstract` +- This is required because Maho Commerce enforces strict type checking for helper classes + +### 2. Search Collection Compatibility +- Fixed `app/code/community/Algolia/Algoliasearch/Model/Resource/Fulltext/Collection.php` to properly handle search results +- Added `_getQuery()` method to retrieve search query text +- Fixed `getFoundIds()` to return array of IDs instead of collection object for non-X3 versions +- Improved `addSearchFilter()` to handle empty search results properly +- These changes fix "Object could not be converted to string" errors when searching + +## Installation Instructions + +### 1. Install via Composer + +Add this repository to your `composer.json`: + +```json +{ + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/trabulium/algoliasearch-mahocommerce" + } + ], + "require": { + "algolia/algoliasearch-magento": "dev-maho-compatibility" + } +} +``` + +Then run: +```bash +composer require algolia/algoliasearch-magento:dev-maho-compatibility +``` + +### 2. CRITICAL: Regenerate Autoloader + +After installation, you MUST regenerate the autoloader with the Maho plugin: + +```bash +COMPOSER_ALLOW_SUPERUSER=1 composer dump-autoload +``` + +This step is essential because the Maho composer plugin needs to regenerate the autoloader with proper inclusion of bootstrap.php and all namespace mappings. + +### 3. Create Required Symlink + +The Algolia library needs to be accessible from the `lib` directory: + +```bash +mkdir -p lib +ln -s vendor/algolia/algoliasearch-magento/lib/AlgoliaSearch lib/AlgoliaSearch +``` + +### 4. Copy Module Declaration + +```bash +cp vendor/algolia/algoliasearch-magento/app/etc/modules/Algolia_Algoliasearch.xml app/etc/modules/ +``` + +### 5. Clear Cache + +```bash +php maho cache:flush +``` + +## Troubleshooting + +### Error: "Failed opening required '/path/to/lib/AlgoliaSearch/loader.php'" +- Ensure you've created the symlink as described in step 3 + +### Error: "Return value must be of type Mage_Core_Helper_Abstract" +- This fork should resolve this issue. If you still see it, ensure you're on the `maho-compatibility` branch + +### Error: "Undefined constant BP" +- Run the composer dump-autoload command from step 2 + +### Error: "Object of class Algolia_Algoliasearch_Model_Resource_Fulltext_Collection could not be converted to string" +- This fork includes fixes for this issue. Ensure you're using the latest version of the `maho-compatibility` branch \ No newline at end of file diff --git a/README.md b/README.md index 1c44796f..3895c014 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -Algolia Search for Magento 1.6+ +Algolia Search for Magento 1.6+ / Maho Commerce ================== ![Latest version](https://img.shields.io/badge/latest-1.19.0-green.svg) @@ -10,6 +10,13 @@ Algolia Search for Magento 1.6+ ![Magento 1.8.1](https://img.shields.io/badge/magento-1.8.1-blue.svg) ![Magento 1.9.2](https://img.shields.io/badge/magento-1.9.2-blue.svg) ![Magento 1.9.3](https://img.shields.io/badge/magento-1.9.3-blue.svg) +![Maho Commerce](https://img.shields.io/badge/maho-commerce-blue.svg) + +------- + +## Maho Commerce Compatibility + +This fork includes modifications for **Maho Commerce** compatibility. See [MAHO_COMMERCE_COMPATIBILITY.md](MAHO_COMMERCE_COMPATIBILITY.md) for installation instructions and changes. ------- diff --git a/app/code/community/Algolia/Algoliasearch/Helper/Entity/Helper.php b/app/code/community/Algolia/Algoliasearch/Helper/Entity/Helper.php index d061ad2e..864b82a4 100644 --- a/app/code/community/Algolia/Algoliasearch/Helper/Entity/Helper.php +++ b/app/code/community/Algolia/Algoliasearch/Helper/Entity/Helper.php @@ -1,6 +1,6 @@ _helper()->isX3Version()) { - return $this; + // For older versions, search is handled in addSearchFilter + // We need to check if we already have Algolia data + $query = $this->_getQuery(); + if (!empty($query)) { + $data = $this->getAlgoliaData($query); + if ($data !== false) { + return array_keys($data); + } + } + return parent::getFoundIds(); } $query = $this->_getQuery(); @@ -70,6 +79,20 @@ protected function getAlgoliaData($query) return $data; } + /** + * Get query text + * + * @return string|null + */ + protected function _getQuery() + { + $query = Mage::helper('catalogsearch')->getQuery(); + if ($query) { + return $query->getQueryText(); + } + return null; + } + /** * @param string $query * @@ -87,10 +110,15 @@ public function addSearchFilter($query) } $sortedIds = array_reverse(array_keys($data)); - $this->getSelect()->columns(array( - 'relevance' => new Zend_Db_Expr("FIND_IN_SET(e.entity_id, '" . implode(',', $sortedIds) . "')"), - )); - $this->getSelect()->where('e.entity_id IN (?)', $sortedIds); + if (!empty($sortedIds)) { + $this->getSelect()->columns(array( + 'relevance' => new Zend_Db_Expr("FIND_IN_SET(e.entity_id, '" . implode(',', $sortedIds) . "')"), + )); + $this->getSelect()->where('e.entity_id IN (?)', $sortedIds); + } else { + // No results, return empty collection + $this->getSelect()->where('1=0'); + } return $this; }