Ejemplo n.º 1
0
    /**
     * Detail action method
     *
     * Contains the logic for the detail page of a blog article
     */
    public function detailAction()
    {
        $blogArticleId = intval($this->Request()->getQuery('blogArticle'));
        if (empty($blogArticleId)) {
            $this->forward("index", "index"); return;
        }

        $blogArticleQuery = $this->getRepository()->getDetailQuery($blogArticleId);
        $blogArticleData = $blogArticleQuery->getOneOrNullResult(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY);

        //load the right template
        if (!empty($blogArticleData['template'])) {
            $this->View()->loadTemplate('frontend/blog/' . $blogArticleData['template']);
        }

        if (!empty(Shopware()->Session()->sUserId) && empty($this->Request()->sVoteName)
            && $this->Request()->getParam('__cache') !== null) {
            $userData = Shopware()->Modules()->Admin()->sGetUserData();
            $this->View()->sFormData = array(
                'sVoteMail' => $userData['additional']['user']['email'],
                'sVoteName' => $userData['billingaddress']['firstname'] . ' ' . $userData['billingaddress']['lastname']
            );
        }

        //adding thumbnails to the blog article
        foreach ($blogArticleData["media"] as &$media) {
            if (!$media["preview"]) {
                /**@var $mediaModel \Shopware\Models\Media\Media*/
                $mediaModel = Shopware()->Models()->find('Shopware\Models\Media\Media', $media['mediaId']);
                if($mediaModel !== null) {
                    $media["thumbNails"] = array_values($mediaModel->getThumbnails());
                }
            } else {
                $blogArticleData["preview"] = $media;
                /**@var $mediaModel \Shopware\Models\Media\Media*/
                $mediaModel = Shopware()->Models()->find('Shopware\Models\Media\Media', $media['mediaId']);
                if($mediaModel !== null) {
                    $blogArticleData["preview"]["thumbNails"] = array_values($mediaModel->getThumbnails());
                }
            }
        }

        //add sRelatedArticles
        foreach ($blogArticleData["assignedArticles"] as &$assignedArticle) {
            $blogArticleData["sRelatedArticles"][] = Shopware()->Modules()->Articles()->sGetPromotionById('fix', 0, (int)$assignedArticle['id']);
        }

        //adding average vote data to the blog article
        $avgVoteQuery = $this->repository->getAverageVoteQuery($blogArticleId);
        $blogArticleData["sVoteAverage"] = $avgVoteQuery->getOneOrNullResult(\Doctrine\ORM\AbstractQuery::HYDRATE_SINGLE_SCALAR);

        //generate breadcrumb
        $breadcrumb = $this->getCategoryBreadcrumb($blogArticleData["categoryId"]);
        $blogDetailLink = $this->Front()->Router()->assemble(array(
            'sViewport' => 'blog', 'sCategory' => $blogArticleData["categoryId"],
            'action' => 'detail', 'blogArticle' => $blogArticleId
        ));

        $breadcrumb[] = array('link' => $blogDetailLink, 'name' => $blogArticleData['title']);

        $this->View()->assign(array('sBreadcrumb' => $breadcrumb, 'sArticle' => $blogArticleData, 'rand' => md5(uniqid(rand()))));
    }
Ejemplo n.º 2
0
 /**
  * Detail action method
  *
  * Contains the logic for the detail page of a blog article
  */
 public function detailAction()
 {
     $blogArticleId = intval($this->Request()->getQuery('blogArticle'));
     if (empty($blogArticleId)) {
         $this->forward("index", "index");
         return;
     }
     $blogArticleQuery = $this->getRepository()->getDetailQuery($blogArticleId);
     $blogArticleData = $blogArticleQuery->getOneOrNullResult(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY);
     //redirect if the blog item is not available
     if (empty($blogArticleData) || empty($blogArticleData["active"])) {
         return $this->redirect(array('controller' => 'index'), array('code' => 301));
     }
     // Redirect if category is not available, inactive or external
     /** @var $category \Shopware\Models\Category\Category */
     $category = $this->getCategoryRepository()->find($blogArticleData['categoryId']);
     if ($category === null || !$category->getActive()) {
         $location = array('controller' => 'index');
     }
     // Redirect if blog's category is not a child of the current shop's category
     $shopCategory = Shopware()->Shop()->getCategory();
     $isChild = $shopCategory && $category ? $category->isChildOf($shopCategory) : false;
     if (!$isChild) {
         $location = array('controller' => 'index');
     }
     if (isset($location)) {
         return $this->redirect($location, array('code' => 301));
     }
     //load the right template
     if (!empty($blogArticleData['template'])) {
         $this->View()->loadTemplate('frontend/blog/' . $blogArticleData['template']);
     }
     $this->View()->userLoggedIn = !empty(Shopware()->Session()->sUserId);
     if (!empty(Shopware()->Session()->sUserId) && empty($this->Request()->name) && $this->Request()->getParam('__cache') === null) {
         $userData = Shopware()->Modules()->Admin()->sGetUserData();
         $this->View()->sFormData = array('eMail' => $userData['additional']['user']['email'], 'name' => $userData['billingaddress']['firstname'] . ' ' . $userData['billingaddress']['lastname']);
     }
     $mediaIds = array_column($blogArticleData["media"], 'mediaId');
     $context = $this->get('shopware_storefront.context_service')->getShopContext();
     $mediaStructs = $this->get('shopware_storefront.media_service')->getList($mediaIds, $context);
     $mediaService = Shopware()->Container()->get('shopware_media.media_service');
     //adding thumbnails to the blog article
     foreach ($blogArticleData["media"] as &$media) {
         $mediaId = $media['mediaId'];
         $mediaData = $this->get('legacy_struct_converter')->convertMediaStruct($mediaStructs[$mediaId]);
         if ($media['preview']) {
             $blogArticleData["preview"] = $mediaData;
         }
         $media = array_merge($media, $mediaData);
         // @deprecated since 5.1 will be removed in 5.2
         $media['media']['path'] = $mediaService->getUrl($media['media']['path']);
     }
     //add sRelatedArticles
     foreach ($blogArticleData["assignedArticles"] as &$assignedArticle) {
         $product = Shopware()->Modules()->Articles()->sGetPromotionById('fix', 0, (int) $assignedArticle['id']);
         if ($product) {
             $blogArticleData["sRelatedArticles"][] = $product;
         }
     }
     //adding average vote data to the blog article
     $avgVoteQuery = $this->repository->getAverageVoteQuery($blogArticleId);
     $blogArticleData["sVoteAverage"] = $avgVoteQuery->getOneOrNullResult(\Doctrine\ORM\AbstractQuery::HYDRATE_SINGLE_SCALAR);
     //count the views of this blog item
     $visitedBlogItems = Shopware()->Session()->visitedBlogItems;
     if (!Shopware()->Session()->Bot && !in_array($blogArticleId, $visitedBlogItems)) {
         //update the views count
         /* @var $blogModel Shopware\Models\Blog\Blog */
         $blogModel = $this->getRepository()->find($blogArticleId);
         if ($blogModel) {
             $blogModel->setViews($blogModel->getViews() + 1);
             Shopware()->Models()->flush($blogModel);
             //save it to the session
             $visitedBlogItems[] = $blogArticleId;
             Shopware()->Session()->visitedBlogItems = $visitedBlogItems;
         }
     }
     //generate breadcrumb
     $breadcrumb = $this->getCategoryBreadcrumb($blogArticleData["categoryId"]);
     $blogDetailLink = $this->Front()->Router()->assemble(array('sViewport' => 'blog', 'sCategory' => $blogArticleData["categoryId"], 'action' => 'detail', 'blogArticle' => $blogArticleId));
     $breadcrumb[] = array('link' => $blogDetailLink, 'name' => $blogArticleData['title']);
     $this->View()->assign(array('sBreadcrumb' => $breadcrumb, 'sArticle' => $blogArticleData, 'rand' => md5(uniqid(rand()))));
 }