Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://stackabuse.com/git-add-all-files-to-a-repo/
- https://magento.stackexchange.com/questions/130725/what-does-catalogimagesresize-do-in-magento-2
- https://stackoverflow.com/questions/58077394/set-all-owl-carousel-items-with-equal-height
- https://stackoverflow.com/questions/40442683/owl-carousel-2-nav-on-sides
- https://www.magesolution.com/google-recaptcha-for-magento-2.html
- https://www.magesolution.com/magento2-shop-by-brand.html
- <?php
- /**
- * Mageplaza
- *
- * NOTICE OF LICENSE
- *
- * This source file is subject to the Mageplaza.com license that is
- * available through the world-wide-web at this URL:
- * https://www.mageplaza.com/LICENSE.txt
- *
- * DISCLAIMER
- *
- * Do not edit or add to this file if you wish to upgrade this extension to newer
- * version in the future.
- *
- * @category Mageplaza
- * @package Mageplaza_Search
- * @copyright Copyright (c) 2017 Mageplaza (http://www.mageplaza.com/)
- * @license https://www.mageplaza.com/LICENSE.txt
- */
- // @codingStandardsIgnoreFile
- ?>
- <?php
- /** @var $block \Magento\Framework\View\Element\Template */
- /** @var $helper \Mageplaza\Search\Helper\Data */
- $helper = $this->helper('Mageplaza\Search\Helper\Data');
- if ($helper->isEnabled()):
- /** @var \Magento\Search\Helper\Data $searchHelper */
- $searchHelper = $this->helper(\Magento\Search\Helper\Data::class);
- ?>
- <?php if ($helper->getConfigGeneral('category/enable')): ?>
- <div class="search-category" style="position:absolute; top: 0; right: 35px; width: 130px">
- <select id="mpsearch-category">
- <?php foreach ($helper->getCategoryTree() as $id => $name): ?>
- <option value="<?php echo $id ?>"><?php echo $name ?></option>
- <?php endforeach; ?>
- </select>
- </div>
- <?php endif; ?>
- <?php
- $productList = [];
- $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
- $priceHelper = $objectManager->create('Magento\Framework\Pricing\Helper\Data'); // Instance of Pricing Helper
- $storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
- $storeID = $storeManager->getStore()->getStoreId();
- $productCollectionFactory = $objectManager->get('\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');
- $collection = $productCollectionFactory->create();
- $collection->addAttributeToSelect('*');
- foreach ($collection as $product) {
- $productList[] = [
- 'value' => $product->getName(),
- 'c' => $product->getCategoryIds(), //categoryIds
- 'd' => strip_tags($product->getShortDescription()), //short description
- 'p' => $priceHelper->currency($product->getFinalPrice(), true, false), //price
- 'i' => '',//image
- 'u' => '' //product url
- ];
- }
- $json_product_list = json_encode($productList);
- ?>
- <script src="<?php echo $helper->getJsFileUrl(); ?>"></script>
- <script type="text/javascript">
- require([
- 'jquery',
- 'Magento_Catalog/js/price-utils',
- 'mpDevbridgeAutocomplete'
- ], function ($, priceUtils) {
- "use strict";
- //var mageplazaSearchProducts = '<?php /*echo $json_product_list;*/ ?>';
- var baseUrl = '<?php echo trim($block->getBaseUrl(), '/') . '/' ?>',
- baseImageUrl = '<?php echo $helper->getMediaHelper()->getSearchMediaUrl() ?>',
- priceFormat = <?php echo $helper->getPriceFormat() ?>,
- displayInfo = <?php echo $helper->getDisplay() ?>;
- var categorySelect = $('#mpsearch-category'),
- searchInput = $('#search');
- if (categorySelect.length) {
- categorySelect.on('change', function () {
- searchInput.focus();
- if ($(this).val() === 0) {
- $(this).removeAttr('name');
- } else {
- $(this).attr('name', 'cat');
- }
- });
- }
- searchInput.devbridgeAutocomplete({
- lookup: mageplazaSearchProducts,
- lookupLimit: <?php echo (int)$helper->getConfigGeneral('max_query_results') ?: 10; ?>,
- maxHeight: 2000,
- minChars: <?php echo $searchHelper->getMinQueryLength(); ?>,
- lookupFilter: function (suggestion, query, queryLowerCase) {
- if (categorySelect.length) {
- var categoryId = categorySelect.val();
- if (categoryId > 0 && ($.inArray(categoryId, suggestion.c) === -1)) {
- return false;
- }
- }
- return suggestion.value.toLowerCase().indexOf(queryLowerCase) !== -1;
- },
- onSelect: function (suggestion) {
- window.location.href = correctProductUrl(suggestion.u);
- },
- formatResult: function (suggestion, currentValue) {
- var html = '<a href="' + correctProductUrl(suggestion.u) + '">';
- if ($.inArray('image', displayInfo) !== -1) {
- html += '<div class="suggestion-left"><img class="img-responsive" src="' + correctProductUrl(suggestion.i, true) + '" alt="" /></div>';
- }
- html += '<div class="suggestion-right">';
- html += '<div class="product-line product-name">' + suggestion.value + '</div>';
- if ($.inArray('price', displayInfo) !== -1) {
- html += '<div class="product-line product-price"><?php echo __('Price: ') ?>' + priceUtils.formatPrice(suggestion.p, priceFormat) + '</div>';
- }
- if ($.inArray('description', displayInfo) !== -1 && suggestion.d) {
- html += '<div class="product-des"><p class="short-des">' + suggestion.d + '...</p></div>';
- }
- html += '</div></a>';
- return html;
- }
- // onSearchComplete: function (query, suggestion) {
- // $('.autocomplete-suggestions').append("<div id='view_all'><a href='javascript:void(0)' id='search-view-all'>View all >></a></div>");
- // $('#search-view-all').on('click', function(){
- // $('#search_mini_form').submit();
- // });
- // }
- });
- function correctProductUrl(urlKey, isImage) {
- if (urlKey.search('http') !== -1) {
- return urlKey;
- }
- return ((typeof isImage !== 'undefined') ? baseImageUrl : baseUrl) + urlKey;
- }
- });
- </script>
- <?php endif; ?>
Add Comment
Please, Sign In to add comment