Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Better way to add attribute to collection
- protected function _prepareCollection()
- {
- $collection = Mage::getResourceModel($this->_getCollectionClass());
- foreach ($collection as &$object){
- $customer = Mage::getModel('customer/customer')
- ->setId($object->getCustomerId())
- ->load();
- $object->setCampaignId($customer->getCampaignId());
- }
- $this->setCollection($collection);
- return parent::_prepareCollection();
- }
- protected function _prepareCollection() {
- $collection = Mage::getResourceModel($this->_getCollectionClass());
- $class = get_class($collection);
- $attribute = Mage::getModel('eav/config')
- ->getAttribute('customer', 'campaign_id');
- $attributeId = $attribute->getAttributeId();
- $backendType = $attribute->getBackendType(); //probably varchar
- $tableName = Mage::getSingleton('core/resource')
- ->getTableName('customer_entity_' . $backendType);
- $collection->getSelect()
- ->joinLeft(array('v' => $tableName),
- 'main_table.customer_id = v.entity_id AND attribute_id = 153',
- array('v.value', 'v.attribute_id'));
- $this->setCollection($collection);
- return parent::_prepareCollection();
- }
Advertisement
Add Comment
Please, Sign In to add comment