Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Changes to Cart Helper
 
seldon
Sr. Member
 
Total Posts:  92
Joined:  2007-11-08
 

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?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

@seldon: overwrite app/code/core/Mage/Core/Model/Config.php with attached file to be able to override helpers same like blocks and models:

<config>
...
  <global>
...
    <
helpers>
      <
checkout>
        <
rewrite>
          <
cart>Mage_Seldon_Helper_Cart</cart>
        </
rewrite>
      </
checkout>
    </
helpers>
  </global>
...
</
config>
File Attachments
Config.php  (File Size: 20KB - Downloads: 165)
 
Magento Community Magento Community
Magento Community
Magento Community
 
seldon
Sr. Member
 
Total Posts:  92
Joined:  2007-11-08
 

Hi Moshe,

Thnx a lot! Ill give it a try first thing in the morning!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brikou Carré
Member
 
Avatar
Total Posts:  37
Joined:  2007-10-04
 

@Moshe

Do you think it will be possible to overload controller this way… because I’ve tried with url rewritting (http://www.magentocommerce.com/boards/viewthread/1286/#t6885) but this is pretty complicated (I have to create a new module in which I create a new controller which inherits from base controller).

Furthermore, I’ve done this (I wanted to overload shippingPost method to add delivery date), but I cannot access post request data… so it is much more complicated and worst of it I cannot make this work out…

THX

 
Magento Community Magento Community
Magento Community
Magento Community
 
seldon
Sr. Member
 
Total Posts:  92
Joined:  2007-11-08
 

Overriding the helper seems to work! Thnx!

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top