public static function findOrCreateByValueAndManufacturer($value, $manufacturer_id) { if (!$value) { return null; } $model_number = static::findOne(['value' => $value, 'manufacturer_id' => $manufacturer_id]); if ($model_number) { return $model_number; } if ($manufacturer_id) { $manufacturer = Manufacturer::findOne(['id' => $manufacturer_id]); } $model_number = new static(); $model_number->value = $value; $model_number->manufacturer_id = $manufacturer ? $manufacturer->id : null; $model_number->save(); return $model_number; }
public function actionSave() { if (Yii::$app->user->can('updateResource')) { $post = Yii::$app->request->post('Manufacturer'); if ($post['id']) { $model = Manufacturer::findOne(['id' => $post['id']]); $model->attributes = $post; if ($model->validate()) { if ($model->update()) { Yii::$app->getSession()->setFlash('success', 'Manufacturer #' . $post['id'] . ' updated.'); } else { Yii::$app->getSession()->setFlash('error', 'Failed to update manufacturer #' . $post['id'] . '.'); } } } } else { Yii::$app->getSession()->setFlash('error', 'Not allowed.'); } return $this->redirect(['index']); }
public function actionManufacturer($id, $name = '') { $manufacturer = Manufacturer::findOne($id); $query = Product::find(); $query->joinWith(['productManufacturers']); $query->andWhere(['in', 'product_manufacturer.manufacturer_id', $id]); $query->andWhere('status = :s AND is_private = :p', [':s' => 1, ':p' => 0]); $query->orderBy('id DESC'); $pageTile = "Items Available in : {$manufacturer->name}"; $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 12]]); return $this->render('category', ['dataProvider' => $dataProvider, 'pageTile' => $pageTile]); }
/** * @return \yii\db\ActiveQuery */ public function getManufacturer() { return $this->hasOne(Manufacturer::className(), ['id' => 'manufacturer_id']); }
<?php use yii\grid\GridView; use yii\data\ActiveDataProvider; use common\models\Manufacturer; /* @var $this yii\web\View */ $this->title = 'Manufacturers'; $this->params['breadcrumbs'][] = $this->title; $dataProvider = new ActiveDataProvider(['query' => Manufacturer::find(), 'pagination' => ['pageSize' => 20]]); ?> <div class="box"> <div class="box-body"> <?php if (Yii::$app->user->can('listResources')) { echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'name', ['attribute' => 'created_at', 'format' => ['datetime', 'php:Y-m-d H:i:s']], ['attribute' => 'updated_at', 'format' => ['datetime', 'php:Y-m-d H:i:s']], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update}']]]); } ?> </div> </div>
/** * Finds the Manufacturer model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Manufacturer the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Manufacturer::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getOdm() { return $this->hasOne(Manufacturer::className(), ['id' => 'odm_id']); }
<div class="info-wrapper"> <?php $productCategories = $model->productCategories; $cat_str = ""; foreach ($productCategories as $pc) { $cat_str .= "{$pc->category->display_name}, "; } echo rtrim($cat_str, ', '); ?> </div> </li> <li class="list-group-item clearfix"> <div class="label-wrapper border-right"> <label><?php echo \common\models\Manufacturer::attributeLabels()['name']; ?> </label> </div> <div class="info-wrapper"> <?php if (!empty($model->productManufacturers)) { $productManufacturers = $model->productManufacturers; $man_str = ""; foreach ($productManufacturers as $pm) { $man_str .= "{$pm->manufacturer->name}, "; } echo rtrim($man_str, ', '); } else { echo '<span class="not-set">(not set)</span>'; }
<?php echo Html::a($category->display_name, Url::to(['/category', 'id' => $category->id, 'name' => Html::encode($category->name)])); ?> </li> <?php } ?> </ul> </li> <li class="dropdown parent-menu"> <?php echo Html::a('Manufacturer', Url::to(['/manufacturer']), ['data-toggle' => 'dropdown', 'data-hover' => 'dropdown', 'class' => 'dropdown-toggle']); ?> <ul class="dropdown-menu list-group"> <?php $manufacturers = Manufacturer::find()->where('status = :s', [':s' => 1])->all(); foreach ($manufacturers as $manufacturer) { ?> <li class="list-group-item"> <?php echo Html::a($manufacturer->name, Url::to(['/manufacturer', 'id' => $manufacturer->id, 'name' => Html::encode($manufacturer->name)])); ?> </li> <?php } ?> </ul> </li> <li class="parent-menu"><?php echo Html::a('Shop', Url::to(['/shop'])); ?>
$this->params['breadcrumbs'][] = 'Edit'; ?> <div class="box"> <?php $form = ActiveForm::begin(['id' => 'edit-model-number-form', 'action' => 'save']); ?> <?php echo Html::activeHiddenInput($model, 'id'); ?> <div class="box-body"> <div class="form-group"> <?php echo $form->field($model, 'value'); ?> <?php echo $form->field($model, 'manufacturer_id')->dropDownList(ArrayHelper::map(Manufacturer::find()->orderBy('name')->all(), 'id', 'name'), ['disabled' => true]); ?> </div> <div class="box-footer"> <?php echo Button::widget(['label' => 'Save', 'options' => ['class' => 'btn btn-primary']]); ?> <?php echo Html::a('Cancel', Yii::$app->request->referrer, ['class' => 'btn btn-default']); ?> </div> </div> <?php ActiveForm::end(); ?> </div>