Example #1
0
 /**
  * Save the value for the supplied attribute, using the primary key
  * values from the table this EAV definition is registered to.
  *
  * @param string $name The name of the attribute to save (e.g. "eav_1")
  * @param mixed $value
  * @param array $pkeyValues
  */
 public function save($name, $value, array $pkeyValues)
 {
     $db = $this->table->getAdapter();
     $pkeyColumns = $this->table->getPrimaryKey();
     $attribute = $this->getAttribute($name);
     $valueTable = $this->getBackendTypeTableName($attribute['backend_type']);
     $valueQuoted = $db->quoteIdentifier($valueTable);
     $where = $this->table->assembleFindWhere($pkeyValues);
     $sql = $db->quoteInto("SELECT true FROM {$valueQuoted} WHERE {$where} AND attribute_id = ?", $attribute['attribute_id']);
     if (is_bool($value)) {
         $value = (int) $value;
     }
     if ($db->fetchOne($sql)) {
         $db->update($valueTable, array('value' => $value), $db->quoteInto("{$where} AND attribute_id = ?", $attribute['attribute_id']));
     } else {
         $data = array('attribute_id' => $attribute['attribute_id'], 'value' => $value);
         foreach ($pkeyColumns as $i => $name) {
             $data[$name] = $pkeyValues[$i];
         }
         $db->insert($valueTable, $data);
     }
 }