本文整理匯總了PHP中Varien_Event_Observer::getQuery方法的典型用法代碼示例。如果您正苦於以下問題:PHP Varien_Event_Observer::getQuery方法的具體用法?PHP Varien_Event_Observer::getQuery怎麽用?PHP Varien_Event_Observer::getQuery使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Varien_Event_Observer
的用法示例。
在下文中一共展示了Varien_Event_Observer::getQuery方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: modifyQuery
/**
* Called before a query is executed. Modifies the query to add sorting
* parameters.
*
* @param Varien_Event_Observer $observer Observer/event data
* @throws InvalidArgumentException for invalid dir and order parameters
*/
public function modifyQuery(Varien_Event_Observer $observer)
{
// get query part from current URL
$urlQuery = Mage::getModel('core/url')->getRequest()->getQuery();
if (!array_key_exists('order', $urlQuery)) {
return;
}
$direction = $urlQuery['dir'];
$field = $urlQuery['order'];
if (!in_array($direction, $this->directions)) {
throw new InvalidArgumentException('Invalid sort direction parameter "' . $direction . '", must be asc or desc.', 1397868721);
}
if (array_key_exists($field, $this->sortAttributes)) {
if ($field == 'relevance') {
$sortField = 'relevance';
} else {
if ($field == 'name') {
$sortField = 'sortTitle';
} else {
$sortField = Mage::helper('solr/schema')->getFieldNameByAttribute($field);
}
}
/** @var Asm_Solr_Model_Solr_Query $query */
$query = $observer->getQuery();
$query->setSorting($sortField . ' ' . $direction);
} else {
throw new InvalidArgumentException('No sortable attribute found for sort parameter ' . $field, 1397868606);
}
}
示例2: modifyQuery
/**
* Called before a query is executed. Modifies the query to add faceting
* parameters.
*
* @param Varien_Event_Observer $observer Observer/event data
*/
public function modifyQuery(Varien_Event_Observer $observer)
{
/** @var Asm_Solr_Model_Solr_Query $query */
$query = $observer->getQuery();
$query->setFaceting();
$this->filterableAttributes = $this->getFilterableAttributes();
// set facet.* query parameters / which facets to generate
foreach ($this->filterableAttributes as $attribute) {
$query->addFacetField(Mage::helper('solr/schema')->getFieldNameByAttribute($attribute));
}
// set filter query (fq) parameters / actually filtering results
$filters = $this->getQueryFilters();
foreach ($filters as $fieldName => $value) {
$query->addFilter($fieldName, $value);
}
}