Skip to content
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
composer.lock
vendor/
.vscode
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

## Guides

* [Backend custom events](https://community.algolia.com/magento/doc/m2/backend/)
* [Frontend custom events](https://community.algolia.com/magento/doc/m2/frontend-events/)
- [Backend custom events](https://community.algolia.com/magento/doc/m2/backend/)
- [Frontend custom events](https://community.algolia.com/magento/doc/m2/frontend-events/)

## Installation

The template module can be installed Manually:
The template module can be installed via [Composer](https://getcomposer.org/):

```sh
$ cd /path/to/your/magento2/directory/app/code
$ Create a directory in app/code as Algolia/CustomAlgolia
$ Download the file from https://github.com/algolia/algoliasearch-custom-algolia-magento-2/ and unzip
$ Copy the unzip files in to app/code/Algolia/CustomAlgolia
$ cd /path/to/your/magento2/directory
$ composer require algolia/algoliasearch-custom-algolia-magento-2
$ php bin/magento setup:upgrade
```

> Please note that this is a starter module. Composer will install this code to your local `app/code` directory where you can make further modifications to the implementation and commit to your own project repository.
23 changes: 14 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@
"name": "algolia/algoliasearch-custom-algolia-magento-2",
"description": "Custom boilerplate module to extend Algolia Magento 2 extension",
"type": "magento2-module",
"license": ["MIT"],
"version": "1.1.0",
"license": [
"MIT"
],
"version": "1.2.0",
"require": {
"algolia/algoliasearch-magento-2": ">=1.13.3"
"algolia/algoliasearch-magento-2": "^3.9.1",
"magento/magento-composer-installer": "*"
},
"autoload": {
"files": [ "registration.php" ],
"psr-4": {
"Algolia\\CustomAlgolia\\": ""
}
"extra": {
"map": [
[
"*",
"Algolia/CustomAlgolia"
]
]
}
}
}
23 changes: 16 additions & 7 deletions view/frontend/layout/algolia_search_handle.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<!-- Uncomment the following line to include files with front-end hook methods -->
<!-- <script src="Algolia_CustomAlgolia::hooks.js" /> -->

<!-- Uncomment the following line to remove the main algolia CSS file -->
<!-- <remove src="Algolia_AlgoliaSearch::internals/algoliasearch.css" /> -->

Expand All @@ -12,11 +9,23 @@
</head>
<body>
<referenceBlock name="before.body.end">
<!-- Uncomment the following line to declare a new template -->
<!-- <block class="Magento\Framework\View\Element\Template" name="custom.autocomplete.template" template="Algolia_CustomAlgolia::autocomplete/custom.phtml"/> -->
<!--
Uncomment the following lines to override the default InstantSearch widget templates.

NOTE: Only a sample facet.phtml file is supplied in this starter kit.
If you wish to override other templates be sure to implement your template based on
vendor/algolia/algoliasearch-magento-2/view/frontend/templates/instant
-->
<!-- <referenceBlock name="algolia.instant.facet" template="Algolia_CustomAlgolia::instant/facet.phtml"/> -->
<!-- <referenceBlock name="algolia.instant.refinements" template="Algolia_CustomAlgolia::instant/refinements.phtml"/> -->
<!-- <referenceBlock name="algolia.instant.hit" template="Algolia_CustomAlgolia::instant/hit.phtml"/> -->
<!-- <referenceBlock name="algolia.instant.stats" template="Algolia_CustomAlgolia::instant/stats.phtml"/> -->

<!-- Uncomment the following line to override the autocomplete/page template -->
<!-- <referenceBlock name="algolia.autocomplete.page" template="Algolia_CustomAlgolia::autocomplete/page.phtml" /> -->
<!--
IMPORTANT!
If you are looking to customize Autocomplete this functionality has moved as of v3.9.1!
(See requirejs-config.js for details)
-->
</referenceBlock>
</body>
</page>
67 changes: 67 additions & 0 deletions view/frontend/requirejs-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* Documentation: https://www.algolia.com/doc/integration/magento-2/customize/autocomplete-menu
**/

/**
* This starter file provides a means to override the Algolia search experience using RequireJS.
*
*
*
* You can customize Autocomplete in 2 ways:
* 1. Via a complete override of the underlying functional template
* 2. Via a JavaScript mixin (recommended)
*/

var config = {
map: {
"*": {
algoliaHooks: "Algolia_CustomAlgolia/hooks",

////////////////////////////////////
// AUTOCOMPLETE TEMPLATE OVERRIDE //
////////////////////////////////////

// Uncomment the following line to override the products.js functional template
// productsHtml': 'Algolia_CustomAlgolia/internals/template/autocomplete/products'
},
},

/////////////////////
// FRONT END HOOKS //
/////////////////////

// Uncomment the following line to include front-end hook methods - see https://www.algolia.com/doc/integration/magento-2/customize/custom-front-end-events/
// deps: ["algoliaHooks"],

//,

////////////////////////
// AUTOCOMPLETE MIXIN //
////////////////////////

/**
* You can add a mixin to customize only a single portion of a template based on the corresponding function.
* Use the `html` tagged template literal supplied via the function arguments to return your custom content as HTML.
*/

config: {
mixins: {
// Uncomment the following mixins to override the hit template via a JavaScript mixin for a given source
// "Algolia_AlgoliaSearch/internals/template/autocomplete/products": {
// "Algolia_CustomAlgolia/template/autocomplete/products-mixin": true,
// },
// "Algolia_AlgoliaSearch/internals/template/autocomplete/categories": {
// "Algolia_CustomAlgolia/template/autocomplete/categories-mixin": true,
// },
// "Algolia_AlgoliaSearch/internals/template/autocomplete/pages": {
// "Algolia_CustomAlgolia/template/autocomplete/pages-mixin": true,
// },
// "Algolia_AlgoliaSearch/internals/template/autocomplete/additional-section": {
// "Algolia_CustomAlgolia/template/autocomplete/additional-section-mixin": true,
// },
// "Algolia_AlgoliaSearch/internals/template/autocomplete/suggestions": {
// "Algolia_CustomAlgolia/template/autocomplete/suggestions-mixin": true,
// },
},
},
};
1 change: 0 additions & 1 deletion view/frontend/templates/autocomplete/custom.phtml

This file was deleted.

14 changes: 0 additions & 14 deletions view/frontend/templates/autocomplete/page.phtml

This file was deleted.

7 changes: 7 additions & 0 deletions view/frontend/templates/instant/facet.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script type="text/template" id="refinements-lists-item-template">
<label class="{{cssClasses.label}} {{#isRefined}}checked{{/isRefined}}">
<input class="{{cssClasses.checkbox}}" {{#isRefined}}checked{{/isRefined}} type="checkbox" value="{{value}}" />
{{value}}
<span class="{{cssClasses.count}}">{{count}}</span>
</label>
</script>
119 changes: 72 additions & 47 deletions view/frontend/web/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,84 @@
* autocomplete.js documentation: https://github.com/algolia/autocomplete.js
**/

algolia.registerHook('beforeAutocompleteSources', function(sources, algolia_client, algoliaBundle) {
console.log('In hook method to modify autocomplete data sources');
define(["jquery", "algoliaAnalytics", "algoliaBundle"], function (
$,
algoliaAnalyticsWrapper,
algoliaBundle
) {
algolia.registerHook(
"beforeAutocompleteSources",
function (sources, algolia_client, algoliaBundle) {
console.log("In hook method to modify autocomplete data sources");

// use the global window variable `algoliaConfig` to see what has been configured in the system configuration
console.log(algoliaConfig);
// use the global window variable `algoliaConfig` to see what has been configured in the system configuration
console.log(algoliaConfig);

// Modify autocomplete data sources

return sources;
});
// Modify autocomplete data sources

algolia.registerHook('beforeAutocompleteOptions', function(options) {
console.log('In hook method to modify autocomplete options');

// Modify autocomplete options

return options;
});
return sources;
}
);

/**
* InstantSearch hook methods
* IS.js v2 documentation: https://community.algolia.com/instantsearch.js/
* IS.js v4 documentation: https://www.algolia.com/doc/api-reference/widgets/instantsearch/js/
**/
algolia.registerHook("beforeAutocompleteOptions", function (options) {
console.log("In hook method to modify autocomplete options");

algolia.registerHook('beforeInstantsearchInit', function(instantsearchOptions, algoliaBundle) {
console.log('In method to modify instantsearch options');

// Modify instant search options

return instantsearchOptions;
});
// Modify autocomplete options

algolia.registerHook('beforeWidgetInitialization', function(allWidgetConfiguration, algoliaBundle) {
console.log('In hook method to modify instant search widgets');

// Modify instant search widgets

return allWidgetConfiguration;
});
return options;
});

algolia.registerHook('beforeInstantsearchStart', function(search, algoliaBundle) {
console.log('In hook method to modify instant search instance before search started');

// Modify instant search instance before search started

return search;
});
/**
* InstantSearch hook methods
* IS.js v2 documentation: https://community.algolia.com/instantsearch.js/
* IS.js v4 documentation: https://www.algolia.com/doc/api-reference/widgets/instantsearch/js/
**/

algolia.registerHook(
"beforeInstantsearchInit",
function (instantsearchOptions, algoliaBundle) {
console.log("In method to modify instantsearch options");

// Modify instant search options

return instantsearchOptions;
}
);

algolia.registerHook(
"beforeWidgetInitialization",
function (allWidgetConfiguration, algoliaBundle) {
console.log("In hook method to modify instant search widgets");

// Modify instant search widgets

return allWidgetConfiguration;
}
);

algolia.registerHook(
"beforeInstantsearchStart",
function (search, algoliaBundle) {
console.log(
"In hook method to modify instant search instance before search started"
);

// Modify instant search instance before search started

return search;
}
);

algolia.registerHook(
"afterInstantsearchStart",
function (search, algoliaBundle) {
console.log(
"In hook method to modify instant search instance after search started"
);

// Modify instant search instance after search started

algolia.registerHook('afterInstantsearchStart', function(search, algoliaBundle) {
console.log('In hook method to modify instant search instance after search started');

// Modify instant search instance after search started

return search;
return search;
}
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SAMPLE ADDITIONAL SECTION MIXIN
define(function () {
"use strict";

const mixin = {
getHeaderHtml: function ({ section }) {
return `This ${section.name} template was customized!`;
},
};

return function (target) {
return { ...target, ...mixin };
};
});
14 changes: 14 additions & 0 deletions view/frontend/web/template/autocomplete/categories-mixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SAMPLE CATEGORIES MIXIN
define(function () {
"use strict";

const mixin = {
getHeaderHtml: function () {
return "This category template was customized!";
},
};

return function (target) {
return { ...target, ...mixin };
};
});
14 changes: 14 additions & 0 deletions view/frontend/web/template/autocomplete/pages-mixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SAMPLE PAGES MIXIN
define(function () {
"use strict";

const mixin = {
getHeaderHtml: function () {
return "This page template was customized!";
},
};

return function (target) {
return { ...target, ...mixin };
};
});
Loading