2012-08-06 49 views
0

我正在嘗試從開始創建一個模板。我已經準備好了所有的東西,現在我有一個主頁,在那裏我想顯示網格中可用的所有產品。所以我從佈局呈現list.phtml。 list.phtml:在我的主頁顯示所有產品 - magento

<?php 
$_productCollection=$this->getLoadedProductCollection(); 

$_helper = $this->helper('catalog/output'); 

?> 
<?php if(!$_productCollection->count()): ?> 
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p> 
<?php else: ?> 
<div class="category-products"> 

<?php // Grid Mode ?> 

<?php $_collectionSize = $_productCollection->count() ?> 
<?php $_columnCount = $this->getColumnCount(); ?> 
<?php $i=0; foreach ($_productCollection as $_product): ?> 
    <?php if ($i++%$_columnCount==0): ?> 
     <ul class="products-grid"> 
    <?php endif ?> 

      <li> 
       productsample 
      </li> 


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

<?php endforeach ?> 
</div> 
<?php endif; ?> 

這表明產品的時候,這個詞productsample數,所以我覺得我是裝好所有的產品,但我的問題是,我不知道如何顯示它們(照片,鏈路,addtocart,價格,名稱...) 由於所有

+0

所以,只檢查'應用程序/設計/前端/基/默認/目錄/產品/ list.phtml'文件 – Serjio 2012-08-06 14:49:35

+0

這是我做的第一件事,但它沒有工作....它表明,這部分沒有產品,因爲我在主頁和你告訴我的文件顯示活動類別的產品 – Carlos 2012-08-06 14:58:29

+0

是的,我知道。但是,您可以將代碼複製粘貼到'foreach'中,在那裏輸出所有產品的數據。無論如何,在'$ _product'上使用'getData()'方法,您將能夠輸出幾乎所有的產品數據 – Serjio 2012-08-06 15:08:10

回答

0

當我使用的GetData我獲得此:

陣列(11){[ 「ENTITY_ID」] =>串(1) 「2」 [「entity_type_id」] => string(1)「4」[「attribute_set_id」] => string(2)「10」[「type_id」] => string(6)「simple」[「sku」] => string (10)「1343918767」[「has_options」] =>字符串(1)「0」[「req uired_options「] => string(1)」0「[」created_at「] => string(19)」2012-08-02 14:46:29「[」updated_at「] => string(19)」2012-08 -02 17:09:43「[」is_salable「] => string(1)」1「[」stock_item「] => object(Varien_Object)#336(5){[」_data「:protected] => array( 1){[「is_in_stock」] => string(1)「1」} [「_hasDataChanges」:protected] => bool(false)[「_origData」:protected] => NULL [「_idFieldName」:protected] => NULL [ 「_isDeleted」:保護]

我需要的名稱,價格......

我已經取代度這=>布爾(假)}}:$ _productCollection = $這個 - > getLoadedProductCollection();作爲交換條件:$ _productCollection = Mage :: getModel('catalog/product') - > getCollection();

因爲如果我使用第一個,它顯示我在實際類別中沒有產品。

然後我在foreach裏面的foreach裏默認list.phtm裏面的代碼,但它沒有顯示我的產品。產品img中存在某種錯誤,因爲它停留在第一個產品中,在其圖像中。這裏是代碼:

代碼:

<?php 
//  $_productCollection=$this->getLoadedProductCollection(); 
$_productCollection=Mage::getModel('catalog/product')->getCollection(); 

$_helper = $this->helper('catalog/output'); 

?> 
<?php if(!$_productCollection->count()): ?> 
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p> 
<?php else: ?> 
<div class="category-products"> 

<?php // Grid Mode ?> 

<?php $_collectionSize = $_productCollection->count() ?> 
<?php $_columnCount = $this->getColumnCount(); ?> 
<?php $i=0; foreach ($_productCollection as $_product): ?> 
    <?php if ($i++%$_columnCount==0): ?> 
     <ul class="products-grid"> 
    <?php endif ?> 

     <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>"> 
      <a href="<?php echo $_product->getProductUrl() ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" /></a> 
      <h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></a></h2> 
      <?php if($_product->getRatingSummary()): ?> 
      <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?> 
      <?php endif; ?> 
      <?php echo $this->getPriceHtml($_product, true) ?> 
      <div class="actions"> 
       <?php if($_product->isSaleable()): ?> 
        <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button> 
       <?php else: ?> 
        <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p> 
       <?php endif; ?> 
       <ul class="add-to-links"> 
        <?php if ($this->helper('wishlist')->isAllow()) : ?> 
         <li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li> 
        <?php endif; ?> 
        <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?> 
         <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li> 
        <?php endif; ?> 
       </ul> 
      </div> 
     </li> 


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

<?php endforeach ?> 
</div> 
<?php endif; ?> 

第一<一>中< LI>,其IMG心不是工作

0

,如果你使用的CMS主頁則只是把這個代碼{{block type="catalog/product_list" category_id="your cat id" template="catalog/product/list.phtml"}}分配所有產品到這個類別。 或者您可以直接使用list.phtml文件代碼來列出下面的代碼所有產品。

$_productCollection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*')->addAttributeToFilter('visibility', 4)->addAttributeToFilter('status', 1)->load(); 

只是把這個代碼,而不是這個$_productCollection=$this->getLoadedProductCollection();

相關問題