cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to display the total number of carts an item is in

Trying to display the total number of carts an item is in

I'm trying to add the total number of carts a product is in when viewing the main product page on the frontend (view.phtml). The goal is the customer would see, "2 available, in 8 other shopping carts", for example.

 

There's an admin report in Reports > Shopping Cart > Products in Carts, and the totals are there. However, it needs to be visible on the frontend, and just for the current item being viewed.

 

Here's the _prepareCollection() function I'm looking at in Mage/Adminhtml/Block/Report/Shopcart/Product/Grid.php:

 

    protected function _prepareCollection()
    {
        /** @var $collection Mage_Reports_Model_Resource_Quote_Collection */
        $collection = Mage::getResourceModel('reports/quote_collection');
        $collection->prepareForProductsInCarts()
            ->setSelectCountSqlType(Mage_Reports_Model_Resource_Quote_Collection::SELECT_COUNT_SQL_TYPE_CART);
        $this->setCollection($collection);
        return parent::_prepareCollection();
    }

Thanks for reading.

Any guidance is appreciated.