如何在magento的产品页面上添加自定义buynow按钮

时间:2015-11-29 09:49:46

标签: magento

我的编码不太好。我正在尝试在产品详细信息页面上添加自定义按钮,该按钮也可用作添加到购物车和BuyNow。单击此按钮时,应将产品添加到购物车中并重定向到结帐页面。我正在使用magento 1.8.1并且有响应的名字。

请任何人帮我讲述所有步骤。

3 个答案:

答案 0 :(得分:2)

app / design / frontend / package / theme / template / catalog / product / view / addtocart.phtml

找到这段代码

 <?php if(!$_product->isGrouped()): ?>
       <label for="qty"><?php //echo $this->__('Qty:') ?></label>
        <input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
        <?php endif; ?>

评论两行

        <?php if(!$_product->isGrouped()): ?>
       <!-- <label for="qty"><?php //echo $this->__('Qty:') ?></label>
        <input type="text" name="qty" id="qty" maxlength="12" value="<?php //echo $this->getProductDefaultQty() * 1 ?>" title="<?php// echo $this->__('Qty') ?>" class="input-text qty" /> -->
        <?php endif; ?>

结束后如果插入此代码

<input type="image" class="button btn-cart" src="<?php echo $this->getSkinurl('images/buy.png')?>" onclick="<?php echo $this->getCheckoutUrl()?>">

最终代码看起来像这样

 <?php if(!$_product->isGrouped()): ?>
       <!-- <label for="qty"><?php //echo $this->__('Qty:') ?></label>
        <input type="text" name="qty" id="qty" maxlength="12" value="<?php //echo $this->getProductDefaultQty() * 1 ?>" title="<?php// echo $this->__('Qty') ?>" class="input-text qty" />  -->
        <?php endif; ?>


  <input type="image" class="button btn-cart" src="<?php echo $this->getSkinurl('images/buy.png')?>" onclick="<?php echo $this->getCheckoutUrl()?>">

在skin / frontend / package / theme / images / buy.png

中添加图片

答案 1 :(得分:0)

请打开app / design / frontend / package / theme / template / catalog / product / view.phtml

将以下行添加到<form>代码

<input type="hidden" name="buy_now" id="buy_now" value="" />

将下方按钮放在您想要的任何地方

<button type="button" onclick="jQuery('#buy_now').val('buy_now');productAddToCartForm.submit(this)" class="btn btn-block btn-express-buynow"><i class="cart-icon-white m-r-sm v-middle"></i>Buy Now</button>

现在打开app / code / core / Mage / Checkout / controllers / CartController.php

按以下说明更改代码

首先在_goBack()函数中添加以下行

$buy_now = $this->getRequest()->getParam('buy_now');

行$ this-&gt; getResponse() - &gt; setRedirect($ backUrl);并将此行替换为以下代码

if (!empty($buy_now)) {
    $this->_redirect('onepagecheckout'); // If you are using onepagecheckout or use this $this->_redirect('checkout/onepage/')
}else{
    $this->getResponse()->setRedirect($backUrl);
}

从此link

获取的代码

答案 2 :(得分:0)

如果您不擅长编码,则很难管理所有这些代码。 还有另一个选项可使用第三方扩展程序在Magento 2中添加自定义立即购买按钮

您可以尝试此扩展程序。

Source

相关问题