瀏覽代碼

Vente au kilo : ajout champs aux modèles Product et ProductOrder

refactoring
Guillaume Bourgeois 5 年之前
父節點
當前提交
dc49d2690b
共有 3 個檔案被更改,包括 43 行新增5 行删除
  1. +14
    -5
      common/models/Product.php
  2. +3
    -0
      common/models/ProductOrder.php
  3. +26
    -0
      console/migrations/m190508_155647_ajout_champs_vente_kilo.php

+ 14
- 5
common/models/Product.php 查看文件

@@ -52,14 +52,21 @@ use common\components\ActiveRecordCommon ;
* @property double $price
* @property double $pweight
* @property string $recipe
* @property string $unit
* @property double $step
*/
class Product extends ActiveRecordCommon
{
var $total = 0;
var $apply_distributions = false ;
const SALE_MODE_UNIT = 'unit' ;
const SALE_MODE_WEIGHT = 'weight' ;
public static $unitsArray = [
'piece' => ['unit' => 'pièce', 'coefficient' => 1],
'g' => ['unit' => 'g', 'coefficient' => 1000],
'kg' => ['unit' => 'kg', 'coefficient' => 1],
'mL' => ['unit' => 'mL', 'coefficient' => 1000],
'L' => ['unit' => 'L', 'coefficient' => 1],
];
/**
* @inheritdoc
@@ -78,9 +85,9 @@ class Product extends ActiveRecordCommon
[['name', 'id_producer'], 'required'],
[['active', 'order', 'quantity_max', 'id_producer'], 'integer'],
[['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday', 'unavailable','apply_distributions'], 'boolean'],
[['price', 'weight'], 'number'],
[['price', 'weight', 'step'], 'number'],
[[ 'photo'], 'file'],
[['name', 'description', 'photo'], 'string', 'max' => 255],
[['name', 'description', 'photo', 'unit'], 'string', 'max' => 255],
[['recipe'], 'string', 'max' => 1000],
];
}
@@ -109,7 +116,9 @@ class Product extends ActiveRecordCommon
'order' => 'Ordre',
'quantity_max' => 'Quantité max par défaut',
'unavailable' => 'Épuisé',
'apply_distributions' => 'Appliquer ces modifications dans les distributions futures'
'apply_distributions' => 'Appliquer ces modifications dans les distributions futures',
'unit' => 'Unité',
'step' => 'Pas'
];
}

+ 3
- 0
common/models/ProductOrder.php 查看文件

@@ -48,6 +48,7 @@ use common\components\ActiveRecordCommon ;
* @property integer $id_order
* @property integer $id_product
* @property double $quantity
* @property string $unit
*/
class ProductOrder extends ActiveRecordCommon
{
@@ -77,6 +78,7 @@ class ProductOrder extends ActiveRecordCommon
return [
[['id_order', 'id_product', 'quantity'], 'required'],
[['id_order', 'id_product'], 'integer'],
[['unit'], 'string', 'max' => 255],
[['quantity'], 'number', 'min' => 0]
];
}
@@ -91,6 +93,7 @@ class ProductOrder extends ActiveRecordCommon
'id_order' => 'Commande',
'id_product' => 'Product',
'quantity' => 'Quantité',
'unit' => 'Unité'
];
}

+ 26
- 0
console/migrations/m190508_155647_ajout_champs_vente_kilo.php 查看文件

@@ -0,0 +1,26 @@
<?php

use yii\db\Migration;
use yii\db\mysql\Schema;

class m190508_155647_ajout_champs_vente_kilo extends Migration {

public function up() {
$this->dropColumn('product', 'sale_mode') ;
$this->addColumn('product', 'unit', Schema::TYPE_STRING.' DEFAULT \'piece\'') ;
$this->addColumn('product', 'step', Schema::TYPE_FLOAT.' DEFAULT 1') ;
$this->dropColumn('product_order', 'sale_mode') ;
$this->addColumn('product_order', 'unit', Schema::TYPE_STRING.' DEFAULT \'piece\'') ;
}

public function down() {
$this->addColumn('product', 'sale_mode', Schema::TYPE_STRING.' DEFAULT \'unit\'') ;
$this->dropColumn('product', 'unit') ;
$this->dropColumn('product', 'step') ;
$this->addColumn('product_order', 'sale_mode', Schema::TYPE_STRING.' DEFAULT \'unit\'') ;
$this->dropColumn('product_order', 'unit') ;
}

}

Loading…
取消
儲存