Beispiel #1
0
 /**
  * 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);
         }
         if (Mage::getVersion() > '1.6.2.0') {
             $attribute->getBackend()->setEntityValueId($object, $valueId);
         } else {
             $attribute->getBackend()->setValueId($object, $valueId);
         }
     }
     return $this;
 }
Beispiel #2
0
 /**
  * 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;
 }
Beispiel #3
0
 public function testUnsetData()
 {
     $data = array('key1' => 'value1', 'key2' => 'value2');
     $this->_model->setData($data);
     // unset one locked
     $this->_model->lockAttribute('key1')->unsetData('key1');
     $this->assertEquals($data, $this->_model->getData());
     // unset all with read only
     $this->_model->setIsReadonly(true)->unsetData();
     $this->assertEquals($data, $this->_model->getData());
     // unset all
     $this->_model->unlockAttributes()->setIsReadonly(false)->unsetData();
     $this->assertEquals(array(), $this->_model->getData());
 }
 /**
  * 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;
 }
Beispiel #5
0
 /**
  * Initialize attribute value for object
  *
  * @param   Mage_Catalog_Model_Abstract $object
  * @param   array $valueRow
  * @return  Mage_Eav_Model_Entity_Abstract
  */
 protected function _setAttribteValue($object, $valueRow)
 {
     $attribute = $this->getAttribute($valueRow['attribute_id']);
     if ($attribute) {
         $attributeCode = $attribute->getAttributeCode();
         if (!empty($valueRow['store_value_id'])) {
             $value = $valueRow['store_value'];
             $valueId = $valueRow['store_value_id'];
             $object->setAttributeDefaultValue($attributeCode, $valueRow['value']);
         } else {
             $value = $valueRow['value'];
             $valueId = $valueRow['value_id'];
         }
         $object->setData($attributeCode, $value);
         $attribute->getBackend()->setValueId($valueId);
     }
     return $this;
 }
Beispiel #6
0
 /**
  * Initialize attribute value for object
  *
  * @param   Mage_Catalog_Model_Abstract $object
  * @param   array $valueRow
  * @return  Mage_Eav_Model_Entity_Abstract
  */
 protected function _setAttribteValue($object, $valueRow)
 {
     $attribute = $this->getAttribute($valueRow['attribute_id']);
     if ($attribute) {
         $attributeCode = $attribute->getAttributeCode();
         if (isset($this->_attributes[$valueRow['attribute_id']])) {
             if ($valueRow['store_id'] == $this->getDefaultStoreId()) {
                 $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);
         $attribute->getBackend()->setValueId($valueId);
     }
     return $this;
 }