本文整理匯總了PHP中Varien_Event_Observer::getCatalogsearchQuery方法的典型用法代碼示例。如果您正苦於以下問題:PHP Varien_Event_Observer::getCatalogsearchQuery方法的具體用法?PHP Varien_Event_Observer::getCatalogsearchQuery怎麽用?PHP Varien_Event_Observer::getCatalogsearchQuery使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Varien_Event_Observer
的用法示例。
在下文中一共展示了Varien_Event_Observer::getCatalogsearchQuery方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: saveProductsPositions
/**
* Append products positions to the current search term if needed
*
* @param Varien_Event_Observer $observer The observer
*
* @event catalogsearch_query_save_after
*
* @return void Nothing
*/
public function saveProductsPositions(Varien_Event_Observer $observer)
{
$searchTerm = $observer->getCatalogsearchQuery();
$positions = $searchTerm->getData("position");
if (!is_array($positions)) {
$positions = array();
}
$filteredPositions = array_filter($positions, 'is_numeric');
$resourceModel = Mage::getResourceModel("smile_elasticsearch/search_term_product_position");
$previousProducts = $resourceModel->getProductIdsByQuery($searchTerm);
$resourceModel->saveProductsPositions($filteredPositions, $searchTerm);
$productIdsToReindex = array_unique(array_merge($previousProducts, array_keys($filteredPositions)));
// If Enterprise version, Mview index will handle editing, otherwise, process reindex
if (!Mage::helper("smile_elasticsearch")->isEnterpriseSupportEnabled()) {
Mage::getSingleton('index/indexer')->processEntityAction($searchTerm->setProductIds($productIdsToReindex), Smile_ElasticSearch_Model_Indexer_Search_Terms_Position::ENTITY, Mage_Index_Model_Event::TYPE_SAVE);
} else {
$helper = Mage::helper('smile_elasticsearch/index');
if ($helper->isLiveProductPositionInSearchReindexEnabled()) {
$client = Mage::getModel('enterprise_mview/client');
$client->init(Mage::helper('enterprise_index')->getIndexerConfigValue('search_term_product_position', 'index_table'));
$arguments = array('value' => $productIdsToReindex);
$client->execute('smile_elasticsearch/index_action_search_terms_refresh_row', $arguments);
}
}
}
示例2: saveRecommendations
/**
* Save admin selected recommendations
*
* @see catalogsearch_query_save_after
* @param Varien_Event_Observer $observer
*/
public function saveRecommendations($observer)
{
try {
$query = $observer->getCatalogsearchQuery();
$request = Mage::app()->getRequest();
$selectedProducts = $request->getParam('grid_selected_products');
$selectedProducts = explode('&', $selectedProducts);
if (is_array($selectedProducts) && count($selectedProducts) > 0) {
$recommendationsData = array();
foreach ($selectedProducts as $selectedProduct) {
$selectedProduct = explode('=', $selectedProduct);
if (is_array($selectedProduct) && count($selectedProduct) > 1) {
$productId = $selectedProduct[0];
$params = urldecode($selectedProduct[1]);
$params = @base64_decode($params, true);
$params = explode('=', $params);
if (is_array($params) && count($params) > 0) {
$position = (int) $params[1];
$recommendationsData[] = array('query_id' => $query->getId(), 'product_id' => $productId, 'position' => $position, 'date_recommended' => date('Y-m-d H:i:s'));
}
}
}
if (is_array($recommendationsData) && count($recommendationsData) > 0) {
$collection = Mage::getModel('autocompleterecommendations/recommendation')->getCollection();
$collection->addFieldToFilter('query_id', $query->getId());
foreach ($collection as $recommendation) {
$recommendation->delete();
}
foreach ($recommendationsData as $data) {
$recommendation = Mage::getModel('autocompleterecommendations/recommendation');
$recommendation->setData($data);
$recommendation->save();
}
}
}
} catch (Exception $e) {
Mage::log($e->getMessage, null, 'extensions_store_autocompleterecommendations.log');
}
}