bootstrap = $bootstrap; } /** * Return the subscribed controller events. * * @return array */ public static function getSubscribedEvents() { // return the events return array( 'Shopware_Components_Document::setDocumentId::before' => "beforeDocumentSetDocumentIdHook", 'Shopware_Components_Document::assignValues::after' => "afterDocumentAssignValuesHook", 'Theme_Inheritance_Template_Directories_Collected' => "onCollectDirectoriesEvent" ); } /** * Add our document path. * * @param \Enlight_Event_EventArgs $args * * @return array */ public function onCollectDirectoriesEvent( \Enlight_Event_EventArgs $args ) { // get the current directories $directories = $args->getReturn(); // add our own array_push( $directories, $this->bootstrap->Path() . "Views/" ); // and we re done return $directories; } /** * ... * * @param \Enlight_Hook_HookArgs $args * * @return void */ public function beforeDocumentSetDocumentIdHook( \Enlight_Hook_HookArgs $args ) { // just save the document id self :: $documentId = $args->get( "id" ); // and we re done return; } /** * ... * * @param \Enlight_Hook_HookArgs $args * * @return void */ public function afterDocumentAssignValuesHook( \Enlight_Hook_HookArgs $args ) { // is this our document?! if ( self :: $documentId != 5 ) // nothing to do here return; // get the controller $document = $args->getSubject(); // get the view $view = $document->_view; // get the pages $pages = $view->getTemplateVars( "Pages" ); // loop all articles within the first page (for now) foreach ( $pages[0] as &$article ) { // set a default value $article['atsdLocation'] = ""; // get the article model $model = Shopware()->Models()->find( '\Shopware\Models\Article\Article', (integer) $article['articleID'] ); // not found?! if ( !$model instanceof \Shopware\Models\Article\Article ) // weird continue; // find the location for it $location = Shopware()->Models() ->getRepository( '\Shopware\CustomModels\AtsdWarehouse\Warehouse\Location\Location' ) ->findOneLocationByArticle( $model ); // we found no location if ( !is_array( $location ) ) // next one continue; // set it $article['atsdLocation'] = $location['shelf']['store']['identifier'] . " " .$location['shelf']['identifier'] . " " . $location['positionY'] . "-" . $location['positionX']; } // now sort it $this->array_sort_by_column( $pages[0], "atsdLocation" ); // assign it again $view->assign( "Pages", $pages ); // and we re done return; } /** * Sort an array by its column. * * @param array $arr * @param string $col * @param int|string $dir * * @return void */ public function array_sort_by_column( &$arr, $col, $dir = SORT_ASC ) { $sort_col = array(); foreach ($arr as $key=> $row) $sort_col[$key] = $row[$col]; array_multisort($sort_col, $dir, $arr); } }