Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions MAHO_COMMERCE_COMPATIBILITY.md
Original file line number Diff line number Diff line change
@@ -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
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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.

-------

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

abstract class Algolia_Algoliasearch_Helper_Entity_Helper
abstract class Algolia_Algoliasearch_Helper_Entity_Helper extends Mage_Core_Helper_Abstract
{
/** @var Algolia_Algoliasearch_Helper_Config */
protected $config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ class Algolia_Algoliasearch_Model_Resource_Fulltext_Collection extends Mage_Cata
public function getFoundIds()
{
if (!$this->_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();
Expand Down Expand Up @@ -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
*
Expand All @@ -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;
}
Expand Down