2012-12-13 43 views
0

我期待通過查看產品ID來定義特定的屬性列表。Magento中的屬性view.phtml

目前我有下面,但我知道它需要更多的工作,特別是因爲它與封閉的div內的php衝突。總體來說,我想說,如果產品id == 30,那麼顯示下面的其他內容顯示規範。

代碼如下。

<?php if($_product->getId() == "30")  
     { 

     <div class="attribute_page"> 
     <p><span class="attribute_first">ISSN:</span> <?php echo $_product->getResource()->getAttribute('issn')->getFrontend()->getValue($_product) ?></p> 
     <p><span class="attribute_first">Editor:</span> <?php echo $_product->getResource()->getAttribute('editor')->getFrontend()->getValue($_product) ?></p> 
     <p><span class="attribute_first">Indexing Info:</span> <?php echo $_product->getResource()->getAttribute('indexing_info')->getFrontend()->getValue($_product) ?></p> 
     <p><span class="attribute_first">Scope of Journal:</span> <?php echo $_product->getResource()->getAttribute('scope_of_journal')->getFrontend()->getValue($_product) ?></p> 

     <p><span class="attribute_first">Purchasing Form:</span> <a href="<?php echo $_product->getResource()->getAttribute('purchasing_form')->getFrontend()->getValue($_product) ?>" target="_blank" rel="nofollow">Download Here</a></p> 
     <p><span class="attribute_first">Download Product Flyer:</span> <a href="<?php echo $_product->getResource()->getAttribute('product_flyer')->getFrontend()->getValue($_product) ?>" target="_blank" rel="nofollow">Download Here</a></p> 
     <p><span class="attribute_first">JSIS Homepage:</span> <a href="<?php echo $_product->getResource()->getAttribute('jsis')->getFrontend()->getValue($_product) ?>" target="_blank" rel="nofollow">Click Here</a></p> 
     <p><span class="attribute_first">Recommend to Librarian:</span> <a href="<?php echo $_product->getResource()->getAttribute('recommend_to_librarian')->getFrontend()->getValue($_product) ?>" target="_blank" rel="nofollow">Click Here</a></p> 


     <?php echo $this->getChildHtml('alert_urls') ?> 
     <?php echo $this->getChildHtml('product_type_data') ?> 
     <?php echo $this->getTierPriceHtml() ?> 
     <?php echo $this->getChildHtml('extrahint') ?> 
     </div> 

     } 
     else { 

     <div class="attribute_page"> 
     <p><span class="attribute_first">Author:</span> <?php echo $_product->getResource()->getAttribute('author')->getFrontend()->getValue($_product) ?></p> 
     <p><span class="attribute_first">Translation:</span> <?php echo $_product->getResource()->getAttribute('translation')->getFrontend()->getValue($_product) ?></p> 
     <p><span class="attribute_first">Cover:</span> <?php echo $_product->getResource()->getAttribute('cover')->getFrontend()->getValue($_product) ?></p> 
     <p><span class="attribute_first">Google Books Preview:</span> <a href="<?php echo $_product->getResource()->getAttribute('google_preview')->getFrontend()->getValue($_product) ?>" target="_blank" rel="nofollow">Click Here</a></p> 

     <?php echo $this->getChildHtml('alert_urls') ?> 
     <?php echo $this->getChildHtml('product_type_data') ?> 
     <?php echo $this->getTierPriceHtml() ?> 
     <?php echo $this->getChildHtml('extrahint') ?> 
     </div> 

     <?php endif; ?> 
+0

?你能解釋你得到的錯誤或確切的問題是什麼? –

+0

woops ..我現在編輯它$ _product。 目前使用此代碼,它打破了產品頁面。沒有任何錯誤產生,也沒有產品。 –

回答

0

完成它:) 經過一番研究,我只是缺少了幾個字符。新代碼看起來像這樣。你爲什麼要同時使用$產品和$ _產品

<?php if($_product->getId() == 30): ?> 

     <div class="attribute_page"> 
     <p><span class="attribute_first">ISSN:</span> <?php echo $_product->getResource()->getAttribute('issn')->getFrontend()->getValue($_product) ?></p> 
     <p><span class="attribute_first">Editor:</span> <?php echo $_product->getResource()->getAttribute('editor')->getFrontend()->getValue($_product) ?></p> 
     <p><span class="attribute_first">Indexing Info:</span> <?php echo $_product->getResource()->getAttribute('indexing_info')->getFrontend()->getValue($_product) ?></p> 
     <p><span class="attribute_first">Scope of Journal:</span> <?php echo $_product->getResource()->getAttribute('scope_of_journal')->getFrontend()->getValue($_product) ?></p> 
     <p><span class="attribute_first">Purchasing Form:</span> <a href="<?php echo $_product->getResource()->getAttribute('purchasing_form')->getFrontend()->getValue($_product) ?>" target="_blank" rel="nofollow">Download Here</a></p> 
     <p><span class="attribute_first">Download Product Flyer:</span> <a href="<?php echo $_product->getResource()->getAttribute('product_flyer')->getFrontend()->getValue($_product) ?>" target="_blank" rel="nofollow">Download Here</a></p> 
     <p><span class="attribute_first">JSIS Homepage:</span> <a href="<?php echo $_product->getResource()->getAttribute('jsis')->getFrontend()->getValue($_product) ?>" target="_blank" rel="nofollow">Click Here</a></p> 
     <p><span class="attribute_first">Recommend to Librarian:</span> <a href="<?php echo $_product->getResource()->getAttribute('recommend_to_librarian')->getFrontend()->getValue($_product) ?>" target="_blank" rel="nofollow">Click Here</a></p> 
     <?php echo $this->getChildHtml('alert_urls') ?> 
     <?php echo $this->getChildHtml('product_type_data') ?> 
     <?php echo $this->getTierPriceHtml() ?> 
     <?php echo $this->getChildHtml('extrahint') ?> 
     </div> 

     <?php else: ?> 

     <div class="attribute_page"> 
     <p><span class="attribute_first">Author:</span> <?php echo $_product->getResource()->getAttribute('author')->getFrontend()->getValue($_product) ?></p> 
     <p><span class="attribute_first">Translation:</span> <?php echo $_product->getResource()->getAttribute('translation')->getFrontend()->getValue($_product) ?></p> 
     <p><span class="attribute_first">Cover:</span> <?php echo $_product->getResource()->getAttribute('cover')->getFrontend()->getValue($_product) ?></p> 
     <p><span class="attribute_first">Google Books Preview:</span> <a href="<?php echo $_product->getResource()->getAttribute('google_preview')->getFrontend()->getValue($_product) ?>" target="_blank" rel="nofollow">Click Here</a></p> 
     <?php echo $this->getChildHtml('alert_urls') ?> 
     <?php echo $this->getChildHtml('product_type_data') ?> 
     <?php echo $this->getTierPriceHtml() ?> 
     <?php echo $this->getChildHtml('extrahint') ?> 
     </div> 

     <?php endif; ?> 
0

第一個代碼也將工作,如果你有提供<?php ?>標籤正確的代碼會是這樣的..

<?php if($_product->getId() == "30")  
    { ?> 

    <div class="attribute_page"> 
    <p><span class="attribute_first">ISSN:</span> <?php echo $_product->getResource()->getAttribute('issn')->getFrontend()->getValue($_product) ?></p> 
    <p><span class="attribute_first">Editor:</span> <?php echo $_product->getResource()->getAttribute('editor')->getFrontend()->getValue($_product) ?></p> 
    <p><span class="attribute_first">Indexing Info:</span> <?php echo $_product->getResource()->getAttribute('indexing_info')->getFrontend()->getValue($_product) ?></p> 
    <p><span class="attribute_first">Scope of Journal:</span> <?php echo $_product->getResource()->getAttribute('scope_of_journal')->getFrontend()->getValue($_product) ?></p> 

    <p><span class="attribute_first">Purchasing Form:</span> <a href="<?php echo $_product->getResource()->getAttribute('purchasing_form')->getFrontend()->getValue($_product) ?>" target="_blank" rel="nofollow">Download Here</a></p> 
    <p><span class="attribute_first">Download Product Flyer:</span> <a href="<?php echo $_product->getResource()->getAttribute('product_flyer')->getFrontend()->getValue($_product) ?>" target="_blank" rel="nofollow">Download Here</a></p> 
    <p><span class="attribute_first">JSIS Homepage:</span> <a href="<?php echo $_product->getResource()->getAttribute('jsis')->getFrontend()->getValue($_product) ?>" target="_blank" rel="nofollow">Click Here</a></p> 
    <p><span class="attribute_first">Recommend to Librarian:</span> <a href="<?php echo $_product->getResource()->getAttribute('recommend_to_librarian')->getFrontend()->getValue($_product) ?>" target="_blank" rel="nofollow">Click Here</a></p> 


    <?php echo $this->getChildHtml('alert_urls') ?> 
    <?php echo $this->getChildHtml('product_type_data') ?> 
    <?php echo $this->getTierPriceHtml() ?> 
    <?php echo $this->getChildHtml('extrahint') ?> 
    </div> 

    <?php } 
    else { ?> 

    <div class="attribute_page"> 
    <p><span class="attribute_first">Author:</span> <?php echo $_product->getResource()->getAttribute('author')->getFrontend()->getValue($_product) ?></p> 
    <p><span class="attribute_first">Translation:</span> <?php echo $_product->getResource()->getAttribute('translation')->getFrontend()->getValue($_product) ?></p> 
    <p><span class="attribute_first">Cover:</span> <?php echo $_product->getResource()->getAttribute('cover')->getFrontend()->getValue($_product) ?></p> 
    <p><span class="attribute_first">Google Books Preview:</span> <a href="<?php echo $_product->getResource()->getAttribute('google_preview')->getFrontend()->getValue($_product) ?>" target="_blank" rel="nofollow">Click Here</a></p> 

    <?php echo $this->getChildHtml('alert_urls') ?> 
    <?php echo $this->getChildHtml('product_type_data') ?> 
    <?php echo $this->getTierPriceHtml() ?> 
    <?php echo $this->getChildHtml('extrahint') ?> 
    </div> 

    <?php } ?>