2015-11-29 50 views
-2

我不擅长编码。我试图在产品详细信息页面上添加一个自定义按钮,该按钮充当Add to cart和BuyNow。当点击这个按钮时,它应该将产品添加到购物车并重定向到结帐页面。我使用的是magento 1.8.1,并且具有响应性。如何在magento的产品页面上添加自定义buynow按钮

请任何人都可以帮助我说出所有的步骤。

回答

2

应用程序/设计/前端/包/主题/模板/目录/产品/视图/ 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; ?> 

后end if if insert this code

<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()?>"> 

添加图片/ buy.png

+0

嗨感谢您的答复采取代码。代码工作正常,但在加载图像时出现问题。图像不会显示。我也尝试过.gif,.jpeg,.png。 –

+0

给我你的网站的网址 – rahul

+0

我的网址是www.lycraze.com –

0

请打开应用程序/设计/前端/包/主题/模板/目录/产品/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> 

现在打开的应用程序/代码/核心/法师/结帐/控制器/ CartController.php

改变代码如下面_goBack()函数将下面行指令

在非常第一

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

找到这行$ this-> getResponse() - > 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

相关问题