/** * Assign group prices to product data * * @param Mage_Catalog_Model_Abstract $object * @return $this */ public function afterLoad($object) { $data = $this->_getResource()->loadProfileData($object->getId(), $object->getEntityTypeId()); $object->setData($this->getAttribute()->getName(), $data); $object->setOrigData($this->getAttribute()->getName(), $data); 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_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; }
/** * 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; }
/** * 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; }