view.phtml中的Magento属性

时间:2012-12-13 12:06:25

标签: magento if-statement php

我希望通过查看产品ID来定义特定的属性列表。

目前我有以下内容,但我知道它需要更多的工作,特别是因为它与所包含的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; ?>

2 个答案:

答案 0 :(得分: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; ?>

答案 1 :(得分: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 } ?>