|
Since i required to get the count of the number of distinct products in the cart , i changed the helper class (since i do not know how to override it) as follows.
public function getCount(){ if (is_null($this->_itemCount)) { $quoteId = Mage::getSingleton('checkout/session')->getQuoteId(); $this->_itemCount = Mage::getResourceModel('checkout/cart')->fetchItemsQty($quoteId); } return $this->_itemCount;
}
public function getItemCount() { if (is_null($this->_itemSummaryCount)) {
$quoteId = Mage::getSingleton('checkout/session')->getQuoteId(); $this->_itemSummaryCount = Mage::getResourceModel('checkout/cart')->fetchItemsSummaryQty($quoteId); } return $this->_itemSummaryCount; }
And I added the fetchItemsQty function to the resource “Mage_Checkout_Model_Mysql4_Cart”
public function fetchItemsQty($quoteId){ $entityType = Mage::getSingleton('eav/config')->getEntityType('quote_item'); $qtyEntityTypeId = $entityType->getEntityTypeId(); $attribute = Mage::getSingleton('eav/config')->getAttribute($qtyEntityTypeId, 'qty'); $qtyAttributeId = $attribute->getAttributeId(); $qtyAttributeTable = $this->getMainTable().'_'.$attribute->getBackendType(); $read = $this->getConnection('read'); $select = $read->select() ->from(array('qty'=>$qtyAttributeTable), 'count(*)') ->join(array('e'=>$this->getMainTable()), 'e.entity_id=qty.entity_id', array()) ->where('e.parent_id=?', $quoteId) ->where('qty.entity_type_id=?', $qtyEntityTypeId) ->where('qty.attribute_id=?', $qtyAttributeId); $qty = $read->fetchOne($select); return $qty; }
Perhaps it is possible that these modifications can be implemented in the core codebase? Or is this not necessary and does an easey way to obtain the above already exist?
|