Guest User

Untitled

a guest
May 8th, 2012
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. Better way to add attribute to collection
  2. protected function _prepareCollection()
  3. {
  4. $collection = Mage::getResourceModel($this->_getCollectionClass());
  5. foreach ($collection as &$object){
  6. $customer = Mage::getModel('customer/customer')
  7. ->setId($object->getCustomerId())
  8. ->load();
  9. $object->setCampaignId($customer->getCampaignId());
  10.  
  11. }
  12. $this->setCollection($collection);
  13. return parent::_prepareCollection();
  14. }
  15.  
  16. protected function _prepareCollection() {
  17.  
  18. $collection = Mage::getResourceModel($this->_getCollectionClass());
  19. $class = get_class($collection);
  20. $attribute = Mage::getModel('eav/config')
  21. ->getAttribute('customer', 'campaign_id');
  22. $attributeId = $attribute->getAttributeId();
  23. $backendType = $attribute->getBackendType(); //probably varchar
  24.  
  25. $tableName = Mage::getSingleton('core/resource')
  26. ->getTableName('customer_entity_' . $backendType);
  27.  
  28. $collection->getSelect()
  29. ->joinLeft(array('v' => $tableName),
  30. 'main_table.customer_id = v.entity_id AND attribute_id = 153',
  31. array('v.value', 'v.attribute_id'));
  32.  
  33. $this->setCollection($collection);
  34.  
  35. return parent::_prepareCollection();
  36. }
Advertisement
Add Comment
Please, Sign In to add comment