在Bootstrap.php文件的install函数中,我订阅了 $这 - > subscribeEvent( 'Enlight_Controller_Action_PostDispatchSecure_Frontend_Listing', 'onPostDispatchListing' ); 事件。之后在onPostDispatchListing函数中我有:
/** @var \Enlight_Controller_Action $controller */
$controller = $args->getSubject();
$request = $controller->Request();
// defines the default shopware VIEWS directory.
$view = $controller->View();
$view->addTemplateDir(
__DIR__ . '/Views/responsive'
);
$shop = Shopware()->Shop();
$sCategorystart = $shop->getCategory()->getId();
$sCategoryID = $this->getCategoryCurrent($sCategorystart);
$oDb = Shopware()->Db();
$EngineCode = $request->getParam('sVehicle');
$query = "SELECT va.`articleID`
FROM `s_vehicle_articles` as va
INNER JOIN `s_articles_categories` as ac ON
ac.articleID=va.articleID
WHERE ac.categoryID=" . $sCategoryID;
$query .= ($EngineCode) ? " AND va.`VehicleCodeID`= '" . $EngineCode . "'" : " ";
$mResults = $oDb->fetchAll($query);
$articleModule = Shopware()->Modules()->Articles();
$aProducts = array();
foreach ($mResults as $key => $value) {
$article = $articleModule->sGetArticleById($value['articleID'], $sCategoryID);
$aProducts[] = $article;
}
$view->sArticles = $aProducts;
代码正常运行且产品已过滤,但默认过滤器不起作用,例如价格过滤等。
有人可以帮忙吗?
答案 0 :(得分:1)
您的代码无法使用默认过滤器,因为您重写了默认文章列表。
$view->sArticles = $aProducts;
注意:在您的查询中,您不会检查重要的自助餐厅,如:
作为解决方案:您可以订阅这两个事件并添加您的查询部分:
$this->subscribeEvent(
'Shopware_Modules_Articles_GetArticleById_FilterSQL' => 'modifyQuery'
);
$this->subscribeEvent(
'Shopware_Modules_Articles_sGetArticlesByCategory_FilterSql' => 'modifyQuery'
);
然后检查查询并使用以下内容进行扩展:
public function modifyQuery(\Enlight_Controller_ActionEventArgs $args)
{
$query = $args->getReturn();
//Do some modifications
$args->setReturn( $query );
return $args->getReturn();
}
更好的方法 - 将您的条件添加到商品SearchBundle
Condition
,但这种情况需要进行一些研究,您可以从this link开始。