|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Algolia\AlgoliaSearch\Helper\Configuration; |
| 4 | + |
| 5 | +use Algolia\AlgoliaSearch\Helper\ConfigHelper; |
| 6 | +use Magento\Framework\View\Asset\Repository as AssetRepository; |
| 7 | + |
| 8 | +class AssetHelper extends \Magento\Framework\App\Helper\AbstractHelper |
| 9 | +{ |
| 10 | + /** @var ConfigHelper */ |
| 11 | + private $configHelper; |
| 12 | + |
| 13 | + /** @var AssetRepository */ |
| 14 | + private $assetRepository; |
| 15 | + |
| 16 | + /** @var array */ |
| 17 | + private $videosConfig = [ |
| 18 | + 'algoliasearch_credentials' => [ |
| 19 | + 'title' => 'How to change a setting', |
| 20 | + 'url' => 'https://www.youtube.com/watch?v=7yqOMb2SHw0', |
| 21 | + 'thumbnail' => 'https://img.youtube.com/vi/7yqOMb2SHw0/mqdefault.jpg', |
| 22 | + ], |
| 23 | + 'algoliasearch_autocomplete' => [ |
| 24 | + 'title' => 'Autocomplete menu configuration', |
| 25 | + 'url' => 'https://www.youtube.com/watch?v=S6yuPl-bsFQ', |
| 26 | + 'thumbnail' => 'https://img.youtube.com/vi/S6yuPl-bsFQ/mqdefault.jpg', |
| 27 | + ], |
| 28 | + 'algoliasearch_instant' => [ |
| 29 | + 'title' => 'Instantsearch page configuration', |
| 30 | + 'url' => 'https://www.youtube.com/watch?v=-gy92Pbwb64', |
| 31 | + 'thumbnail' => 'https://img.youtube.com/vi/-gy92Pbwb64/mqdefault.jpg', |
| 32 | + ], |
| 33 | + 'algoliasearch_products' => [ |
| 34 | + 'title' => 'Product search configuration', |
| 35 | + 'url' => 'https://www.youtube.com/watch?v=6XJ11UdgVPE', |
| 36 | + 'thumbnail' => 'https://img.youtube.com/vi/6XJ11UdgVPE/mqdefault.jpg', |
| 37 | + ], |
| 38 | + 'algoliasearch_queue' => [ |
| 39 | + 'title' => 'The indexing queue', |
| 40 | + 'url' => 'https://www.youtube.com/watch?v=0V1BSKlCm10', |
| 41 | + 'thumbnail' => 'https://img.youtube.com/vi/0V1BSKlCm10/mqdefault.jpg', |
| 42 | + ], |
| 43 | + 'algoliasearch_synonyms' => [ |
| 44 | + 'title' => 'Notable features', |
| 45 | + 'url' => 'https://www.youtube.com/watch?v=45NKJbrs1Z4', |
| 46 | + 'thumbnail' => 'https://img.youtube.com/vi/45NKJbrs1Z4/mqdefault.jpg', |
| 47 | + ], |
| 48 | + 'algoliasearch_cc_analytics' => [ |
| 49 | + 'title' => 'Notable features', |
| 50 | + 'url' => 'https://www.youtube.com/watch?v=45NKJbrs1Z4', |
| 51 | + 'thumbnail' => 'https://img.youtube.com/vi/45NKJbrs1Z4/mqdefault.jpg', |
| 52 | + ], |
| 53 | + ]; |
| 54 | + |
| 55 | + /** @var array */ |
| 56 | + private $linksConfig = [ |
| 57 | + 'algoliasearch_credentials' => [ |
| 58 | + [ |
| 59 | + 'title' => 'Documentation', |
| 60 | + 'url' => 'https://www.algolia.com/doc/integration/magento-2/getting-started/quick-start/?utm_source=magento&utm_medium=extension&utm_campaign=magento_2&utm_term=shop-owner&utm_content=doc-link', |
| 61 | + 'icon' => 'iconDocs', |
| 62 | + ], |
| 63 | + [ |
| 64 | + 'title' => 'FAQ', |
| 65 | + 'url' => 'https://www.algolia.com/doc/integration/magento-2/troubleshooting/general-faq/?utm_source=magento&utm_medium=extension&utm_campaign=magento_2&utm_term=shop-owner&utm_content=doc-link', |
| 66 | + 'icon' => 'iconFaq', |
| 67 | + ], |
| 68 | + [ |
| 69 | + 'title' => 'Issues', |
| 70 | + 'url' => 'https://github.com/algolia/algoliasearch-magento-2/issues/', |
| 71 | + 'icon' => 'iconIssues', |
| 72 | + ], |
| 73 | + ], |
| 74 | + 'algoliasearch_autocomplete' => [ |
| 75 | + [ |
| 76 | + 'title' => 'Customize autocomplete', |
| 77 | + 'url' => 'https://www.algolia.com/doc/integration/magento-2/customize/autocomplete-menu/?utm_source=magento&utm_medium=extension&utm_campaign=magento_2&utm_term=shop-owner&utm_content=doc-link', |
| 78 | + 'icon' => 'iconDocs', |
| 79 | + ], |
| 80 | + [ |
| 81 | + 'title' => 'Add an external data source', |
| 82 | + 'url' => 'https://www.algolia.com/doc/integration/magento-1/guides/adding-autocomplete-source/?utm_source=magento&utm_medium=extension&utm_campaign=magento_2&utm_term=shop-owner&utm_content=doc-link', |
| 83 | + 'icon' => 'iconDocs', |
| 84 | + ], |
| 85 | + [ |
| 86 | + 'title' => 'Use backend events', |
| 87 | + 'url' => 'https://www.algolia.com/doc/integration/magento-2/customize/custom-back-end-events/?utm_source=magento&utm_medium=extension&utm_campaign=magento_2&utm_term=shop-owner&utm_content=doc-link', |
| 88 | + 'icon' => 'iconDocs', |
| 89 | + ], |
| 90 | + ], |
| 91 | + 'algoliasearch_instant' => [ |
| 92 | + [ |
| 93 | + 'title' => 'Customize InstantSearch', |
| 94 | + 'url' => 'https://www.algolia.com/doc/integration/magento-2/customize/instant-search-page/?utm_source=magento&utm_medium=extension&utm_campaign=magento_2&utm_term=shop-owner&utm_content=doc-link', |
| 95 | + 'icon' => 'iconDocs', |
| 96 | + ], |
| 97 | + [ |
| 98 | + 'title' => 'Use backend events', |
| 99 | + 'url' => 'https://www.algolia.com/doc/integration/magento-2/customize/custom-back-end-events/?utm_source=magento&utm_medium=extension&utm_campaign=magento_2&utm_term=shop-owner&utm_content=doc-link', |
| 100 | + 'icon' => 'iconDocs', |
| 101 | + ], |
| 102 | + ], |
| 103 | + 'algoliasearch_products' => [ |
| 104 | + [ |
| 105 | + 'title' => 'Products\' indexing documentation', |
| 106 | + 'url' => 'https://www.algolia.com/doc/integration/magento-2/how-it-works/indexing/?utm_source=magento&utm_medium=extension&utm_campaign=magento_2&utm_term=shop-owner&utm_content=doc-link#products-indexing', |
| 107 | + 'icon' => 'iconDocs', |
| 108 | + ], |
| 109 | + ], |
| 110 | + 'algoliasearch_categories' => [ |
| 111 | + [ |
| 112 | + 'title' => 'Categories\' indexing documentation', |
| 113 | + 'url' => 'https://www.algolia.com/doc/integration/magento-2/how-it-works/indexing/?utm_source=magento&utm_medium=extension&utm_campaign=magento_2&utm_term=shop-owner&utm_content=doc-link#categories-indexing', |
| 114 | + 'icon' => 'iconDocs', |
| 115 | + ], |
| 116 | + ], |
| 117 | + 'algoliasearch_images' => [ |
| 118 | + [ |
| 119 | + 'title' => 'Issues with images', |
| 120 | + 'url' => 'https://www.algolia.com/doc/integration/magento-2/troubleshooting/general-faq/?utm_source=magento&utm_medium=extension&utm_campaign=magento_2&utm_term=shop-owner&utm_content=doc-link#why-are-images-not-showing-up', |
| 121 | + 'icon' => 'iconIssues', |
| 122 | + ], |
| 123 | + ], |
| 124 | + 'algoliasearch_queue' => [ |
| 125 | + [ |
| 126 | + 'title' => 'Indexing queue documentation', |
| 127 | + 'url' => 'https://www.algolia.com/doc/integration/magento-2/how-it-works/indexing-queue/?utm_source=magento&utm_medium=extension&utm_campaign=magento_2&utm_term=shop-owner&utm_content=doc-link#general-information', |
| 128 | + 'icon' => 'iconDocs', |
| 129 | + ], |
| 130 | + [ |
| 131 | + 'title' => 'Indexing troubleshooting guide', |
| 132 | + 'url' => 'https://www.algolia.com/doc/integration/magento-2/troubleshooting/data-indexes-queues/?utm_source=magento&utm_medium=extension&utm_campaign=magento_2&utm_term=shop-owner&utm_content=doc-link#general-information', |
| 133 | + 'icon' => 'iconDocs', |
| 134 | + ], |
| 135 | + ], |
| 136 | + 'algoliasearch_synonyms' => [ |
| 137 | + [ |
| 138 | + 'title' => 'Synonyms documentation', |
| 139 | + 'url' => 'https://www.algolia.com/doc/guides/managing-results/optimize-search-results/adding-synonyms/?utm_source=magento&utm_medium=extension&utm_campaign=magento_2&utm_term=shop-owner&utm_content=doc-link', |
| 140 | + 'icon' => 'iconDocs', |
| 141 | + ], |
| 142 | + ], |
| 143 | + 'algoliasearch_cc_analytics' => [ |
| 144 | + [ |
| 145 | + 'title' => 'Click & Conversion Analytics', |
| 146 | + 'url' => 'https://www.algolia.com/doc/guides/getting-insights-and-analytics/click-analytics/?utm_source=magento&utm_medium=extension&utm_campaign=magento_2&utm_term=shop-owner&utm_content=doc-link', |
| 147 | + 'icon' => 'iconDocs', |
| 148 | + ], |
| 149 | + [ |
| 150 | + 'title' => 'Documentation for magento2', |
| 151 | + 'url' => 'https://www.algolia.com/doc/integration/magento-2/how-it-works/click-and-conversion-analytics/?utm_source=magento&utm_medium=extension&utm_campaign=magento_2&utm_term=shop-owner&utm_content=doc-link', |
| 152 | + 'icon' => 'iconDocs', |
| 153 | + ], |
| 154 | + ], |
| 155 | + 'algoliasearch_analytics' => [ |
| 156 | + [ |
| 157 | + 'title' => 'Documentation of Magento Google analytics', |
| 158 | + 'url' => 'https://www.algolia.com/doc/integration/magento-2/how-it-works/google-analytics/?utm_source=magento&utm_medium=extension&utm_campaign=magento_2&utm_term=shop-owner&utm_content=doc-link', |
| 159 | + 'icon' => 'iconDocs', |
| 160 | + ], |
| 161 | + ], |
| 162 | + 'algoliasearch_extra_settings' => [ |
| 163 | + [ |
| 164 | + 'title' => 'List of possible settings', |
| 165 | + 'url' => 'https://www.algolia.com/doc/api-reference/settings-api-parameters/#index-settings-parameters', |
| 166 | + 'icon' => 'iconDocs', |
| 167 | + ], |
| 168 | + ], |
| 169 | + ]; |
| 170 | + |
| 171 | + private $icons = []; |
| 172 | + |
| 173 | + /** @var array */ |
| 174 | + private $videoInstallation = [ |
| 175 | + 'title' => 'Installation & Setup', |
| 176 | + 'url' => 'https://www.youtube.com/watch?v=twEj_VBWxp8', |
| 177 | + 'thumbnail' => 'https://img.youtube.com/vi/twEj_VBWxp8/mqdefault.jpg', |
| 178 | + ]; |
| 179 | + |
| 180 | + public function __construct( |
| 181 | + \Magento\Framework\App\Helper\Context $context, |
| 182 | + ConfigHelper $configHelper, |
| 183 | + AssetRepository $assetRepository |
| 184 | + ) { |
| 185 | + $this->configHelper = $configHelper; |
| 186 | + $this->assetRepository = $assetRepository; |
| 187 | + |
| 188 | + $this->icons = [ |
| 189 | + 'iconDocs' => $this->assetRepository->getUrl('Algolia_AlgoliaSearch::images/icon-docs.svg'), |
| 190 | + 'iconFaq' => $this->assetRepository->getUrl('Algolia_AlgoliaSearch::images/icon-faq.svg'), |
| 191 | + 'iconIssues' => $this->assetRepository->getUrl('Algolia_AlgoliaSearch::images/icon-issues.svg'), |
| 192 | + ]; |
| 193 | + parent::__construct($context); |
| 194 | + } |
| 195 | + |
| 196 | + /** @return array|void */ |
| 197 | + protected function getVideoConfig($section, $configNotSet) |
| 198 | + { |
| 199 | + $config = null; |
| 200 | + |
| 201 | + if (isset($this->videosConfig[$section])) { |
| 202 | + $config = $this->videosConfig[$section]; |
| 203 | + } |
| 204 | + |
| 205 | + // If the credentials are not set, display the installation video |
| 206 | + if ($configNotSet) { |
| 207 | + $config = $this->videoInstallation; |
| 208 | + } |
| 209 | + |
| 210 | + return $config; |
| 211 | + } |
| 212 | + |
| 213 | + /** @return array|void */ |
| 214 | + protected function getLinksConfig($section) |
| 215 | + { |
| 216 | + $config = null; |
| 217 | + |
| 218 | + if (isset($this->linksConfig[$section])) { |
| 219 | + $config = $this->linksConfig[$section]; |
| 220 | + } |
| 221 | + |
| 222 | + return $config; |
| 223 | + } |
| 224 | + |
| 225 | + public function getLinksAndVideoTemplate($section) |
| 226 | + { |
| 227 | + $configNotSet = false; |
| 228 | + // Check if all the mandatory credentials have been set |
| 229 | + if (!$this->configHelper->getApplicationID() |
| 230 | + || !$this->configHelper->getAPIKey() |
| 231 | + || !$this->configHelper->getSearchOnlyAPIKey()) { |
| 232 | + $configNotSet = true; |
| 233 | + } |
| 234 | + |
| 235 | + $linksTemplate = $this->getLinksTemplate($section); |
| 236 | + $videoTemplate = $this->getVideoTemplate($section, $configNotSet); |
| 237 | + $template = '<div class="algolia-admin-content-wrapper">'; |
| 238 | + $template .= $linksTemplate; |
| 239 | + $template .= $videoTemplate; |
| 240 | + $template .= '</div><br><hr><br>'; |
| 241 | + |
| 242 | + return $template; |
| 243 | + } |
| 244 | + |
| 245 | + protected function getVideoTemplate($section, $configNotSet) |
| 246 | + { |
| 247 | + $config = $this->getVideoConfig($section, $configNotSet); |
| 248 | + $template = ''; |
| 249 | + |
| 250 | + if (is_array($config)) { |
| 251 | + $template = '<div class="algolia-admin-content-videos"> |
| 252 | + <p> |
| 253 | + <span>Related video:</span> |
| 254 | + <a target="_blank" href="' . $config['url'] . '"><img src="' . $config['thumbnail'] . '"/></a> |
| 255 | + <a target="_blank" href="' . $config['url'] . '">' . $config['title'] . '</a> |
| 256 | + </p> |
| 257 | + </div>'; |
| 258 | + } |
| 259 | + |
| 260 | + return $template; |
| 261 | + } |
| 262 | + |
| 263 | + protected function getLinksTemplate($section) |
| 264 | + { |
| 265 | + $config = $this->getLinksConfig($section); |
| 266 | + $template = ''; |
| 267 | + |
| 268 | + if (is_array($config)) { |
| 269 | + $links = ''; |
| 270 | + $i = 0; |
| 271 | + foreach ($config as $link) { |
| 272 | + $links .= '<span><img src="' . $this->icons[$link['icon']] . '"/><a target="_blank" href="' . $link['url'] . '">' . $link['title'] . '</a></span>'; |
| 273 | + if ($i%2 == 1) { |
| 274 | + $links .= '<br/>'; |
| 275 | + } |
| 276 | + $i++; |
| 277 | + } |
| 278 | + |
| 279 | + $template = '<div class="algolia-admin-content-links"><p>' . $links . '</p></div>'; |
| 280 | + } |
| 281 | + |
| 282 | + return $template; |
| 283 | + } |
| 284 | +} |
0 commit comments