示例#1
0
 protected function _toHtml()
 {
     $storeId = Mage::app()->getStore()->getId();
     if (AW_Productquestions_Helper_Data::isModuleOutputDisabled($storeId)) {
         return '';
     }
     if (!AW_Productquestions_Helper_Data::checkIfGuestsAllowed($storeId)) {
         return Mage::helper('productquestions')->getPleaseRegisterMessage($storeId);
     }
     if (!$this->getQuestionAuthorName() || !$this->getQuestionAuthorEmail()) {
         $customer = Mage::getSingleton('customer/session')->getCustomer();
         if ($customer && $customer->getId()) {
             if (!$this->getQuestionAuthorName()) {
                 // add logged in customer name as nickname
                 $this->setQuestionAuthorName($customer->getFirstname());
             }
             if (!$this->getQuestionAuthorEmail()) {
                 // add logged in customer email
                 $this->setQuestionAuthorEmail($customer->getEmail());
             }
         }
     }
     $product = Mage::helper('productquestions')->getCurrentProduct();
     if (!$product instanceof Mage_Catalog_Model_Product) {
         return '';
     }
     $this->setProduct($product);
     $data = Mage::getSingleton('core/session')->getProductquestionsData(true);
     if (is_array($data)) {
         $this->setData(array_merge($this->getData(), $data));
     }
     return parent::_toHtml();
 }
 protected function _toHtml()
 {
     if (AW_Productquestions_Helper_Data::isModuleOutputDisabled()) {
         return '';
     }
     $storeId = Mage::app()->getStore()->getId();
     $route = $this->getRequest()->getModuleName();
     if ($route != 'productquestions') {
         $this->_showLastX = (int) Mage::getStoreConfig('productquestions/interface/show_last_x', $storeId);
     }
     $this->setShowPager('productquestions' == $this->getRequest()->getModuleName() || !$this->_showLastX);
     if (false === $this->_prepareCollection()) {
         return '';
     }
     if ($sorter = $this->getLayout()->getBlock('productquestions_sorter')) {
         list($sortOrder, $sortDir) = $sorter->getCurrentSorting();
         if ($sortOrder) {
             $this->_collection = $this->_collection->applySorting($sortOrder, $sortDir);
         }
     }
     if ($this->getShowPager() && ($pager = $this->getLayout()->getBlock($this->_pagerName))) {
         $qid = $this->getQuestionId();
         if (null !== $qid && ($allIds = $this->_collection->getAllIdsFiltered())) {
             $pos = array_search($qid, $allIds);
             if (false !== $pos && ($pageSize = $pager->getLimit()) && $pageSize < count($allIds) && ($pageNum = 1 + (int) ($pos / $pageSize))) {
                 $this->getRequest()->setParam($pager->getPageVarName(), $pageNum);
             }
         }
         $this->_collection = $pager->setCollection($this->_collection)->getCollection();
     }
     $this->setVotingAllowed(Mage::getStoreConfig('productquestions/interface/guests_allowed_to_vote', $storeId) || Mage::getSingleton('customer/session')->isLoggedIn());
     return parent::_toHtml();
 }
示例#3
0
 protected function _toHtml()
 {
     if (AW_Productquestions_Helper_Data::isModuleOutputDisabled()) {
         return '';
     }
     $product = Mage::helper('productquestions')->getCurrentProduct(true);
     if (!$product instanceof Mage_Catalog_Model_Product) {
         return '';
     }
     $productId = $product->getId();
     $category = Mage::registry('current_category');
     if ($category instanceof Mage_Catalog_Model_Category) {
         $categoryId = $category->getId();
     } else {
         $categoryId = false;
     }
     $questionCount = Mage::getResourceModel('productquestions/productquestions_collection')->addProductFilter($productId)->addVisibilityFilter()->addAnsweredFilter()->addStoreFilter()->getSize();
     $params = array('id' => $productId);
     if ($categoryId) {
         $params['category'] = $categoryId;
     }
     $suffix = Mage::getStoreConfig('catalog/seo/category_url_suffix');
     /*if($urlKey = $product->getUrlKey())
       {
           $requestString = ltrim(Mage::app()->getFrontController()->getRequest()->getRequestString(), '/');
           
           $pqSuffix = $urlKey.$suffix;
           if($pqSuffix == substr($requestString, strlen($requestString)-strlen($pqSuffix)))
           {
               $requestString = substr($requestString, 0, strlen($requestString)-strlen($suffix));
               $this->setQuestionsPageUrl($this->getBaseUrl().$requestString.AW_Productquestions_Model_Urlrewrite::SEO_SUFFIX.$suffix);
           }
       }*/
     if (Mage::getStoreConfig('productquestions/seo/enable_url_rewrites')) {
         $productUrl = $product->getProductUrl();
         $fileExtentionPos = strrpos($productUrl, $suffix);
         $this->setQuestionsPageUrl(substr($productUrl, 0, $fileExtentionPos) . AW_Productquestions_Model_Urlrewrite::SEO_SUFFIX . $suffix);
     } else {
         $this->setQuestionsPageUrl(Mage::getUrl('productquestions/index/index/', $params));
     }
     $this->setQuestionCount($questionCount);
     return parent::_toHtml();
 }