Beispiel #1
0
 /**
  * Validate attribute set name
  *
  * @param Mage_Eav_Model_Entity_Attribute_Set $object
  * @param string $attributeSetName
  * @return bool
  */
 public function validate($object, $attributeSetName)
 {
     $adapter = $this->_getReadAdapter();
     $bind = array('attribute_set_name' => trim($attributeSetName), 'entity_type_id' => $object->getEntityTypeId());
     $select = $adapter->select()->from($this->getMainTable())->where('attribute_set_name = :attribute_set_name')->where('entity_type_id = :entity_type_id');
     if ($object->getId()) {
         $bind['attribute_set_id'] = $object->getId();
         $select->where('attribute_set_id != :attribute_set_id');
     }
     return !$adapter->fetchOne($select, $bind) ? true : false;
 }
Beispiel #2
0
 /**
  * Validate attribute set name
  *
  * @param Mage_Eav_Model_Entity_Attribute_Set $object
  * @param string $name
  * @return bool
  */
 public function validate($object, $name)
 {
     $read = $this->_getReadAdapter();
     $select = $read->select()->from($this->getMainTable())->where("attribute_set_name=?", $name)->where("entity_type_id=?", $object->getEntityTypeId());
     if ($object->getId()) {
         $select->where("attribute_set_id!=?", $object->getId());
     }
     if (!$read->fetchOne($select)) {
         return true;
     }
     return false;
 }
 private function saveRelation()
 {
     if (!$this->attributeObj) {
         return array('result' => false, 'error' => "Attribute '{$this->code}' is not found.");
     }
     if (!$this->attributeSetObj) {
         return array('result' => false, 'error' => "Attribute Set '{$this->setId}' is not found.");
     }
     if ($this->checkIsAlreadyInSet()) {
         return array('result' => true);
     }
     $groupId = $this->getGroupId();
     $sortOrder = !empty($this->params['sorder']) ? $this->params['sorder'] : $this->getMaxSortOrderByGroup($groupId) + 1;
     !empty($this->params['sorder_ofset']) && ($sortOrder += $this->params['sorder_ofset']);
     /* @var $collection Mage_Eav_Model_Resource_Entity_Attribute */
     $relation = Mage::getModel('eav/entity_attribute');
     $relation->setEntityTypeId($this->attributeSetObj->getEntityTypeId())->setAttributeSetId($this->attributeSetObj->getId())->setAttributeGroupId($groupId)->setAttributeId($this->attributeObj->getId())->setSortOrder($sortOrder);
     try {
         $relation->save();
     } catch (Exception $e) {
         return array('result' => false, 'error' => $e->getMessage());
     }
     return array('result' => true, 'obj' => $relation);
 }