In the install function in the Bootstrap.php file I subscribed the $this->subscribeEvent( 'Enlight_Controller_Action_PostDispatchSecure_Frontend_Listing', 'onPostDispatchListing' ); event. After that in the onPostDispatchListing function I have:
/** @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;
The code is working and the products are filtered but the default filters do not work, like price filter etc..
Can someone help?
Your code can't use default filters, because you rewrite default article list.
$view->sArticles = $aProducts;
Note: in your query you don't check important cafeterias like:
As solution: you can subscribe these 2 events and add your query part:
$this->subscribeEvent(
'Shopware_Modules_Articles_GetArticleById_FilterSQL' => 'modifyQuery'
);
$this->subscribeEvent(
'Shopware_Modules_Articles_sGetArticlesByCategory_FilterSql' => 'modifyQuery'
);
Then check query and extend with your:
public function modifyQuery(\Enlight_Controller_ActionEventArgs $args)
{
$query = $args->getReturn();
//Do some modifications
$args->setReturn( $query );
return $args->getReturn();
}
Better way - add your criteria to shopware SearchBundle
Condition
, but this case require some research, you can start from this link.