Product::saveTypeAttributes PHP Method

saveTypeAttributes() public method

public saveTypeAttributes ( array $attributes ) : boolean
$attributes array
return boolean
    public function saveTypeAttributes(array $attributes)
    {
        $transaction = Yii::app()->getDb()->beginTransaction();
        try {
            foreach ($attributes as $attribute => $value) {
                if (null === $value) {
                    continue;
                }
                $model = AttributeValue::model()->find('product_id = :product AND attribute_id = :attribute', [':product' => $this->id, ':attribute' => $attribute]);
                //множественные значения
                if (is_array($value)) {
                    AttributeValue::model()->deleteAll('product_id = :product AND attribute_id = :attribute', [':product' => $this->id, ':attribute' => $attribute]);
                    foreach ($value as $val) {
                        $model = new AttributeValue();
                        if (false === $model->store($attribute, $val, $this)) {
                            throw new InvalidArgumentException('Error store attribute!');
                        }
                    }
                } else {
                    $model = $model ?: new AttributeValue();
                    if (false === $model->store($attribute, $value, $this)) {
                        throw new InvalidArgumentException('Error store attribute!');
                    }
                }
            }
            $transaction->commit();
            return true;
        } catch (Exception $e) {
            $transaction->rollback();
            return false;
        }
    }