宇讯一资源

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

发布于2020年11月18日 | 暂无评论 | 17阅读 | magento

1,在addtoCart.phtml里添加html

<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里

<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

.buynow {
    float: left;
    height: 100%;
    overflow: hidden;
    position: relative;
    margin-right: 10px;
    background-color: #ffeded;
    border: 1px solid #FF0036;
    color: #FF0036;
}

暂无评论

发布评论