/** * After Save Attribute manipulation * * @param Mage_Catalog_Model_Abstract $object * @return $this */ public function afterSave($object) { // var_dump($object);exit; $hasChanges = $object->dataHasChangedFor($this->getAttribute()->getName()); if (!$hasChanges) { return $this; } $data = $object->getData($this->getAttribute()->getName()); return $this; }
/** * Insert or Update attribute data * * @param Mage_Catalog_Model_Abstract $object * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute * @param mixed $value * @return Mage_Catalog_Model_Resource_Abstract */ protected function _saveAttributeValue($object, $attribute, $value) { $write = $this->_getWriteAdapter(); //set default store id $storeId = Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID; $table = $attribute->getBackend()->getTable(); /** * If we work in single store mode all values should be saved just * for default store id * In this case we clear all not default values */ if (Mage::app()->isSingleStoreMode()) { $storeId = $this->getDefaultStoreId(); $write->delete($table, array('attribute_id = ?' => $attribute->getAttributeId(), 'entity_id = ?' => $object->getEntityId(), 'store_id <> ?' => $storeId)); } $data = new Varien_Object(array('entity_type_id' => $attribute->getEntityTypeId(), 'attribute_id' => $attribute->getAttributeId(), 'store_id' => $storeId, 'entity_id' => $object->getEntityId(), 'value' => $this->_prepareValueForSave($value, $attribute))); $bind = $this->_prepareDataForTable($data, $table); if ($attribute->isScopeStore()) { /** * Update attribute value for store */ $this->_attributeValuesToSave[$table][] = $bind; } else { if ($attribute->isScopeWebsite() && $storeId != $this->getDefaultStoreId()) { /** * Update attribute value for website */ $storeIds = Mage::app()->getStore($storeId)->getWebsite()->getStoreIds(true); foreach ($storeIds as $storeId) { $bind['store_id'] = (int) $storeId; $this->_attributeValuesToSave[$table][] = $bind; } } else { /** * Update global attribute value */ $bind['store_id'] = $this->getDefaultStoreId(); $this->_attributeValuesToSave[$table][] = $bind; } } return $this; }
/** * Update attribute value for specific store * * @param Mage_Catalog_Model_Abstract $object * @param object $attribute * @param mixed $value * @param int $storeId * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Abstract */ protected function _updateAttributeForStore($object, $attribute, $value, $storeId) { $entityIdField = $attribute->getBackend()->getEntityIdField(); $select = $this->_getWriteAdapter()->select()->from($attribute->getBackend()->getTable(), 'value_id')->where('entity_type_id=?', $object->getEntityTypeId())->where("{$entityIdField}=?", $object->getId())->where('store_id=?', $storeId)->where('attribute_id=?', $attribute->getId()); /** * When value for store exist */ if ($valueId = $this->_getWriteAdapter()->fetchOne($select)) { $this->_getWriteAdapter()->update($attribute->getBackend()->getTable(), array('value' => $this->_prepareValueForSave($value, $attribute)), 'value_id=' . $valueId); } else { $this->_getWriteAdapter()->insert($attribute->getBackend()->getTable(), array($entityIdField => $object->getId(), 'entity_type_id' => $object->getEntityTypeId(), 'attribute_id' => $attribute->getId(), 'value' => $this->_prepareValueForSave($value, $attribute), 'store_id' => $storeId)); } return $this; }
/** * Init indexing process after category save * * @return Mage_Catalog_Model_Category */ protected function _afterSave() { $result = parent::_afterSave(); Mage::getSingleton('Mage_Index_Model_Indexer')->processEntityAction($this, self::ENTITY, Mage_Index_Model_Event::TYPE_SAVE); return $result; }
public function getCollection() { return parent::getCollection(); }
public function isEntityVisible(Mage_Catalog_Model_Abstract $entity, $customerGroupId = null) { // if the module is deactivated or a store view all entities are visible if (!$this->isModuleActive($entity->getStoreId())) { return true; } $cachedState = $entity->getData(self::HIDE_GROUPS_ATTRIBUTE_STATE_CACHE); if (!is_null($cachedState)) { return $cachedState; } // Default to the current customer group id if (is_null($customerGroupId)) { $customerGroupId = $this->getCustomerGroupId(); } $groupIds = $entity->getData(self::HIDE_GROUPS_ATTRIBUTE); if (!is_array($groupIds) && !is_string($groupIds)) { // If the value isn't set on the entity mode fall back to querying the db index table $visibility = Mage::getResourceSingleton('netzarbeiter_groupscatalog2/filter')->isEntityVisible($entity, $customerGroupId); $entity->setData(self::HIDE_GROUPS_ATTRIBUTE_STATE_CACHE, $visibility); return $visibility; } /* @var $entityType string The entity type code for the specified entity */ $entityType = $this->getEntityTypeCodeFromEntity($entity); if (is_string($groupIds)) { if ('' === $groupIds) { // This case will not happen in production: // at least USE_DEFAULT or USE_NONE should be in the value array. // Just your average paranoia... $groupIds = array(); } else { $groupIds = explode(',', $groupIds); } } if (in_array(self::USE_NONE, $groupIds)) { $groupIds = array(); } elseif (in_array(self::USE_DEFAULT, $groupIds)) { // Get the default settings for this entity type without applying the mode settings $groupIds = $this->getEntityVisibleDefaultGroupIds($entityType, $entity->getStore(), false); } // If the configured mode is 'show' the list of group ids must be inverse $groupIds = $this->applyConfigModeSettingByStore($groupIds, $entityType, $entity->getStore()); $visibility = in_array($customerGroupId, $groupIds); $entity->setData(self::HIDE_GROUPS_ATTRIBUTE_STATE_CACHE, $visibility); return $visibility; }
/** * Callback function which called after transaction commit in resource model * * @return Mage_Catalog_Model_Product */ public function afterCommitCallback() { parent::afterCommitCallback(); /** @var \Mage_Index_Model_Indexer $indexer */ $indexer = Mage::getSingleton('index/indexer'); $indexer->processEntityAction($this, self::ENTITY, Mage_Index_Model_Event::TYPE_SAVE); return $this; }
public function delete() { parent::delete(); Mage::dispatchEvent($this->_eventPrefix . '_delete_after_done', array($this->_eventObject => $this)); return $this; }
protected function _construct() { parent::_construct(); $this->_init('prolabels/index'); }
protected function _construct() { parent::_construct(); $this->_init('prolabels/sysstore'); }
/** * isEnabledProduct * * @param Mage_Catalog_Model_Abstract $product * @return boolean */ public function isEnabledProduct(Mage_Catalog_Model_Abstract $product) { return Mage_Catalog_Model_Product_Status::STATUS_ENABLED == $product->getStatus(); }
/** * Sets product image from it's child if possible * * @return string */ public function getImage() { $this->getTypeInstance()->setImageFromChildProduct($this); return parent::getImage(); }
/** * Before delete process * * @return Mage_Catalog_Model_Category */ protected function _beforeDelete() { $this->_protectFromNonAdmin(); if ($this->getResource()->isForbiddenToDelete($this->getId())) { Mage::throwException("Can't delete root category."); } return parent::_beforeDelete(); }
/** * Initialize attribute value for object * * @param Mage_Catalog_Model_Abstract $object * @param array $valueRow * @return Mage_Catalog_Model_Resource_Abstract */ protected function _setAttributeValue($object, $valueRow) { $attribute = $this->getAttribute($valueRow['attribute_id']); if ($attribute) { $attributeCode = $attribute->getAttributeCode(); $isDefaultStore = $valueRow['store_id'] == $this->getDefaultStoreId(); if (isset($this->_attributes[$valueRow['attribute_id']])) { if ($isDefaultStore) { $object->setAttributeDefaultValue($attributeCode, $valueRow['value']); } else { $object->setAttributeDefaultValue($attributeCode, $this->_attributes[$valueRow['attribute_id']]['value']); } } else { $this->_attributes[$valueRow['attribute_id']] = $valueRow; } $value = $valueRow['value']; $valueId = $valueRow['value_id']; $object->setData($attributeCode, $value); if (!$isDefaultStore) { $object->setExistsStoreValueFlag($attributeCode); } // $attribute->getBackend()->setEntityValueId($object, $valueId); $attribute->getBackend()->setValueId($valueId); } return $this; }
protected function _beforeDelete() { $this->_protectFromNonAdmin(); return parent::_beforeDelete(); }
/** * Set original loaded data if needed * * @param string $key * @param mixed $data * @return Varien_Object */ public function setOrigData($key = null, $data = null) { if (Mage::app()->getStore()->isAdmin()) { return parent::setOrigData($key, $data); } return $this; }
/** * Generate unique url key if current url key already occupied * * @param Mage_Catalog_Model_Abstract $object * @return Mage_Catalog_Model_Abstract */ protected function _generateNextUrlKeySuffix(Mage_Catalog_Model_Abstract $object) { $prefixValue = $object->getData($this->getAttribute()->getAttributeCode()); $requestPathField = new Zend_Db_Expr($this->_connection->quoteIdentifier('value')); //select increment part of request path and cast expression to integer $urlIncrementPartExpression = $this->_eavHelper->getCastToIntExpression($this->_connection->getSubstringSql($requestPathField, strlen($prefixValue) + 1, $this->_connection->getLengthSql($requestPathField) . ' - ' . strlen($prefixValue))); $prefixRegexp = preg_quote($prefixValue); $orCondition = $this->_connection->select()->orWhere($this->_connection->prepareSqlCondition('value', array('regexp' => '^' . $prefixRegexp . '$')))->orWhere($this->_connection->prepareSqlCondition('value', array('regexp' => '^' . $prefixRegexp . '-[0-9]*$')))->getPart(Zend_Db_Select::WHERE); $select = $this->_connection->select(); $select->from($this->getAttribute()->getBackendTable(), new Zend_Db_Expr('MAX(ABS(' . $urlIncrementPartExpression . '))'))->where('value LIKE :url_key')->where('entity_id <> :entity_id')->where(implode('', $orCondition)); $bind = array('url_key' => $prefixValue . '%', 'entity_id' => (int) $object->getId()); $suffix = $this->_connection->fetchOne($select, $bind); if (!is_null($suffix)) { $suffix = (int) $suffix; $object->setData($this->getAttribute()->getAttributeCode(), sprintf('%s-%s', $prefixValue, ++$suffix)); } return $object; }
/** * @covers Mage_Catalog_Model_Abstract::isReadonly * @covers Mage_Catalog_Model_Abstract::setIsReadonly */ public function testIsReadonly() { $this->assertFalse($this->_model->isReadonly()); $this->_model->setIsReadonly(true); $this->assertTrue($this->_model->isReadonly()); }
/** * Get cahce tags associated with object id * * @return array */ public function getCacheIdTags() { $tags = parent::getCacheIdTags(); $affectedCategoryIds = $this->getAffectedCategoryIds(); if (!$affectedCategoryIds) { $affectedCategoryIds = $this->getCategoryIds(); } foreach ($affectedCategoryIds as $categoryId) { $tags[] = Mage_Catalog_Model_Category::CACHE_TAG . '_' . $categoryId; } return $tags; }
/** * Saving product type related data * * @return unknown */ protected function _afterSave() { $this->getLinkInstance()->saveProductRelations($this); $this->getTypeInstance()->save(); return parent::_afterSave(); }
/** * Update attribute value for specific store * * @param Mage_Catalog_Model_Abstract $object * @param object $attribute * @param mixed $value * @param int $storeId * @return Mage_Catalog_Model_Resource_Abstract */ protected function _updateAttributeForStore($object, $attribute, $value, $storeId) { $adapter = $this->_getWriteAdapter(); $table = $attribute->getBackend()->getTable(); $entityIdField = $attribute->getBackend()->getEntityIdField(); $select = $adapter->select()->from($table, 'value_id')->where('entity_type_id = :entity_type_id')->where("{$entityIdField} = :entity_field_id")->where('store_id = :store_id')->where('attribute_id = :attribute_id'); $bind = array('entity_type_id' => $object->getEntityTypeId(), 'entity_field_id' => $object->getId(), 'store_id' => $storeId, 'attribute_id' => $attribute->getId()); $valueId = $adapter->fetchOne($select, $bind); /** * When value for store exist */ if ($valueId) { $bind = array('value' => $this->_prepareValueForSave($value, $attribute)); $where = array('value_id = ?' => (int) $valueId); $adapter->update($table, $bind, $where); } else { $bind = array($idField => (int) $object->getId(), 'entity_type_id' => (int) $object->getEntityTypeId(), 'attribute_id' => (int) $attribute->getId(), 'value' => $this->_prepareValueForSave($value, $attribute), 'store_id' => (int) $storeId); $adapter->insert($table, $bind); } return $this; }
/** * Lock a specific category or product attribute so that it can not be editted through the interface. * @param Mage_Eav_Model_Entity_Attribute $attribute * @param Mage_Catalog_Model_Abstract $model * @param $profile */ protected function _lockAttribute(Mage_Eav_Model_Entity_Attribute $attribute, Mage_Catalog_Model_Abstract $model, $profile) { $note = $attribute->getNote() ? $attribute->getNote() : ''; if ($attribute->getAttributeCode() == 'ho_import_profile') { return; } if ($note) { $note .= "<br />\n"; } $note .= Mage::helper('ho_import')->__("Locked by import: <i>%s</i>", $profile); $model->lockAttribute($attribute->getAttributeCode()); $attribute->setNote($note); }