2015-04-06 108 views
1

我已经为产品添加了特价。它在产品详细信息页面上显示特价,但未在类别页面上显示。如果我在list.phtml上调用specialprice而不是仅显示0.我认为需要在list.php中进行一些更改。特价没有在分类页面上显示

代码低于: - 在list.php的我的作用是

protected function _getProductCollection() 
    { 
     if (is_null($this->_productCollection)) { 
      $layer = $this->getLayer(); 
      /* @var $layer Mage_Catalog_Model_Layer */ 
      if ($this->getShowRootCategory()) { 
       $this->setCategoryId(Mage::app()->getStore()->getRootCategoryId()); 
      } 

      // if this is a product view page 
      if (Mage::registry('product')) { 
       // get collection of categories this product is associated with 
       $categories = Mage::registry('product')->getCategoryCollection() 
        ->setPage(1, 1) 
        ->load(); 
       // if the product is associated with any category 
       if ($categories->count()) { 
        // show products from this category 
        $this->setCategoryId(current($categories->getIterator())); 
       } 
      } 

      $origCategory = null; 
      if ($this->getCategoryId()) { 
       $category = Mage::getModel('catalog/category')->load($this->getCategoryId()); 
       if ($category->getId()) { 
        $origCategory = $layer->getCurrentCategory(); 
        $layer->setCurrentCategory($category); 
        $this->addModelTags($category); 
       } 
      } 

      $this->_productCollection = $layer->getProductCollection(); 

      $this->prepareSortableFieldsByCategory($layer->getCurrentCategory()); 

      if ($origCategory) { 
       $layer->setCurrentCategory($origCategory); 
      } 



     } 


     return $this->_productCollection; 
    } 

list.phtml

<?php 
     $_productCollection=$this->getLoadedProductCollection(); 
     $_helper = $this->helper('catalog/output'); 

      <?php // Grid Mode ?> 

      <?php $_collectionSize = $_productCollection->count() ?> 
      <?php $_columnCount = $this->getColumnCount(); ?> 
      <div class="products-grid"> 
       <div class="row"> 
      <?php $i=0; foreach ($_productCollection as $_product): 
       $id_product = Mage::getModel('catalog/product')->load($_product->getId()); 
         //$count_input_qty++; 
         $now = date("Y-m-d"); 
         $newsFrom = substr($_product->getData('news_from_date'), 0, 10); 
         $newsTo = substr($_product->getData('news_to_date'), 0, 10); 

         $specialprice = Mage::getModel('catalog/product')->load($_product->getId())->getSpecialPrice(); 
         //echo $specialprice . '-hau<br/>'; 
         $price = Mage::getModel('catalog/product')->load($_product->getId())->getPrice(); 
         if ($specialprice == '') { 
          $store_id = Mage::app()->getStore()->getStoreId(); 
          $discounted_price = Mage::getResourceModel('catalogrule/rule')->getRulePrice(
           Mage::app()->getLocale()->storeTimeStamp($store_id), 
           Mage::app()->getStore($store_id)->getWebsiteId(), 
           Mage::getSingleton('customer/session')->getCustomerGroupId(), 
           $_product->getId()); 
          $specialprice = $discounted_price; 

         } 
      ?> 
       <?php if ($i++%$_columnCount==0): ?> 

       <?php endif ?> 

         <div class="item col-lg-4 col-md-4 col-sm-6 col-xs-6 respl-item"> 
         <div class="item-inner"> 
          <div class="w-image-box"> 
           <div class="item-image"> 
            <!--SHOW 2 IMAGE FOR PRODUCTS--> 
             <?php $_media = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages() ?> 

             <?php $count_item=0; $check_img=0;?> 

             <?php $check_img = count($_media);?> 

            <a class="<?php if ($check_img >= 2) echo $this->__('rspl-image');?>" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>"> 
             <img class="first_image" src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(270); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /> 

             <?php if ($check_img >= 2): ?> 
              <?php 
              $flag=0; 
              foreach($_media as $_img): ?> 
                <?php $count_item++;?> 
                <?php if ($_img->getFile() == $_product->getSmallImage()){ 
                 if($count_item==$check_img){ 
                  $flag = 0; 
                 }else{ 
                  $flag = 1; 
                 } 
                 continue; 
                } ?> 
                <?php if($flag==1) { ?> 
                <img class="last_image" src="<?php echo $this->helper('catalog/image')->init($_product, 'image', $_img->getFile())->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)->resize(270,270); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true); ?>" /> 
                <?php break; }?> 
              <?php endforeach; ?> 
              <?php 
               if($flag==0){ 
                foreach($_media as $_img){ ?> 
                <img class="last_image" src="<?php echo $this->helper('catalog/image')->init($_product, 'image', $_img->getFile())->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)->resize(270,270); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true); ?>" /> 
               <?php break; } 
               } 
              ?> 
             <?php endif?> 
            <!--END SHOW 2 IMAGE FOR PRODUCTS--> 
            </a> 



           </div> 
           <?php if ($newsFrom != "" && $now >= $newsFrom && ($now <= $newsTo || $newsTo == "")) { ?> 
            <div class="new-product"> 
              <?php echo $this->__('New'); ?> 
            </div> 
           <?php }?> 
           <?php if ($specialprice) { ?> 
            <div class='sale-item'> 
             <?php echo $this->__('Sale'); ?> 
            </div> 
           <?php }?> 
          </div> 
          <div class="item-info"> 
           <div class="item-title "> 
            <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"> 
            <?php if(strlen($_helper->productAttribute($_product, $_product->getName(), 'name')) > 100){ 
             echo substr($_helper->productAttribute($_product, $_product->getName(), 'name'), 0, 100); 
            } else { 
             echo $_helper->productAttribute($_product, $_product->getName(), 'name'); 
            }?> 
            </a> 
           </div> 
           <div class="item-review"> 
            <?php echo $this->getReviewsSummaryHtml($_product, "short", true); ?> 
           </div> 

           <div class="item-price"> 
            <?php // echo $this->getPriceHtml($_product, true) ?> 
            <?php echo $this->getPriceHtml($_product, true) ?> 
           </div> 
           <!-- 
           <div class="item-desc"> 
            <?php 
             echo substr($_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description'), 0, 70); 
            ?> 
           </div> 
           --> 
           <div class="item-addto-wrap"> 
            <div class="button-action item-addcart"> 
             <?php if($_product->isSaleable()): ?> 
             <a class="button btn-cart" title="<?php echo $this->__('Add to Cart') ?>" href="javascript:void(0);" onclick="setLocation('<?php echo $this->getAddToCartUrl($id_product) ?>')"> 
              <?php echo $this->__('Add to Cart') ?> 
             </a> 
             <?php else: ?> 
             <p class="availability out-of-stock"> 
              <span><?php echo $this->__('Out of stock') ?> </span> 
             </p> 
             <?php endif; ?> 

             <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?> 
              <a class="link-compare" href="<?php echo $_compareUrl ?>" title="<?php echo $this->__('Add to Compare'); ?>"> 
               <?php echo $this->__('Add to Compare') ?> 
              </a> 
             <?php endif;?> 

             <?php if ($this->helper('wishlist')->isAllow()) : ?> 
              <a class="link-wishlist" href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" title="<?php echo $this->__('Add to Wishlist') ?>"> 
               <?php echo $this->__('Add to Wishlist') ?> 
              </a> 
             <?php endif; ?> 


            </div> 
           </div>    
          </div> 

         </div> 

        </div> 
       <?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?> 

       <?php endif ?> 
       <?php endforeach ?> 
       </div> 
      </div> 
       <script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script> 
      <?php endif; ?> 

建议我,我该怎么办?

回答

0

正如我记得在产品查看页面上的所有价格在飞行中收集。但在具有许多产品(网格/列表)的网页上,价格会从数据库中获得。这意味着最有可能你的代码没有问题。数据库中存在问题。尝试重新索引,重新保存,检查数据库中的值。

也尝试禁用任何可能影响计算价格过程,然后重新索引和reSave的模块。打开系统/设计中的默认主题。

希望它会有帮助。

1

重建索引"Category Products"即使Status = Ready & Update Required = NO

相关问题