Magento:如何显示产品已售出多少次? [英] Magento: How to display how many times a product has been sold?

查看:45
本文介绍了Magento:如何显示产品已售出多少次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的主页上显示产品的总销售额.该怎么办?

I want to echo on my homepage the total sales of a product. How can this be done?

我还想知道如何在首页上查询已售商品总数(数量).

Also i would like to know how to query Total items sold (quantity) on the front page.

在我的商店中,只有1种产品(虚拟).

In my shop, there will be only 1 product (virtual).

修改:

我找到了此代码,并且在产品的查看页面中效果很好.

I found this code and it works pretty well in the product's view page.

$sku = nl2br($_product->getSku());
$_productCollection = Mage::getResourceModel('reports/product_collection')
    ->addOrderedQty()
    ->addAttributeToFilter('sku', $sku)
    ->setOrder('ordered_qty', 'desc')
    ->getFirstItem();
$product = $_productCollection;

echo 'Already Bought '.(int)$product->ordered_qty; 

但是在首页上,我如何直接指向我想要的产品的ID?

But on the front page, how would I point directly to the ID of the product i want?

推荐答案

这应该有效:

$id = 123; // enter your product ID here
$product = Mage::getResourceModel('reports/product_collection')
    ->addOrderedQty()
    ->addAttributeToFilter('id', $id)
    ->setOrder('ordered_qty', 'desc')
    ->getFirstItem();

echo 'Already Bought '.(int)$product->ordered_qty;

这篇关于Magento:如何显示产品已售出多少次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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