如何在magento中显示RECOMMENDED类别

时间:2015-03-18 13:15:23

标签: php magento wamp

我是magento平台的新手。

我想在产品页面中显示推荐的产品类别。

我有一些代码,但它无法正常工作。

它将显示所有产品,而不仅仅是推荐的类别。

推荐产品猫我正在服用产品添加时间。

我的代码是

<?php
    $product_id = Mage::registry('current_product')->getId();
    $_product = Mage::getModel('catalog/product')->load($product_id);
    $pr_data = $_product->getData();
    ?>
    <?php if ($pr_data['recommended_categories']): ?>
        <?php
        $category = new Mage_Catalog_Model_Category();
        $category->load($categoryid);
        $collection = $category->getProductCollection();
        $collection->addAttributeToSelect('*');
        ?>
        <div class="col-lg-7 col-md-7 col-sm-7 cpl-xs-12">  
            <div class="ndlSimilarTop">
                <div class="ndlSimilatProductTitle">RECOMMENDED PRODUCTS</div>
                <div id="amazingcarousel-container-1" style="overflow:hidden">
                    <div id="amazingcarousel-1" style="display:block;position:relative;width:100%;max-width:711px;margin:0px auto 0px;">
                        <div class="amazingcarousel-list-container" style="overflow:hidden;">
                            <ul class="amazingcarousel-list">
                                <?php foreach ($collection as $_item): ?>
                                    <li class="amazingcarousel-item">
                                        <div class="amazingcarousel-item-container">
                                            <div class="amazingcarousel-image">
                                                <img src="<?php echo $this->helper('catalog/image')->init($_item, 'small_image')->resize(217, 173) ?>"  alt="product-img" />

                                                <ul class="mask mask1">
                                                    <li class="ndlHoverContent ndlHoverContent1">
                                                        <a href="<?php echo $this->getAddToWishlistUrl($_item) ?>" class="ndlListWishlist ndlListWishlist1 ndlListWishlist2"><img src="<?php echo $this->getSkinUrl() ?>images/wishlist-white-icon.png" alt="">Add to wishlist</a>
                                                        <a href="#" class="ndlListAddtobag ndlListAddtobag1 ndlListAddtobag2"><img src="<?php echo $this->getSkinUrl() ?>images/mybag-white-icon.png" alt="">Add to bag</a>
                                                    </li>
                                                </ul>
                                            </div>
                                            <div class="ndlListDetail">
                                                <div class="ndlProductListName"><?php echo $this->escapeHtml($_item->getName()) ?></div>
                                                <?php echo $this->getPriceHtml($_item, true, '-related') ?>
                                            </div>

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

1 个答案:

答案 0 :(得分:1)

$categoryid
当你这样做时,

是未定义的:

$category->load($categoryid);

将其设置为“推荐”&#39;您希望显示的类别ID。