dongruan6001 2017-11-16 12:18
浏览 22
已采纳

访问Download.php上的$ item-> getNumberOfDownloadsUsed()函数

I need to get the number of downloads bought and used, that's two methods that are available on $item object. But I can't instance $item on the file that I'm working:

app/code/core/Mage/Downloadable/Helper/Download.php

On this file, I need to retrieve the number of boughts and used of the download purchased.

I'm also trying to get the order ID or at least the link hash to identify that number of boughts/used downloads with the unique id of the purchase.

For example, I try this:

Mage::getModel('downloadable/link_purchased_item')
            ->load($this->getOrderItem()->getOrder()->getId(), 'order_id');

But $this->getOrderItem() is not available on Download.php file. I was trying this:

Mage::getModel('downloadable/link_purchased_item')->getCollection()
            ->addFieldToFilter('order_item_id', $this->getOrderItem()->getId());

But obviously getOrderItem() is unavailable.

Fatal error: Call to undefined method Mage_Downloadable_Helper_Download::getOrderItem() in /[...]/app/code/core/Mage/Downloadable/Helper/Download.php on line 135

But I'm able to use the customer singleton to retrieve client data like this:

$cliente = Mage::getSingleton('customer/session')->getCustomer();

So on this file I'm able to access others methods, but I'm unable to get the following details:

  • Number of downloads bought
  • Number of downloads used
  • Order ID or Link hash ID.

So please, I'm requesting how to get the current order instance and / or the current link instance, on the Download.php related with the file downloading.

Thank you!

  • 写回答

1条回答 默认 最新

  • dougang6178 2017-11-17 08:46
    关注

    You are doing it wrong, you can not get any object like this $this->getOrderItem() without set/declaring them. As you are trying to get order_id and item_id in the helper, which you are using on a custom page redirected from customer downloadable products. Here is what you have to do

    Step - 1

    From customer My Downloadable products, in the redirect url you have to pass that products order_id and item_id as parameter. You can get them from below code

    $orderId = $_item->getPurchased()->getOrderId();
    $itemId = $_item->getId();
    

    Step -2

    Now in your template file while using your helper function pass this order_id and item_id to method parameter. Like below code

    $orderId = $this->getRequest()->getParam('order_param');
    $itemId = $this->getRequest()->getParam('item_param');
    
    //Your helper function
    Mage::helper('your_helper')->yourMethod($orderId, $itemId);
    

    Step - 3

    In your helper file you can use below code

    public function yourMethod($orderId, $itemId)
    {
        $linkPurchasedItem = Mage::getModel('downloadable/link_purchased_item')
                ->load($orderItem, 'order_id');
    
    
        $LinkPurchaseOrderItemId = Mage::getModel('downloadable/link_purchased_item')->getCollection()
                ->addFieldToFilter('order_item_id', $itemId);
    }
    

    Note: Do not make any changes in core files, instead override them

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)