duanjiyun7391 2018-10-26 13:53
浏览 65

Magento:将产品页面中的产品选项显示为两列中的列表元素

Having actual Magento 1.9.3 situation...

In product-page there are a lot of configuration options. Need to save space, so need to turn the one column vertical product options list into a two column list to reduce the space to 50%.

Already tried several methods, also this one: https://magento.stackexchange.com/questions/70857/display-product-options-change-layout-of-in-block-after-info-column

in combination with Css Styling list elements in two columns

and this https://csswizardry.com/2010/02/mutiple-column-lists-using-one-ul/

But did not figure it out really. Was stopping on the results, to display all in only one horizontal line. The issue is, that if there are 10 attributes to select, the line is becoming very pressed and nothing is recognisable.

Is anyone out there, who is able to adjust the code?

Here is the code having in:

/template/catalog/product/view/type/options/configurable.phtml

    <?php
$_product    = $this->getProduct();
$_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes());
$_jsonConfig = $this->getJsonConfig();
$_renderers = $this->getChild('attr_renderers')->getSortedChildren();
?>
<?php if ($_product->isSaleable() && count($_attributes)):?>
<div class="items">    
    <dl>
    <?php foreach($_attributes as $_attribute): ?>
        <?php
        $_rendered = false;
        foreach ($_renderers as $_rendererName):
            $_renderer = $this->getChild('attr_renderers')->getChild($_rendererName);
            if (method_exists($_renderer, 'shouldRender') && $_renderer->shouldRender($_attribute, $_jsonConfig)):
                $_renderer->setProduct($_product);
                $_renderer->setAttributeObj($_attribute);
                echo $_renderer->toHtml();
                $_rendered = true;
                break;
            endif;
        endforeach;

        if (!$_rendered):
        ?>
        <dt><label class="required"><em>*</em><?php echo $_attribute->getLabel() ?></label></dt>
        <dd<?php if ($_attribute->decoratedIsLast){?> class="last"<?php }?>>
            <div class="input-box">
                <select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select">
                    <option><?php echo $this->__('Choose an Option...') ?></option>
                  </select>
              </div>
        </dd>
        <?php endif; ?>
    <?php endforeach; ?>
    </dl>
</div>  
    <script type="text/javascript">
        var spConfig = new Product.Config(<?php echo $_jsonConfig ?>);
    </script>
    <?php echo $this->getChildHtml('after') ?>
<?php endif;?>
  • 写回答

1条回答 默认 最新

  • doudongfu8006 2018-10-27 02:03
    关注

    Without Seeing the output its hard to know what you want exactly, but if you want the options to be in 2 columns this should work.

    .items dl {
    display:flex;
    flex-wrap: wrap;
    }
    
    .items dl .options-wrapper{
     width: 50%;
    }
    
    //If you want on smaller screens to make them 1 row.
    
    @media screen and (max-width: 768px) {
    .items dl .options-wrapper{
     width: 100%;
     }
    }
       <?php
    $_product    = $this->getProduct();
    $_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes());
    $_jsonConfig = $this->getJsonConfig();
    $_renderers = $this->getChild('attr_renderers')->getSortedChildren();
    ?>
    <?php if ($_product->isSaleable() && count($_attributes)):?>
    <div class="items">    
        <dl>
        <?php foreach($_attributes as $_attribute): ?>
            <?php
            $_rendered = false;
            foreach ($_renderers as $_rendererName):
                $_renderer = $this->getChild('attr_renderers')->getChild($_rendererName);
                if (method_exists($_renderer, 'shouldRender') && $_renderer->shouldRender($_attribute, $_jsonConfig)):
                    $_renderer->setProduct($_product);
                    $_renderer->setAttributeObj($_attribute);
                    echo $_renderer->toHtml();
                    $_rendered = true;
                    break;
                endif;
            endforeach;
    
            if (!$_rendered):
            ?>
            <div class="options-wrapper">
                    <dt><label class="required"><em>*</em><?php echo $_attribute->getLabel() ?></label></dt>
            <dd<?php if ($_attribute->decoratedIsLast){?> class="last"<?php }?>>
                <div class="input-box">
                    <select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select">
                        <option><?php echo $this->__('Choose an Option...') ?></option>
                      </select>
                  </div>
            </dd>
            </div>
    
            <?php endif; ?>
        <?php endforeach; ?>
        </dl>
    </div>  
        <script type="text/javascript">
            var spConfig = new Product.Config(<?php echo $_jsonConfig ?>);
        </script>
        <?php echo $this->getChildHtml('after') ?>
    <?php endif;?>

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢