app/ 000777 00000000000 12315450314 0005206 5 ustar app/code/ 000777 00000000000 12315450314 0006120 5 ustar app/code/community/ 000777 00000000000 12315450314 0010144 5 ustar app/code/community/LitExtension/ 000777 00000000000 12315450314 0012571 5 ustar app/code/community/LitExtension/AjaxSearch/ 000777 00000000000 12315450314 0014602 5 ustar app/code/community/LitExtension/AjaxSearch/Helper/ 000777 00000000000 12315450314 0016021 5 ustar app/code/community/LitExtension/AjaxSearch/Helper/Data.php 000666 00000000360 12315450314 0017402 0 ustar getSelect()->joinLeft(array('urwr' => $this->getTable('core/url_rewrite')), '(urwr.product_id=e.entity_id) AND (urwr.store_id=' . $this->getStoreId() . ')', array('request_path')); return $this; } /** * Selecting products from multiple categories * @param string $categories categories list separated by commas * @return AW_Autorelated_Model_Product_Collection */ public function addCategoriesFilter($categories, $includeSubCategories = false) { if (!is_array($categories)) $categories = @explode(',', $categories); $sqlCategories = array(); if ($includeSubCategories) { foreach ($categories as $categoryId) { $category = Mage::getModel('catalog/category')->load($categoryId); $sqlCategories = array_merge($sqlCategories, $category->getAllChildren(true)); } } else { $sqlCategories = $categories; } $sqlCategories = array_unique($sqlCategories); if (is_array($sqlCategories)) $categories = @implode(',', $sqlCategories); $alias = 'cat_index'; $categoryCondition = $this->getConnection()->quoteInto( $alias . '.product_id=e.entity_id' . ($includeSubCategories ? '' : ' AND ' . $alias . '.is_parent=1') . ' AND ' . $alias . '.store_id=? AND ', $this->getStoreId()); $categoryCondition.= $alias . '.category_id IN (' . $categories . ')'; $this->getSelect()->joinInner( array($alias => $this->getTable('catalog/category_product_index')), $categoryCondition, array('position' => 'position') ); $this->_categoryIndexJoined = true; $this->_joinFields['position'] = array('table' => $alias, 'field' => 'position'); return $this; } public function addFilterByIds($ids) { if ($ids) { $whereString = '(e.entity_id IN ('; $whereString .= implode(',', $ids); $whereString .= '))'; $this->getSelect()->where($whereString); } return $this; } /** * Covers bug in Magento function * @return Varien_Db_Select */ public function getSelectCountSql() { $catalogProductFlatHelper = Mage::helper('catalog/product_flat'); if ($catalogProductFlatHelper && $catalogProductFlatHelper->isEnabled()) return parent::getSelectCountSql(); $this->_renderFilters(); $countSelect = clone $this->getSelect(); return $countSelect->reset()->from($this->getSelect(), array())->columns('COUNT(*)'); } } app/code/community/LitExtension/AjaxSearch/Model/System/ 000777 00000000000 12315450314 0017126 5 ustar app/code/community/LitExtension/AjaxSearch/Model/System/Config/ 000777 00000000000 12315450314 0020333 5 ustar app/code/community/LitExtension/AjaxSearch/Model/System/Config/Source/ 000777 00000000000 12315450314 0021573 5 ustar app/code/community/LitExtension/AjaxSearch/Model/System/Config/Source/Attribute.php 000666 00000014316 12315450314 0024254 0 ustar getConnection('core_read'); $select = $db->select() ->from($resource->getTableName('eav/entity_type'), 'entity_type_id') ->where('entity_type_code=?', 'catalog_product') ->limit(1); self::$_entityTypeId = $db->fetchOne($select); $select = $db->select() ->from($resource->getTableName('eav/attribute'), array( 'title' => 'frontend_label', // for admin part 'id' => 'attribute_id', // for applying filter to collection 'code' => 'attribute_code', // as a tip for constructing {attribute_name} 'type' => 'backend_type', // for table name )) ->where('entity_type_id=?', self::$_entityTypeId) ->where('frontend_label<>""') ->orWhere('attribute_code=?', "manufacturer") //add new attribute in backend ->where('find_in_set(backend_type, "text,varchar,static")') ->order('frontend_label'); foreach($db->fetchAll($select) as $v) self::$_productAttributes[$v['id']] = array( 'title' => $v['title'], 'code' => $v['code'], 'type' => $v['type'], ); return self::$_productAttributes; } public static function getProductIds2($query, $storeId){ $resource = Mage::getSingleton('core/resource'); $db = $resource->getConnection('core_read'); $select = $db->select(); $fullTextTable = $resource->getTableName('catalogsearch/fulltext'); $select->from($fullTextTable, 'product_id') ->where('store_id = ?',$storeId) ->where('data_index LIKE "%'.$query.'%"'); $result = $db->fetchCol($select); // var_dump($result); return $result; } public static function getProductIds($attributes, $attrValues, $storeId) { $ids = array(); if(empty($attributes)) return $ids; $resource = Mage::getSingleton('core/resource'); $db = $resource->getConnection('core_read'); // list of tables used for selecting $usedTables = array(); foreach($attributes as $attrId => $attrType) $usedTables[$attrType] = true; foreach(array_keys($usedTables) as $tableName) { if ($tableName != 'static') { $select = $db->select(); if ($tableName == 'int') { $eaov = $resource->getTableName('eav/attribute_option_value'); $cpei = $resource->getTableName('catalog/product') . '_' . $tableName; //SQL // SELECT cpei.entity_id from catalog_product_entity_int AS cpei // JOIN eav_attribute_option_value AS eaov // ON cpei.`value` = eaov.option_id // WHERE eaov.`value` Like '%str%' $select->from(array('cpei' => $cpei), array('cpei.entity_id')) ->join(array('eaov' => $eaov), 'cpei.`value` = eaov.option_id', array()) ->where('cpei.entity_type_id=?', self::$_entityTypeId) ->where('cpei.store_id=0 OR cpei.store_id=?', $storeId) ->where('cpei.attribute_id IN (' . implode(',', array_keys($attributes)) . ')'); foreach ($attrValues as $value) $select ->where('eaov.`value` LIKE "%' . addslashes($value) . '%"'); } else { $select ->distinct() ->from($resource->getTableName('catalog/product') . '_' . $tableName, 'entity_id') ->where('entity_type_id=?', self::$_entityTypeId) ->where('store_id=0 OR store_id=?', $storeId) ->where('attribute_id IN (' . implode(',', array_keys($attributes)) . ')'); foreach ($attrValues as $value) $select->where('`value` LIKE "%' . addslashes($value) . '%"'); } $ids = array_merge($ids, $db->fetchCol($select)); } if ($tableName == 'static') { $select = $db->select(); $select ->distinct() ->from($resource->getTableName('catalog/product'), 'entity_id') ->where('entity_type_id=?', self::$_entityTypeId); foreach ($attrValues as $value) $select->where('`sku` LIKE "%' . addslashes($value) . '%"'); $ids = array_merge($ids, $db->fetchCol($select)); } } if(!(Mage::getStoreConfig('ajaxsearch/general/showoosp'))&& !empty($ids)){ $select = $db->select(); $select ->from($resource->getTableName('cataloginventory/stock_status'), 'product_id') ->where('product_id IN ('.implode(',',$ids).') AND stock_status = 1'); $ids = $db->fetchCol($select); } return array_unique($ids); } public static function toOptionArray() { if(is_array(self::$_productAttributeOptions)) return self::$_productAttributeOptions; self::$_productAttributeOptions = array(); foreach(self::getProductAttributeList() as $id => $data) self::$_productAttributeOptions[] = array( 'value' => $id, 'label' => $data['title'] ); return self::$_productAttributeOptions; } } app/code/community/LitExtension/AjaxSearch/Model/System/Config/Source/Info.php 000666 00000001347 12315450314 0023204 0 ustar 'shortdecs', 'label' => Mage::helper('ajaxsearch')->__('Short Description')), array('value' => 'price', 'label' => Mage::helper('ajaxsearch')->__('Price')), ); } public function toArray() { return array( 'shortdecs' => Mage::helper('adminhtml')->__('Short Description'), 'price' => Mage::helper('adminhtml')->__('Price'), ); } } app/code/community/LitExtension/AjaxSearch/controllers/ 000777 00000000000 12315450314 0017150 5 ustar app/code/community/LitExtension/AjaxSearch/controllers/AjaxController.php 000666 00000030013 12315450314 0022605 0 ustar $pos ) { $nearestPos = $pos; $nearestWord = substr($haystack, $pos, strlen($needle)); } if ($nearestWord) return array('pos' => $nearestPos, 'word' => $nearestWord); else return false; } public static function decorateWords($words, $subject, $before, $after) { $replace = array(); for ($pos = 0; $pos < strlen($subject) && (false !== $nearest = self::findNearest($subject, $words, $pos));) { $replace[$nearest['pos']] = $nearest['word']; $pos = $nearest['pos'] + strlen($nearest['word']); } $res = ''; $pos = 0; foreach ($replace as $start => $word) { $res .= substr($subject, $pos, $start - $pos) . $before . $word . $after; $pos = $start + strlen($word); } $res .= substr($subject, $pos); return $res; } protected function _prepareCollection() { $collection = Mage::getModel('ajaxsearch/product'); $collection->addAttributeToSelect('*'); return $collection; } protected function _postProcessCollection() { $this->_collection->addUrlRewrites() ->addMinimalPrice() ->addFinalPrice() ->groupByAttribute('entity_id'); return $this; } public function indexAction() { $numproducts = Mage::getStoreConfig('ajaxsearch/general/showprod'); $linknewtab = Mage::getStoreConfig('ajaxsearch/general/linknewtab'); $imagesize = Mage::getStoreConfig('ajaxsearch/general/imagesize'); $showinfo = Mage::getStoreConfig('ajaxsearch/general/showinfo'); $message_default = Mage::getStoreConfig('ajaxsearch/general/no_result_message'); $search_in_categories = Mage::getStoreConfig('ajaxsearch/general/search_in_categories'); $highlight = Mage::getStoreConfig('ajaxsearch/general/highlight'); if (!is_numeric($numproducts)) $numproducts = 6; if (!is_numeric($imagesize)) $imagesize = 85; if ($linknewtab == 1) { $blank = ' target="_blank"'; } else { $blank = ''; } if (isset($_POST['key']) && $_POST['key'] != '') { $sta = true; $html = ""; $qParam = $_POST['key']; $storeId = Mage::app()->getStore()->getId(); $q = Mage::helper('core')->htmlEscape($qParam); $q = htmlspecialchars_decode($q); $allAttributes = LitExtension_AjaxSearch_Model_System_Config_Source_Attribute::getProductAttributeList(); $searchedWords = explode(' ', trim($q)); for ($i = 0; $i < count($searchedWords); $i++) { if (strlen($searchedWords[$i]) < 2 || preg_match('(:)', $searchedWords[$i])) unset($searchedWords[$i]); } if (is_null($this->_collection) || !$this->_collection) { $this->_collection = $this->_prepareCollection(); $fulltext = false; $searchableAttributes = explode(',', Mage::getStoreConfig('ajaxsearch/general/attrsearch')); $attributes = array(); foreach ($searchableAttributes as $attrId) { if (array_key_exists($attrId, $allAttributes)) $attributes[$attrId] = $allAttributes[$attrId]['type']; $aasd = Mage::getModel('eav/entity_attribute')->load($attrId); if ($aasd->getData('frontend_input') == self::TEXTAREA_CODE) { if ($aasd->getData('is_searchable') == self::SEARCHABLE_STATUS) { $fulltext = true; } } } $productIds = false; try { if ($fulltext) { $productIds = LitExtension_AjaxSearch_Model_System_Config_Source_Attribute::getProductIds($attributes, $searchedWords, $storeId); } else { $productIds = LitExtension_AjaxSearch_Model_System_Config_Source_Attribute::getProductIds2($q, $storeId); } } catch (Exception $e) { } if (!$productIds || empty($productIds)) { $sta = false; }else{ $this->_collection->addFilterByIds($productIds); $visibility = array(Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_SEARCH, Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH); $this->_collection ->addStoreFilter($storeId) ->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED) ->setVisibility($visibility); } } $this->_postProcessCollection(); $this->_collection->setPageSize($numproducts); if ($search_in_categories == 1) { $ret_cat = array(); $ret_cat[] = array( 'attribute' => 'name', 'like' => '%' . $q . '%', ); $collection_cat = Mage::getModel('catalog/category')->getCollection() ->addAttributeToSelect("*") ->addAttributeToFilter($ret_cat); } if (count($this->_collection) <= 0 && count($collection_cat) <= 0) { $sta = false; } if ($sta == false) { $html .= "
' . $formattedPrice . '
'; } else { $html .= 'Regular Price: ' . $formattedPrice . '
Special Price: ' . $special_price . '
'; } } if (strpos($showinfo, 'shortdecs') !== false) { $html .= '' . $short_desc . '
'; } $html .= '