0

Magentoの製品によって生み出された総収益をプログラムで取得するにはどうすればよいですか?

idasの製品があり1、それが$ 10で5回、$ 5(割引料金)で8回販売されているとすると、Magentoから合計$90を取得したいとします。これは可能ですか?

4

1 に答える 1

0

私のコード提案の基礎については、ここに投稿された回答を参照してください

Magento: 商品の販売回数を表示するには?

この値をフロントエンドに表示したいので、phtml を想定しているので、そのようにコーディングし、最終価格に販売数量を掛けようとします。

<?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;
?>

これはテストされておらず、その場でコード化されていますが、概念はかなり基本的なものなので、必要なことを行うために私が示したことを問題なく適応させることができます.

于 2013-01-08T20:07:04.470 に答える