本文整理汇总了PHP中AttributeValue::store方法的典型用法代码示例。如果您正苦于以下问题:PHP AttributeValue::store方法的具体用法?PHP AttributeValue::store怎么用?PHP AttributeValue::store使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AttributeValue
的用法示例。
在下文中一共展示了AttributeValue::store方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: safeUp
public function safeUp()
{
$this->createTable('{{store_product_attribute_value}}', ['id' => 'pk', 'product_id' => 'INTEGER NOT NULL', 'attribute_id' => 'INTEGER NOT NULL', 'number_value' => 'REAL', 'string_value' => 'VARCHAR(250)', 'text_value' => 'TEXT', 'option_value' => 'INTEGER', 'create_time' => 'DATETIME'], $this->getOptions());
//fk
$this->addForeignKey('{{fk_product_attribute_product}}', '{{store_product_attribute_value}}', 'product_id', '{{store_product}}', 'id', 'CASCADE');
$this->addForeignKey('{{fk_product_attribute_attribute}}', '{{store_product_attribute_value}}', 'attribute_id', '{{store_attribute}}', 'id', 'CASCADE');
$this->addForeignKey('{{fk_product_attribute_option}}', '{{store_product_attribute_value}}', 'option_value', '{{store_attribute_option}}', 'id', 'CASCADE');
//ix
$this->createIndex('{{ix_product_attribute_number_value}}', '{{store_product_attribute_value}}', 'number_value');
$this->createIndex('{{ix_product_attribute_string_value}}', '{{store_product_attribute_value}}', 'string_value');
//перенести аттрибуты
$attributes = Yii::app()->getDb()->createCommand('SELECT * FROM {{store_product_attribute_eav}}')->queryAll();
$modelsAttr = [];
foreach ($attributes as $attribute) {
$product = Product::model()->findByPk($attribute['product_id']);
if (null === $product) {
continue;
}
if (!isset($modelsAttr[$attribute['attribute']])) {
$model = Attribute::model()->find('name = :name', [':name' => $attribute['attribute']]);
if (null === $model) {
continue;
}
$modelsAttr[$attribute['attribute']] = $model;
}
$value = new AttributeValue();
$value->store($modelsAttr[$attribute['attribute']]->id, $attribute['value'], $product);
}
$this->dropTable('{{store_product_attribute_eav}}');
}
示例2: saveTypeAttributes
/**
* @param array $attributes
* @return bool
*/
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;
}
}
示例3: saveTypeAttributes
/**
* @param array $attributes
* @return bool
*/
public function saveTypeAttributes(array $attributes)
{
$transaction = Yii::app()->getDb()->beginTransaction();
try {
AttributeValue::model()->deleteAll('product_id = :id', [':id' => $this->id]);
foreach ($attributes as $attribute => $value) {
if (null == $value) {
continue;
}
//необходимо определить в какое поле сохраняем значение
$model = new AttributeValue();
$model->store($attribute, $value, $this);
}
$transaction->commit();
} catch (Exception $e) {
$transaction->rollback();
return false;
}
}