We are doing custom Magento themes, Magento design, custom Magento extensions and creative services through Magento designers & developers for worldwide shop owners.

Last News
Update you technique of search (Query.php,Fulltext.php,Advanced.php)

Update you technique of search (Query.php,Fulltext.php,Advanced.php)

If you want to make changes in the way of search inside Magento,by example you have private sales store , and you want hide many products , the customer can see all products just if is logging , ok you need rewrite this three main classes (tables) Fulltext.php Query.php Advanced.php and play with it.
it’s the code of rewriting

1
2
3
4
5
6
7
8
9
<models>
<catalogsearch_mysql4>
<rewrite>       <fulltext>Package_Module_Model_CatalogSearch_Mysql4_Fulltext</fulltext>         <query>Package_Module_Model_CatalogSearch_Mysql4_Query</query> </rewrite>
</catalogsearch_mysql4>
<catalogsearch>
<rewrite>       <advanced>Package_Module_Model_CatalogSearch_Advanced</advanced>
</rewrite>
</catalogsearch>
</models>

and by example you want change the structure of code inside Query.php ,and is related to the customer if is logging or not that is simple example :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
class Package_Module_Model_CatalogSearch_Mysql4_Query extends Mage_CatalogSearch_Model_Mysql4_Query
{



    public function loadByQuery(Mage_Core_Model_Abstract $object, $value)
    {


       $session = Mage::getSingleton('customer/session');
        if($session->isLoggedIn() == true)
        {
          $select = $this->_getReadAdapter()->select()
            ->from($this->getMainTable())
            ->where('synonym_for=? OR query_text=?', $value)
            ->where('caselog=?', '1')
            ->where('store_id=?', $object->getStoreId())
            ->order('synonym_for ASC')
            ->limit(1);

        }
        else
        {
          $select = $this->_getReadAdapter()->select()
            ->from($this->getMainTable())
            ->where('synonym_for=? OR query_text=?', $value)
            ->where('caselog=?', '0')
            ->where('store_id=?', $object->getStoreId())
            ->order('synonym_for ASC')
            ->limit(1);
        }

        if ($data = $this->_getReadAdapter()->fetchRow($select)) {
            $object->setData($data);
            $this->_afterLoad($object);
        }
        return $this;
    }
        /**
     * Custom load model only by query text (skip synonym for)
     *
     * @param Mage_Core_Model_Abstract $object
     * @param string $value
     * @return Mage_CatalogSearch_Model_Mysql4_Query
     */
    public function loadByQueryText(Mage_Core_Model_Abstract $object, $value)
    {
    
     $session = Mage::getSingleton('customer/session');
        if($session->isLoggedIn() == true)
        {
       $select = $this->_getReadAdapter()->select()
            ->from($this->getMainTable())
            ->where('query_text = ?', $value)
            ->where('caselog=?', '1')
            ->where('store_id = ?', $object->getStoreId())
            ->limit(1);
        }
        else
        {
       $select = $this->_getReadAdapter()->select()
            ->from($this->getMainTable())
            ->where('query_text = ?', $value)
            ->where('caselog=?', '0')
            ->where('store_id = ?', $object->getStoreId())
            ->limit(1);
        }

        if ($data = $this->_getReadAdapter()->fetchRow($select)) {
            $object->setData($data);
            $this->_afterLoad($object);
        }
        return $this;
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*