【问题标题】:Skip Checkout in Magento for a downloadable product在 Magento 中跳过结帐以获取可下载的产品
【发布时间】:2011-02-07 07:04:51
【问题描述】:

我正在使用 Magento 构建一个电子书网站。对于该版本,我们计划提供一些免费的可下载书籍。我们希望可以使用正常的 Magento '目录' 功能来添加产品类别。但是,由于这些是免费的可下载产品,因此在用户尝试下载时让他们通过结帐是没有意义的。

有没有人知道创建完全绕过结帐的免费下载产品的方法?我注意到可下载产品有一个“免费样品”选项,但如果可以的话,我不希望使用它,因为我计划在添加付费产品时将此字段用于其预期目的。

[编辑] 我注意到你们中的一些人因为“缺乏问题的清晰度”而否决了这个问题。为了清楚起见,我想要:

  1. 知道是否有可能 创建一个可下载的产品 不需要用户的 Magento 通过通常的结帐 进程(因为它是免费的)
  2. 和 这不是“免费样品”字段 一个可下载的产品

不幸的是,我认为我不能再雄辩地问这个问题了。 [/编辑]

【问题讨论】:

  • 我的猜测是人们可能不喜欢这个标题。听起来确实有点像垃圾邮件。也许类似于“在 Magento 中跳过结帐”?
  • 很好的反馈,-我已经更新了标题。
  • 您是想将下载记录为“订单”还是让人们抓取它们。作为订单,您可以查看下载者的历史记录...

标签: php magento download product


【解决方案1】:

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

将以下行添加到您的catalog/product/list.phtml 中您想要的位置。

<?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 的新模块,其中包含以下代码:

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);
 }
 }

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

【讨论】:

    【解决方案2】:

    我最好的盲目猜测(查看 Mage_Downloadable 中的块和模型)是使用产品类型实例。因此,在您的产品模板中的某处,您也许可以这样做:

    // $_product is the current product
    $links = $product->getTypeInstance(true)->getLinks();
    if(count($links)) {
        foreach($links as $link) {
            print "<a href='". $this->getUrl('downloadable/download/link', array(
                'id'        => $item->getLinkHash(),
                '_secure'   => true,
                '_nosid'    => true
            )) . "'>Download</a>";
        }
    }
    

    如果没有,我希望至少能让你走上正确的道路。

    希望对您有所帮助。谢谢, 乔

    【讨论】:

    • 谢谢。看起来我的一位同事设法使用可配置产品做到了这一点,但我不确定如何。如果我发现我会在这里发布。
    【解决方案3】:

    您可以循环浏览可下载链接的列表并为每个链接添加一个链接。

    $links=Mage::getModel('downloadable/link')
            ->getCollection()
            ->addFieldToFilter('product_id',array('eq'=>$_product->getId()));
    
    foreach($links as $link){
        echo "<a href='" . $link->getLink_url() . "'>Download</a>";
    }
    

    【讨论】:

      猜你喜欢
      • 2013-06-20
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-14
      • 2019-06-20
      相关资源
      最近更新 更多