getProductManager();
$this->setTitle('Produits');
$this->addBreadcrumb($this->getTitle());
$this->addButton(['label' => 'Nouveau produit ', 'url' => 'product/create', 'class' => 'btn btn-primary']);
?>
= $dataProvider->pagination->pageSize; ?>
= GridView::widget([
'filterModel' => $searchModel,
'dataProvider' => $dataProvider,
'columns' => [
[
'attribute' => 'order',
'headerOptions' => ['class' => 'order column-hide-on-mobile'],
'filterOptions' => ['class' => 'column-hide-on-mobile'],
'contentOptions' => ['class' => 'column-hide-on-mobile'],
'format' => 'raw',
'filter' => '',
'value' => function ($model) {
return '
';
}
],
[
'attribute' => 'photo',
'format' => 'raw',
'headerOptions' => ['class' => 'td-photo column-hide-on-mobile'],
'filterOptions' => ['class' => 'column-hide-on-mobile'],
'contentOptions' => ['class' => 'column-hide-on-mobile'],
'filter' => '',
'value' => function ($model) {
if (strlen($model->photo)) {
$url = Yii::$app->urlManagerProducer->getHostInfo() . '/' . Yii::$app->urlManagerProducer->baseUrl . '/uploads/' . $model->photo;
$url = str_replace('//uploads', '/uploads', $url);
return '
';
}
return '';
}
],
'name',
[
'attribute' => 'description',
'headerOptions' => ['class' => 'column-hide-on-mobile'],
'filterOptions' => ['class' => 'column-hide-on-mobile'],
'contentOptions' => ['class' => 'column-hide-on-mobile'],
],
[
'attribute' => 'id_product_category',
'format' => 'raw',
'headerOptions' => ['class' => 'td-product-category column-hide-on-mobile'],
'filterOptions' => ['class' => 'column-hide-on-mobile'],
'contentOptions' => ['class' => 'column-hide-on-mobile'],
'filter' => '',
'value' => function ($model) {
if ($model->productCategory) {
return $model->productCategory->name;
}
return '';
}
],
[
'attribute' => 'id_tax_rate',
'headerOptions' => ['class' => 'column-hide-on-mobile'],
'filterOptions' => ['class' => 'column-hide-on-mobile'],
'contentOptions' => ['class' => 'column-hide-on-mobile'],
'value' => function ($model) {
if ($model->id_tax_rate == 0 || $model->id_tax_rate == null) {
//Récupère la tva par défaut du producteur courant
$taxRateDefault = GlobalParam::getCurrentProducer()->taxRate;
$return = $taxRateDefault->name;
} else {
$return = $model->taxRate->name;
}
return $return;
}
],
[
'attribute' => 'price',
'value' => function ($model) use ($productManager) {
$return = '';
if ($model->price) {
$return = Price::format($productManager->getPriceWithTax($model)) . ' (' . $productManager->strUnit($model->unit, 'wording_unit', true) . ')';
}
return $return;
}
],
[
'attribute' => 'active',
'headerOptions' => ['class' => 'active column-hide-on-mobile'],
'filterOptions' => ['class' => 'column-hide-on-mobile'],
'contentOptions' => ['class' => 'center column-hide-on-mobile'],
'format' => 'raw',
'filter' => [0 => 'Non', 1 => 'Oui'],
'value' => function ($model) {
return Toggle::widget(
[
'name' => 'active',
'checked' => $model->active,
'options' => [
'data-id' => $model->id,
'data-on' => 'Oui',
'data-off' => 'Non',
],
]
);
}
],
[
'class' => 'yii\grid\ActionColumn',
'template' => '{update} {delete}',
'headerOptions' => ['class' => 'column-actions'],
'contentOptions' => ['class' => 'column-actions'],
'buttons' => [
'update' => function ($url, $model) {
return Html::a('
', $url, [
'title' => 'Modifier', 'class' => 'btn btn-default'
]);
},
'delete' => function ($url, $model) {
return Html::a('
', $url, [
'title' => 'Supprimer', 'class' => 'btn btn-default'
]);
}
],
],
],
]); ?>