創建函數addAction
的cartController.php
(app/code/core/checkout/controllers/
)到myaddAction()的副本。
下面添加結束view.phtml (app/design/frontend/your package/your template/template/catalog/product/view.phtml)
<script type="text/javascript">
//<![CDATA[
productAddToCartForm.submit = function(button, url){
replaceURL = url.replace("add/","myadd/");
if(this.validator) {
var nv = Validation.methods;
delete Validation.methods['required-entry'];
delete Validation.methods['validate-one-required'];
delete Validation.methods['validate-one-required-by-name'];
// Remove custom datetime validators
for (var methodName in Validation.methods) {
if (methodName.match(/^validate-datetime-.*/i)) {
delete Validation.methods[methodName];
}
}
if (this.validator.validate()) {
if (url) {
this.form.action = replaceURL;
}
this.form.submit();
}
Object.extend(Validation.methods, nv);
}
}.bind(productAddToCartForm);
//]]>
</script>
添加結賬按鈕addtocart.phhtml (app/design/frontend/your package/your template/template/catalog/product/view
)
<button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" onclick="productAddToCartForm.submitmy(this)"><span><span><?php echo "Checkout"; ?></span></span></button>
正如我告訴你複製的addAction到mycartAction 變化
$this->_goBack();
至
$this->_redirect('checkout/onepage');
return;
endof
if (!$cart->getQuote()->getHasError()){
$message = $this->__('%s was added to your shopping cart.', Mage::helper('core')->escapeHtml($product->getName()));
$this->_getSession()->addSuccess($message);
}
添加
感謝
Checkout按鈕。這是一個很好的解決方案。我想讓它在自定義控制器中運行,這正是我認爲你現在所建議的,但我只是添加了一些類似的邏輯到默認的addAction。如果他們點擊我的結賬按鈕,我只是傳遞了一個附加參數,如果設置了附加參數,它會重定向到「checkout/onepage」。但是我只是把它添加到了核心中,我不喜歡這樣做,但是我無法將它加入到模塊中。是否有一個單獨的控制器比其他參數更好?我想如果它在本地代碼池,這將是有意義的 – RattanOutdoorFurnitureDev