在Magento中跳过Checkout可下载的产品 [英] Skip Checkout in Magento for a downloadable product

查看:243
本文介绍了在Magento中跳过Checkout可下载的产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Magento来构建电子书网站。为了发布,我们计划有一些免费的可下载的书籍。我们希望可以使用正常的Magento目录功能来添加类别与下面的产品。然而,由于这些是免费的可下载的产品,所以在尝试下载时,通过结帐来传送用户并不真实。

I am using Magento to build an eBooks site. For the release, we plan to have a number of free downloadable books. We were hoping that it would be possible to use the normal Magento 'catalog' functionality to add categories with products underneath. However, since these are free downloadable products, it doesn't really make sense to send users through the checkout when they try to download.

有没有人知道一种方法创建一个免费的可下载的产品,完全绕过结帐?我注意到可下载的产品有一个免费样品选项,但是如果我可以在我添加付费产品时,我可以使用这个字段来达到预期目的,我不愿意使用。

Does anyone know of a way to create a free downloadable product which bypasses the checkout altogether? I have noticed that there is a 'free sample' option for downloadable products, but I would prefer not to use this if I can as I plan to use this field for its intended purpose when I add paid products.


我注意到你们中有些人把这个问题投在了缺乏清晰度上。为了清楚起见,我想要:

I have noticed that some of you have voted this question down for 'lack of question clarity'. For clarity, I want:


  1. 知道是否可以

    Magento中创建一个可下载的产品不需要用户
    通过通常的结帐
    进程(因为它是免费的)


  2. 这不是免费样品字段
    的可下载产品

不幸的是,我不认为我可以更加雄辩地问这个问题。
[/ EDIT]

Unfortunately I don't think I can ask this any more eloquently. [/EDIT]

推荐答案

此代码将允许登录的客户免费下订单 ,虚拟产品,绕过结帐,并将其重定向到他们的帐户的我的下载部分。

This code will allow logged-in customers to "place an order" for a Free, Virtual product while bypassing checkout and redirect them straight to the My Downloads section of their account.

在您想要的位置,将以下行添加到您的 catalog / product / list.phtml p

Add the following line to your catalog/product/list.phtml in the spot you want it.

<?php if($_product->isVirtual() && $_product->getFinalPrice()==0) { ?>
                <a href="/modulename/checkout/purchase/id/<?php echo $_product->getId()?>"><?php echo $this->__('Download and Install') ?></a>
            <?php } ?>

然后使用 controllers / CheckoutController.php 包含以下代码:

Then create a new module with a controllers/CheckoutController.php containing this code:

public function purchaseAction() {
if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
        $this->_redirectUrl(Mage::getBaseUrl().'customer/account');
        return;
 }
 $request = $this->getRequest();
 $id = $request->getParam('id');
 $product = Mage::getModel('catalog/product')
                ->load($id)
                ->setStoreId(Mage::app()->getStore()->getId());
 if(!($product->getIsVirtual() && $product->getFinalPrice() == 0)){
     Mage::getSingleton('checkout/session')->addError($this->__('Method only available for Free Downloadable Items'));
     return $this;
 }
 $onepage = Mage::getSingleton('checkout/type_onepage');
 /* @var $onepage Mage_Checkout_Model_Type_Onepage */
 try{
     $quote = $onepage->getQuote();
     /* @var $quote Mage_Sales_Model_Quote */
     $quote->addProduct($product);
     Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
     $onepage->initCheckout();
     $payment=array('method'=>'free');
     $onepage->savePayment($payment);   
     $onepage->saveOrder();
     $this->getResponse()->setRedirect('/downloadable/customer/products');
 }
 catch(Exception $e){
     $result = $e->getMessage();
     Mage::getSingleton('checkout/session')->addError($result);
 }
 }

您需要更好地处理例外,但这应该在功能上是正确的。

You'll need to handle the Exceptions a little better, but that should be functionally correct.

这篇关于在Magento中跳过Checkout可下载的产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆