0

大家好,我正在尝试将 CSS3 Mashmenu 集成到我的 Magento 商店http://www.mybloggerlab.com/2012/07/mashable-drop-down-navigation-menu-for.html

我想设置菜单以显示产品类别,当将鼠标悬停在显示产品缩略图上时,该类别中的每个产品都有简短的描述。

我遇到的问题是设置它,所以它是动态的,因为我希望菜单可以通过管理员控制。

如果有人能告诉我哪里出错了,我将不胜感激,因为当前代码无法正常工作。

<div id="pageContainer">
  <div class="mashmenu">
    <div class="fnav"><a href="#" class="flink"><?php echo $this->__('BROWSE PRODUCTS'); ?>+</a>
        <div class="allContent">
          <?php foreach ($_categories as $_category): ?>
            <?php if($_category->getIsActive()): ?>
                <div class="snav"><a href="#" class="slink">
                  <a href="<?php echo $this->getCategoryUrl($_category) ?>"<?php if ($this->isCategoryActive($_category)): ?> class="current"<?php endif; ?>><?php echo $this->htmlEscape($_category->getName()) ?></a> (<?php echo $_category->getProductCount() ?>)</a>
                  <?php $collection = $_category->getProductCollection()->addAttributeToSort('name', 'asc'); ?>
                  <?php foreach ($collection as $_product) : ?>
                    <div class="insideContent"> 
                      <a href="<?php echo $this->getProductUrl($_product) ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>" class="product-image">
                        <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(75) ?>" width="75" height="75" alt="<?php echo $this->stripTags($_product->getName(), null, true) ?>" />
                      </a> 
                      <span>  <?php $sdesc = $_product->getShortDescription();
                      $sdesc = trim($sdesc);
                      $limit = 170;
                      if (strlen($sdesc) > $limit) {
                        $sdesc = substr($sdesc, 0, strrpos(substr($sdesc, 0, $limit), ' '));
                      } ?>
                      <?php echo $sdesc."..."; ?></span> 
                    </div>
                  <?php endforeach; ?> 
                </div>
            <?php endif; ?>
          <?php endforeach; ?>
          <!-- end insideContent -->
        </div>
      </div>
    </div>
  </div>
  <script>
    $j(document).ready(function(){
      $j('div.mashmenu img').css({"width":"100px","height":"60px"});
      $j('div.mashmenu').find('.allContent').css({"top":"38px"});

      $j('div.mashmenu').mouseleave(function(){
        $j('div.mashmenu .allContent').show('50');
        $j('div.mashmenu .insideContent').fadeOut('50');
      }); 

      $j('.flink').mouseenter(function(){
        $j('div.mashmenu .allContent').show('50');
        $j(this).parent('.fnav').children('.allContent').show(200);
      });

      $j('.slink').mouseenter(function(){
        if($j(this).parent('.snav').children('.insideContent').find('a').size() != 0 )
          $j(this).parents('.allContent').css({"width":"640px","height":"500px"});
        else $j(this).parents('.allContent').css({"width":"auto","height":"auto"});
          $j('div.mashmenu .insideContent').fadeOut('50');
        $j(this).parent('.snav').children('.insideContent').fadeIn(200);
      });

      $j('.snav').mouseleave(function(){
        $j(this).parents('.allContent').css({"width":"auto","height":"auto"});
      });

      $j('.snav').mouseenter(function(){
        $j(this).children('.insideContent').css({"display":"block","position":"absolute","width":"auto","height":"450px"});
      });
    });
  </script>
<?php endif; ?>
4

1 回答 1

0
<div class="insideContent"> 
<a href="<?php echo $this->getProductUrl($_product) ?>" title="<?php echo    $this->stripTags($_product->getName(), null, true) ?>" class="product-image"><img src="<?php     echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(75) ?>" width="75" height="75" alt="<?php echo $this->stripTags($_product->getName(), null, true) ?>" /></a> <span>  <?php $sdesc = $_product->getShortDescription();
                $sdesc = trim($sdesc);
                $limit = 170;
                if (strlen($sdesc) > $limit) {
                    $sdesc = substr($sdesc, 0, strrpos(substr($sdesc, 0, $limit), ' '));
                } ?>
                <?php echo $sdesc."..."; ?></span> 
</div>

您的 $_product 在这里未定义,而且每个类别只有一种产品,那么要显示哪一种?

用类似的东西替换它:

<?php $collection =   Mage::getModel('catalog/product')->getCollection()->addCategoryFilter($_category)->setPageSize(4);
<div class="insideContent"> 
<?php foreach ($collection as $_product)  { ?>
//Your product here, copy your code
<?php } /*end foreach*/ ?>
</div>

它应该像这样更好地工作。

于 2012-11-28T10:57:32.630 回答