magento产品详情页面添加立即购买按钮

1,在addtoCart.phtml里添加html

1
2
3
4
5
6
7
<input type="hidden" value="<?php echo Mage::getUrl('checkout/onepage')?>" name="return_url" />
<button type="button"
title="<?php echo __('Buynow') ?>"
class="button btn-cart buynow"
onclick="productBuyNowForm.submit(this)">
<span><span><?php echo __('Buynow')?></span></span>
</button>

 

2,js触发。代码写在catalog/product/view.phtml里

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<script>
var productBuyNowForm = new VarienForm('product_addtocart_form');
productBuyNowForm.submit = function (button, url) {
if (this.validator.validate()) {
var form = this.form;
var oldUrl = form.action;
//alert(form.action);
if (url) {
form.action = url;
}

/* add return Url */
var inputreturn= document.createElement("input");
inputreturn.type = "hidden";
inputreturn.name = "return_url";
inputreturn.value = "<?php echo Mage::getUrl('checkout/onepage')?>";
document.getElementById('product_addtocart_form').appendChild(inputreturn);
/* add return Url */
// Append a line break
var e = null;
try {
this.form.submit();
} catch (e) {
}
this.form.action = oldUrl;
if (e) {
throw e;
}

if (button && button != 'undefined') {
button.disabled = true;
}
}
}.bind(productBuyNowForm);
</script>

 

3,css

1
2
3
4
5
6
7
8
9
10
.buynow {
float: left;
height: 100%;
overflow: hidden;
position: relative;
margin-right: 10px;
background-color: #ffeded;
border: 1px solid #FF0036;
color: #FF0036;
}

 

效果:

jietu20180301-101532

坚持原创技术分享,您的支持将鼓励我继续创作!