vijayrami

search.phtml

Jun 11th, 2020
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.11 KB | None | 0 0
  1. https://stackabuse.com/git-add-all-files-to-a-repo/
  2. https://magento.stackexchange.com/questions/130725/what-does-catalogimagesresize-do-in-magento-2
  3. https://stackoverflow.com/questions/58077394/set-all-owl-carousel-items-with-equal-height
  4. https://stackoverflow.com/questions/40442683/owl-carousel-2-nav-on-sides
  5. https://www.magesolution.com/google-recaptcha-for-magento-2.html
  6. https://www.magesolution.com/magento2-shop-by-brand.html
  7. <?php
  8. /**
  9.  * Mageplaza
  10.  *
  11.  * NOTICE OF LICENSE
  12.  *
  13.  * This source file is subject to the Mageplaza.com license that is
  14.  * available through the world-wide-web at this URL:
  15.  * https://www.mageplaza.com/LICENSE.txt
  16.  *
  17.  * DISCLAIMER
  18.  *
  19.  * Do not edit or add to this file if you wish to upgrade this extension to newer
  20.  * version in the future.
  21.  *
  22.  * @category    Mageplaza
  23.  * @package     Mageplaza_Search
  24.  * @copyright   Copyright (c) 2017 Mageplaza (http://www.mageplaza.com/)
  25.  * @license     https://www.mageplaza.com/LICENSE.txt
  26.  */
  27. // @codingStandardsIgnoreFile
  28. ?>
  29. <?php
  30. /** @var $block \Magento\Framework\View\Element\Template */
  31.  
  32. /** @var $helper \Mageplaza\Search\Helper\Data */
  33. $helper = $this->helper('Mageplaza\Search\Helper\Data');
  34. if ($helper->isEnabled()):
  35.     /** @var \Magento\Search\Helper\Data $searchHelper */
  36.     $searchHelper = $this->helper(\Magento\Search\Helper\Data::class);
  37.     ?>
  38.     <?php if ($helper->getConfigGeneral('category/enable')): ?>
  39.     <div class="search-category" style="position:absolute; top: 0; right: 35px; width: 130px">
  40.         <select id="mpsearch-category">
  41.             <?php foreach ($helper->getCategoryTree() as $id => $name): ?>
  42.                 <option value="<?php echo $id ?>"><?php echo $name ?></option>
  43.             <?php endforeach; ?>
  44.         </select>
  45.     </div>
  46.     <?php endif; ?>
  47.     <?php
  48.     $productList = [];
  49.     $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
  50.     $priceHelper = $objectManager->create('Magento\Framework\Pricing\Helper\Data'); // Instance of Pricing Helper
  51.     $storeManager  = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
  52.     $storeID       = $storeManager->getStore()->getStoreId();
  53.  
  54.    
  55.     $productCollectionFactory = $objectManager->get('\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');
  56.     $collection = $productCollectionFactory->create();
  57.     $collection->addAttributeToSelect('*');
  58.     foreach ($collection as $product) {
  59.             $productList[] = [
  60.                 'value' => $product->getName(),
  61.                 'c'     => $product->getCategoryIds(), //categoryIds
  62.                 'd'     => strip_tags($product->getShortDescription()), //short description
  63.                 'p'     => $priceHelper->currency($product->getFinalPrice(), true, false), //price
  64.                 'i'     => '',//image
  65.                 'u'     => '' //product url
  66.             ];
  67.         }
  68.     $json_product_list = json_encode($productList);
  69.     ?>
  70.     <script src="<?php echo $helper->getJsFileUrl(); ?>"></script>
  71.     <script type="text/javascript">
  72.     require([
  73.         'jquery',
  74.         'Magento_Catalog/js/price-utils',
  75.         'mpDevbridgeAutocomplete'
  76.     ], function ($, priceUtils) {
  77.         "use strict";
  78.         //var mageplazaSearchProducts = '<?php /*echo $json_product_list;*/ ?>';
  79.         var baseUrl = '<?php echo trim($block->getBaseUrl(), '/') . '/' ?>',
  80.             baseImageUrl = '<?php echo $helper->getMediaHelper()->getSearchMediaUrl() ?>',
  81.             priceFormat = <?php echo $helper->getPriceFormat() ?>,
  82.             displayInfo = <?php echo $helper->getDisplay() ?>;
  83.  
  84.         var categorySelect = $('#mpsearch-category'),
  85.             searchInput = $('#search');
  86.         if (categorySelect.length) {
  87.             categorySelect.on('change', function () {
  88.                 searchInput.focus();
  89.  
  90.                 if ($(this).val() === 0) {
  91.                     $(this).removeAttr('name');
  92.                 } else {
  93.                     $(this).attr('name', 'cat');
  94.                 }
  95.             });
  96.         }
  97.  
  98.         searchInput.devbridgeAutocomplete({
  99.             lookup: mageplazaSearchProducts,
  100.             lookupLimit: <?php  echo (int)$helper->getConfigGeneral('max_query_results') ?: 10; ?>,
  101.             maxHeight: 2000,
  102.             minChars: <?php echo $searchHelper->getMinQueryLength(); ?>,
  103.             lookupFilter: function (suggestion, query, queryLowerCase) {
  104.                 if (categorySelect.length) {
  105.                     var categoryId = categorySelect.val();
  106.                     if (categoryId > 0 && ($.inArray(categoryId, suggestion.c) === -1)) {
  107.                         return false;
  108.                     }
  109.                 }
  110.  
  111.                 return suggestion.value.toLowerCase().indexOf(queryLowerCase) !== -1;
  112.             },
  113.             onSelect: function (suggestion) {
  114.                 window.location.href = correctProductUrl(suggestion.u);
  115.             },
  116.             formatResult: function (suggestion, currentValue) {
  117.                 var html = '<a href="' + correctProductUrl(suggestion.u) + '">';
  118.  
  119.                 if ($.inArray('image', displayInfo) !== -1) {
  120.                     html += '<div class="suggestion-left"><img class="img-responsive" src="' + correctProductUrl(suggestion.i, true) + '" alt="" /></div>';
  121.                 }
  122.  
  123.                 html += '<div class="suggestion-right">';
  124.                 html += '<div class="product-line product-name">' + suggestion.value + '</div>';
  125.  
  126.                 if ($.inArray('price', displayInfo) !== -1) {
  127.                     html += '<div class="product-line product-price"><?php echo __('Price: ') ?>' + priceUtils.formatPrice(suggestion.p, priceFormat) + '</div>';
  128.                 }
  129.  
  130.                 if ($.inArray('description', displayInfo) !== -1 && suggestion.d) {
  131.                     html += '<div class="product-des"><p class="short-des">' + suggestion.d + '...</p></div>';
  132.                 }
  133.  
  134.                 html += '</div></a>';
  135.  
  136.                 return html;
  137.             }
  138.     //      onSearchComplete: function (query, suggestion) {
  139.     //          $('.autocomplete-suggestions').append("<div id='view_all'><a href='javascript:void(0)' id='search-view-all'>View all >></a></div>");
  140.     //          $('#search-view-all').on('click', function(){
  141.     //             $('#search_mini_form').submit();
  142.     //            });
  143.     //      }
  144.         });
  145.  
  146.         function correctProductUrl(urlKey, isImage) {
  147.             if (urlKey.search('http') !== -1) {
  148.                 return urlKey;
  149.             }
  150.  
  151.             return ((typeof isImage !== 'undefined') ? baseImageUrl : baseUrl) + urlKey;
  152.         }
  153.     });
  154.     </script>
  155. <?php endif; ?>
Add Comment
Please, Sign In to add comment