Exemplo n.º 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;
 }
Exemplo n.º 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;
 }
Exemplo n.º 3
0
 private function saveAttributeSet()
 {
     if ($this->attributeSetObj->getId()) {
         return array('result' => true, 'obj' => $this->attributeSetObj);
     }
     $this->attributeSetObj->setEntityTypeId($this->entityTypeId)->setAttributeSetName($this->setName);
     try {
         $this->attributeSetObj->validate();
         $this->attributeSetObj->save();
         $this->attributeSetObj->initFromSkeleton($this->skeletonId)->save();
     } catch (Exception $e) {
         return array('result' => false, 'error' => $e->getMessage());
     }
     return array('result' => true, 'obj' => $this->attributeSetObj);
 }
 /**
  * Assigns the attribute to the attribute set
  *
  * @param Mage_Eav_Model_Entity_Attribute $attribute
  * @param Mage_Eav_Model_Entity_Attribute_Set $attributeSet
  * @param int $attributeGroupId
  */
 protected function _assignAttributeToAttributeSet($attribute, $attributeSet, $attributeGroupId)
 {
     $entityTypeId = $this->_getEntityTypeId();
     $setup = Mage::getModel('eav/entity_setup', 'core_setup');
     $setup->addAttributeToSet($entityTypeId, $attributeSet->getId(), $attributeGroupId, $attribute->getId());
 }
Exemplo n.º 5
0
 public function testValidateWithNonexistentValidName()
 {
     $this->_model->getResource()->expects($this->any())->method('validate')->will($this->returnValue(true));
     $this->_model->setAttributeSetName('nonexistent_name');
     $this->assertTrue($this->_model->validate());
 }
Exemplo n.º 6
0
 /**
  * @param Mage_Eav_Model_Entity_Attribute_Set $obj
  * @return $this
  */
 public function setAttributeSetObj(Mage_Eav_Model_Entity_Attribute_Set $obj)
 {
     $this->attributeSetObj = $obj;
     $this->attributeSetId = $obj->getId();
     return $this;
 }