在magento中获取某产品产生的总收入 [英] Get total revenue generated by a product in magento

查看:47
本文介绍了在magento中获取某产品产生的总收入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Magento中以编程方式获取产品产生的总收入?

How can I programmatically get the total revenue generated by a product in Magento?

假设有一种产品,其中id作为1,并且分别以10美元,5倍和5美元(折扣价),8倍的价格出售,所以我想从Magento总共获得90美元.这可能吗?

Suppose there is a product with id as 1 and it's sold at $10, five times and at $5 (discounted rate), eight times so i want to get a total of $90 from Magento. Is this possible??

推荐答案

有关我的代码建议的信息,请参见此处发布的答案

See the answer posted here for the basis of my code suggestion

Magento:如何显示产品已售出多少次?

由于您要在前端显示此值,因此我假设使用phtml,因此我将以此方式进行编码,然后尝试将最终价格乘以售出数量乘以该价格.

Since you are wanting to display this value in the frontend, i'm assuming phtml, so I'll code it that way, and just attempt to multiply final price by qty sold.

<?php
        // Enter your product ID here 
        $id = 123; 

        // Load the product collection and do some filters   
        $_productCollection = Mage::getResourceModel('reports/product_collection')
            ->addOrderedQty()
            ->addAttributeToFilter('id', $id)
            ->setOrder('ordered_qty', 'desc')
            ->getFirstItem();

        // Since the filter selects one product, we can use it here as the single result
        $product = $_productCollection;

        // Load the tax helper
        $_taxHelper  = Mage::helper('tax');

        // Get the final price of the product
        $finalprice = $_taxHelper->getPrice($product, $product->getFinalPrice(), true);


        // Print the results
        echo $product->getName() . " total revenue: " . (int)$product->ordered_qty * $finalprice;
?>

这是未经测试的,即时编码的,但是概念很基本,因此您可以毫无疑问地适应我展示的内容来完成所需的工作.

This is untested, coded on the fly, but the concepts are pretty basic so you should have no trouble adapting what I've shown to do what you need.

这篇关于在magento中获取某产品产生的总收入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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