Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace VossMedienJvp;
- use Shopware\Bundle\SearchBundle\Condition\CategoryCondition;
- use Shopware\Bundle\SearchBundle\Criteria;
- use Shopware\Components\Plugin;
- use VossMedienJvp\SearchBundle\ManufacturerConditionHandler;
- use VossMedienJvp\SearchBundle\ManufacturerFacetHandler;
- class VossMedienJvp extends Plugin
- {
- public static function getSubscribedEvents()
- {
- return [
- 'Enlight_Controller_Action_PostDispatch_Frontend' => 'onPostDispatchFrontend',
- 'Enlight_Bootstrap_AfterInitResource_shopware_searchdbal.manufacturer_condition_handler_dbal' => 'decorateManufacturerConditionHandler',
- 'Enlight_Bootstrap_AfterInitResource_shopware_searchdbal.manufacturer_facet_handler_dbal' => 'decorateManufacturerFacetHandler',
- ];
- }
- public function decorateManufacturerConditionHandler()
- {
- Shopware()->Container()->set('shopware_searchdbal.manufacturer_condition_handler_dbal', new ManufacturerConditionHandler());
- }
- public function decorateManufacturerFacetHandler()
- {
- $c = Shopware()->Container();
- Shopware()->Container()->set('shopware_searchdbal.manufacturer_facet_handler_dbal', new ManufacturerFacetHandler(
- $c->get('shopware_storefront.manufacturer_service'),
- $c->get('shopware_searchdbal.dbal_query_builder_factory'),
- $c->get('snippets'),
- $c->get('query_alias_mapper')
- ));
- }
- public function onPostDispatchFrontend(\Enlight_Event_EventArgs $args)
- {
- /** @var \Enlight_Controller_Action $controller */
- $controller = $args->get('subject');
- $view = $controller->View();
- $container = Shopware()->Container();
- /** @var \Shopware\Bundle\SearchBundle\ProductSearch $searchService */
- $searchService = $container->get('shopware_search.product_search');
- /** @var \Shopware\Bundle\StoreFrontBundle\Service\ContextServiceInterface $contextService */
- $contextService = $container->get('shopware_storefront.context_service');
- $context = $contextService->getShopContext();
- $criteria = new Criteria();
- $criteria->removeBaseCondition('category');
- $criteria->resetFacets();
- $category = $context->getShop()->getCategory()->getId();
- $criteria->addBaseCondition(new CategoryCondition([$category]));
- $searchResult = $searchService->search($criteria, $context);
- $products = $searchResult->getProducts();
- usort($products, function ( $a, $b): int {
- return $a->getNumber() <=> $b->getNumber();
- });
- $view->assign('allShopProducts', $products);
- $controllerName = $controller->Request()->getParam('controller');
- if ($controllerName === 'detail') {
- $manufacturerGateway = $container->get('shopware_storefront.manufacturer_gateway');
- $sArticle = $view->getAssign('sArticle');
- if ($sArticle["attributes"]["core"]) {
- if ($supplierIds = $sArticle["attributes"]["core"]->get('jvp_autoren')) {
- foreach ($supplierIds as $k => $v) {
- $supplierIds[] = $v['id'];
- }
- $suppliers = $manufacturerGateway->getList($supplierIds, $context);
- $view->assign('authors', $suppliers);
- }
- }
- }
- if ($controllerName === 'cat' || $controllerName === 'listing') {
- $manufacturerGateway = $container->get('shopware_storefront.manufacturer_gateway');
- $sArticles = $view->getAssign('sArticles');
- foreach ($sArticles as &$sArticle) {
- if ($sArticle["attributes"]["core"]) {
- if ($supplierIds = $sArticle["attributes"]["core"]->get('jvp_autoren')) {
- foreach ($supplierIds as $k => $v) {
- $supplierIds[] = $v['id'];
- }
- $suppliers = $manufacturerGateway->getList($supplierIds, $context);
- $sArticle["authors"] = $suppliers;
- }
- }
- }
- $view->assign('sArticles', $sArticles);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement