/** * Check unique url_key value in catalog_category_entity_url_key table. * * @param Mage_Catalog_Model_Abstract $object * @return bool * @throws Mage_Core_Exception */ protected function _isAvailableUrl($object) { $select = $this->_connection->select()->from($this->getAttribute()->getBackendTable(), array('entity_id', 'store_id'))->where('value = ?', $object->getUrlKey())->limit(1); $row = $this->_connection->fetchRow($select); // we should allow save same url key for product in current store view // but not allow save existing url key in current store view from another store view if (empty($row)) { return true; } elseif ($object->getId() && $object->getStoreId() !== null && ($row['store_id'] == $object->getStoreId() && $row['entity_id'] == $object->getId())) { return true; } return false; }
/** * 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(); $storeId = (int) Mage::app()->getStore($object->getStoreId())->getId(); $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; }
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; }