【问题标题】:Navigation menu with product thumbnails Magento带有产品缩略图的导航菜单 Magento
【发布时间】:2012-11-16 04:21:58
【问题描述】:

大家好,我正在尝试将 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; ?>

【问题讨论】:

    标签: php html magento css


    【解决方案1】:
    <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>
    

    这样应该会更好。

    【讨论】:

    • 感谢您的回复,非常有帮助。我已更改代码(见上文^ 编辑),但现在出现错误:Parse error: syntax error, unexpected 'endforeach' (T_ENDFOREACH) in /Applications/MAMP/htdocs/mysite/app/design/frontend/bootstrapped/default /template/vertnav/left.phtml 第 27 行
    • 我已经修复了上面的错误^代码...但是导航菜单不再显示...
    • 在尝试完成上述任务后,我发现 Magento 不允许在导航菜单中显示产品缩略图。相反,我应该使用类别缩略图
    猜你喜欢
    • 1970-01-01
    • 2014-07-26
    • 2012-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多