/** * Override addItem to not attempt to use item id as key, and to set item root and path. * Also to ensure indexing on strings for safety with MongoId * * @param Varien_Object $item * @return Cm_Mongo_Model_Resource_Collection_Embedded */ public function addItem(Varien_Object $item) { $index = count($this->_items); $item->_setEmbeddedIn($this->_root, $this->_path . '.' . $index); $itemId = $item->getIdFieldName() ? $this->_getItemKey($item->getId()) : NULL; if ($itemId !== NULL) { if (isset($this->_items[$itemId])) { throw new Exception('Item (' . get_class($item) . ') with the same id "' . $item->getId() . '" already exist'); } $this->_items[$itemId] = $item; } else { $this->_items[] = $item; } return $this; }
public function render(Varien_Object $row) { $idField = $this->getColumn()->getIdField(); if (!$idField) { $idField = $row->getIdFieldName(); } $labelField = $this->getColumn()->getLabelField(); if ($labelField) { $label = $row->getData($labelField); } else { $label = $this->getObject()->getRowId($row); } $url = $this->getObject()->getAdminUrl($row->getData($idField)); if ($url) { return "<a href=\"{$url}\" target=\"_blank\">{$label}</a>"; } return $label; }
/** * Retrieve identifier field name for model * * @return string */ public function getIdFieldName() { if (!($fieldName = parent::getIdFieldName())) { $fieldName = $this->_getResource()->getIdFieldName(); $this->setIdFieldName($fieldName); } return $fieldName; }
/** * Save attribute * * @param Varien_Object $object * @param string $attributeCode * @return Mage_Eav_Model_Entity_Abstract */ public function saveAttribute(Varien_Object $object, $attributeCode) { $attribute = $this->getAttribute($attributeCode); $backend = $attribute->getBackend(); $entity = $attribute->getEntity(); $entityIdField = $entity->getEntityIdField(); $newValue = $object->getData($attributeCode); if ($attribute->isValueEmpty($newValue)) { $newValue = null; } $condition = array($object->getIdFieldName() => $object->getId()); if (!is_null($newValue)) { $operation = array('$set' => array($attributeCode => $newValue)); } else { $operation = array('$unset' => array($attributeCode => 1)); } $this->_getWriteAdapter()->getCollection($this->getEntityTable())->update($condition, $operation, array('multiple' => FALSE, 'safe' => TRUE)); return $this; }