根据magento中的数量增量和减量更改价格?

时间:2015-11-09 13:32:14

标签: php jquery magento prototype magento-1.9

我想根据使用magento的数量增量或减量的变化来改变价格,magento默认它不存在,我已经安装了一个主题但是没有提供内置的这个功能,我该如何实现呢?其中包括可配置产品,它是产品描述(详情)页面

html里面的price.phtml文件

<span class="regular-price" id="product-price-<?php echo $_id ?><?php echo $this->getIdSuffix() ?>">
                    <?php if ($_finalPrice == $_price): ?>
                        <?php if(!in_array($idSuffix, $idSuffixArray) && $_isPP): ?>
                            <?php echo str_replace('class="price"', 'class="price" itemprop="price"  content="' . $_price . '"', $_coreHelper->formatPrice($_price, true)); ?>
                        <?php else: ?>
                            <?php echo $_coreHelper->formatPrice($_price, true) ?>
                        <?php endif; ?>
                    <?php else: ?>
                        <?php if(!in_array($idSuffix, $idSuffixArray) && $_isPP): ?>
                            <?php echo str_replace('class="price"', 'class="price" itemprop="price"  content="' . $_finalPrice . '"', $_coreHelper->formatPrice($_finalPrice, true)); ?>
                        <?php else: ?>
                            <?php echo $_coreHelper->formatPrice($_finalPrice, true); ?>
                        <?php endif; ?>
                    <?php endif; ?>
                </span>
    </span>

addtocart.phtml文件我们有给定的代码

<?php $_product = $this->getProduct(); ?>
<?php $buttonTitle = $this->__('Add to Cart'); ?>
<?php if($_product->isSaleable()): ?>
    <div class="add-to-cart">
        <?php if(!$_product->isGrouped()): ?>
            <label for="qty"><?php echo $this->__('Qty:') ?></label>
            <div class="qty_cart">
                <div class="qty-ctl">
                    <button title="decrease" onclick="changeQty(0); return false;" class="decrease">decrease</button>
                </div>
                <input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
                <div class="qty-ctl">
                    <button title="increase" onclick="changeQty(1); return false;" class="increase">increase</button>
                </div>
            </div>
        <?php endif; ?>
        <?php echo $this->getLayout()->getBlock('product.info.addto')->toHtml()?>
        <div class="button_addto">
            <button type="button" title="<?php echo $this->__('Buy Now') ?>" id="em-buy-now" class="button btn-em-buy-now" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $this->__('Buy Now') ?></span></span></button>
            <button type="button" title="<?php echo $buttonTitle ?>" id="product-addtocart-button" class="button btn-cart btn-cart-detail"><span><span><?php echo $buttonTitle ?></span></span></button>            
        </div>
        <?php echo $this->getChildHtml('', true, true) ?>
    </div>
    <script type="text/javascript">
        function changeQty(increase) {
            var qty = parseInt($('qty').value);
            if ( !isNaN(qty) ) {
                qty = increase ? qty+1 : (qty>1 ? qty-1 : 1);
                $('qty').value = qty;
            }
        }
    </script>
<?php endif; ?>

任何人都知道任何解决方案或代码请分享,任何帮助都可以得到赞赏。

1 个答案:

答案 0 :(得分:0)

Magento根据数量改变了价格变化的分层定价概念。

您也可以应用一些规则来实现这一目标。