/** * @inheritdoc */ public function actions() { return ['remove-all' => ['class' => MultipleDelete::className(), 'modelName' => Currency::className()], 'delete' => ['class' => DeleteOne::className(), 'modelName' => Currency::className()], 'update-editable' => ['class' => UpdateEditable::className(), 'modelName' => Currency::className(), 'allowedAttributes' => ['currency_rate_provider_id' => function (Currency $model, $attribute) { if ($model === null || $model->rateProvider === null || $model->currency_rate_provider_id === 0) { return null; } return \yii\helpers\Html::tag('div', $model->rateProvider->name, ['class' => $model->rateProvider->name]); }]]]; }
/** * Returns model instance by ID using IdentityMap * @param integer $id * @return Currency */ public static function findById($id) { if (!isset(static::$identity_map[$id])) { static::$identity_map[$id] = Yii::$app->cache->get('Currency: ' . $id); if (static::$identity_map[$id] === false) { static::$identity_map[$id] = Currency::findOne($id); if (is_object(static::$identity_map[$id])) { Yii::$app->cache->set('Currency: ' . $id, static::$identity_map[$id], 86400, new TagDependency(['tags' => [\devgroup\TagDependencyHelper\ActiveRecordHelper::getObjectTag(Currency::className(), $id)]])); } } } return static::$identity_map[$id]; }
public function getCurrency() { return $this->hasOne(Currency::className(), ['id' => 'currency_id']); }
<div class="row"> <div class="col-md-4"> <?php echo TreeWidget::widget(['treeDataRoute' => ['getTree'], 'doubleClickAction' => ContextMenuHelper::actionUrl(['index', 'returnUrl' => Helper::getReturnUrl()], ['parent_id' => 'id']), 'contextMenuItems' => ['show' => ['label' => 'Show products in category', 'icon' => 'fa fa-folder-open', 'action' => ContextMenuHelper::actionUrl(['index'], ['parent_id' => 'id'])], 'createProduct' => ['label' => 'Create product in this category', 'icon' => 'fa fa-plus-circle', 'action' => ContextMenuHelper::actionUrl(['edit', 'returnUrl' => Helper::getReturnUrl()], ['parent_id' => 'id'])], 'edit' => ['label' => 'Edit category', 'icon' => 'fa fa-pencil', 'action' => ContextMenuHelper::actionUrl(['/shop/backend-category/edit', 'returnUrl' => Helper::getReturnUrl()])], 'create' => ['label' => 'Create category', 'icon' => 'fa fa-plus-circle', 'action' => ContextMenuHelper::actionUrl(['/shop/backend-category/edit', 'returnUrl' => Helper::getReturnUrl()], ['parent_id' => 'id'])], 'delete' => ['label' => 'Delete', 'icon' => 'fa fa-trash-o', 'action' => new \yii\web\JsExpression("function(node) {\n jQuery('#delete-category-confirmation')\n .attr('data-url', '/backend/category/delete?id=' + jQuery(node.reference[0]).data('id'))\n .attr('data-items', '')\n .modal('show');\n return true;\n }")]]]); ?> </div> <div class="col-md-8" id="jstree-more"> <?php echo DynaGrid::widget(['options' => ['id' => 'Product-grid'], 'columns' => [['class' => \kartik\grid\CheckboxColumn::className(), 'options' => ['width' => '10px']], ['class' => 'yii\\grid\\DataColumn', 'attribute' => 'id'], ['class' => 'yii\\grid\\DataColumn', 'attribute' => 'name'], 'slug', ['class' => \kartik\grid\EditableColumn::className(), 'attribute' => 'active', 'editableOptions' => ['data' => [0 => Yii::t('app', 'Inactive'), 1 => Yii::t('app', 'Active')], 'inputType' => 'dropDownList', 'placement' => 'left', 'formOptions' => ['action' => 'update-editable']], 'filter' => [0 => Yii::t('app', 'Inactive'), 1 => Yii::t('app', 'Active')], 'format' => 'raw', 'value' => function (Product $model) { if ($model === null || $model->active === null) { return null; } if ($model->active === 1) { $label_class = 'label-success'; $value = 'Active'; } else { $value = 'Inactive'; $label_class = 'label-default'; } return \yii\helpers\Html::tag('span', Yii::t('app', $value), ['class' => "label {$label_class}"]); }], ['class' => 'kartik\\grid\\EditableColumn', 'attribute' => 'price', 'editableOptions' => ['inputType' => \kartik\editable\Editable::INPUT_TEXT, 'formOptions' => ['action' => 'update-editable']]], ['class' => 'kartik\\grid\\EditableColumn', 'attribute' => 'old_price', 'editableOptions' => ['inputType' => \kartik\editable\Editable::INPUT_TEXT, 'formOptions' => ['action' => 'update-editable']]], ['attribute' => 'currency_id', 'class' => \kartik\grid\EditableColumn::className(), 'editableOptions' => ['data' => [0 => '-'] + \app\components\Helper::getModelMap(\app\modules\shop\models\Currency::className(), 'id', 'name'), 'inputType' => 'dropDownList', 'placement' => 'left', 'formOptions' => ['action' => 'update-editable']], 'filter' => \app\components\Helper::getModelMap(\app\modules\shop\models\Currency::className(), 'id', 'name'), 'format' => 'raw', 'value' => function ($model) { if ($model === null || $model->currency === null || $model->currency_id === 0) { return null; } return \yii\helpers\Html::tag('div', $model->currency->name, ['class' => $model->currency->name]); }], ['class' => 'kartik\\grid\\EditableColumn', 'attribute' => 'sku', 'editableOptions' => ['inputType' => \kartik\editable\Editable::INPUT_TEXT, 'formOptions' => ['action' => 'update-editable'], 'placement' => 'left']], 'date_modified', ['class' => 'app\\backend\\components\\ActionColumn', 'buttons' => [['url' => '@product', 'icon' => 'eye', 'class' => 'btn-info', 'label' => Yii::t('app', 'Preview'), 'appendReturnUrl' => false, 'url_append' => '', 'attrs' => ['model', 'mainCategory.category_group_id'], 'keyParam' => null], ['url' => 'edit', 'icon' => 'pencil', 'class' => 'btn-primary', 'label' => Yii::t('app', 'Edit')], ['url' => 'clone', 'icon' => 'copy', 'class' => 'btn-success', 'label' => Yii::t('app', 'Clone')], ['url' => 'delete', 'icon' => 'trash-o', 'class' => 'btn-danger', 'label' => Yii::t('app', 'Delete'), 'options' => ['data-action' => 'delete']]]]], 'theme' => 'panel-default', 'gridOptions' => ['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'hover' => true, 'panel' => ['heading' => '<h3 class="panel-title">' . $this->title . '</h3>', 'after' => $this->blocks['add-button']]]]); ?> </div> </div>
public function up() { $this->createTable('{{%special_price_list%}}', ['id' => Schema::TYPE_PK, 'object_id' => Schema::TYPE_SMALLINT . ' NOT NULL', 'class' => Schema::TYPE_STRING . ' NOT NULL', 'active' => Schema::TYPE_BOOLEAN . ' NOT NULL DEFAULT 1', 'type' => "ENUM('core', 'discount', 'delivery', 'project') NOT NULL", 'sort_order' => Schema::TYPE_INTEGER . ' NOT NULL DEFAULT 0', 'params' => Schema::TYPE_TEXT]); $this->batchInsert('{{%special_price_list%}}', ['object_id', 'class', 'type', 'sort_order'], [[\app\models\Object::getForClass(\app\modules\shop\models\Product::className())->id, \app\modules\shop\models\Currency::className(), 'core', 5], [\app\models\Object::getForClass(\app\modules\shop\models\Product::className())->id, \app\modules\shop\models\Discount::className(), 'discount', 10]]); }