/** * Load the confgi data into the passed $object * * @param Core_Model_Abstract $object * @param string $scope * @param int $scopeId * @return Core_Model_Abstract */ public function loadConfigData(Core_Model_Abstract $object, $scope = 'default', $scopeId = 0) { $results = $this->_getReadAdapter()->fetchAll("SELECT * FROM " . $this->tbl_config_data . " WHERE scope='" . $scope . "' AND scope_id=" . $scopeId . "\n GROUP BY path ORDER BY scope DESC"); if (!$results) { return $object; } foreach ($results as $result) { $object->setData($result['path'], $result['value']); } return $object; }
/** * Load the eav data into the object * If attributes is passed (array of attribute_code) the data values will be loaded only for the specified attributes * * @param Core_Model_Abstract $object * @param array $attributes * @return Core_Model_Abstract */ public function loadEavData(Core_Model_Abstract $object, $attributes = array()) { $entityId = $object->getId(); $entityTypeId = $object->getEntityTypeId(); if (empty($entityId) || empty($entityTypeId)) { return false; } $sql = "SELECT\n tbl_attr.attribute_code,\n tbl_attr.attribute_id,\n tbl_attr.frontend_input,\n tbl_value.value\n FROM\n valueTable AS tbl_value\n LEFT JOIN " . $this->tbl_eav_entity_attribute . " AS tbl_entity_attr ON tbl_entity_attr.attribute_id = tbl_value.attribute_id\n LEFT JOIN " . $this->tbl_eav_attribute . " AS tbl_attr ON tbl_attr.attribute_id = tbl_entity_attr.attribute_id\n WHERE\n tbl_value.entity_id = " . $entityId . "\n AND tbl_entity_attr.entity_type_id = " . $entityTypeId . ""; //load the data only for the specific attributes if given if (!empty($attributes) && is_array($attributes)) { $sql .= " AND tbl_attr.attribute_code IN ('" . implode("','", $attributes) . "')"; } $eavOptionValues = array(); foreach ($this->tbl_set_eav as $table) { $result = $this->_getReadAdapter()->fetchAll(str_replace('valueTable', $table, $sql)); if (empty($result)) { continue; } foreach ($result as $row) { $object->setData($row['attribute_code'], $row['value']); if ($row['frontend_input'] == 'select' || $row['frontend_input'] == 'multiselect') { $valueId = intval($row['value']); if (empty($valueId)) { continue; } $optionValue = $this->_getReadAdapter()->fetchColumn("SELECT value FROM " . $this->tbl_eav_attr_option_value . " WHERE value_id IN (" . $valueId . ")", 'value'); $eavOptionValues[$row['attribute_code']] = implode(',', $optionValue); } } } //set the origianl data prior to adding the display data $object->setOrigData(); //set the attribute option values foreach ($eavOptionValues as $attributeCode => $value) { $object->setData($attributeCode, $value); } return $object; }
/** * Load an object model data from db * * @param Core_Model_Abstract $object * @param mixed $value * @param string $field field to load by (defaults to model id) * @return Core_Model_Resource_Abstract */ public function load(Core_Model_Abstract $object, $value, $field = null) { if (is_null($field)) { $field = $this->getIdFieldName(); } $read = $this->_getReadAdapter(); if (!is_null($value)) { $data = $this->_getReadAdapter()->fetchRow("SELECT * FROM " . $this->getMainTable() . " WHERE " . $field . "='" . $value . "'"); if ($data) { $object->setData($data); } } if ($object->getId()) { $this->_afterLoad($object); } return $this; }