add changes sell product

This commit is contained in:
2015-10-01 17:31:48 +02:00
parent e3d6c0b902
commit e9f9567618
7 changed files with 323 additions and 144 deletions

View File

@@ -3,6 +3,7 @@
namespace common\models;
use Yii;
use yii\helpers\ArrayHelper;
/**
* This is the model class for table "product".
@@ -125,4 +126,44 @@ class Product extends \common\models\BaseFitnessActiveRecord {
return $warehouses;
}
public static function findProduct($query){
$result = [];
$product = null;
$products = Product::find()
->andWhere(
['or',
['product_number' => $query ],
['barcode' => $query ],
]
)->andWhere(['status' =>Product::STATUS_ACTIVE])
->all();
if ( count($products) == 1 ){
$product = $products[0];
}
return $product;
}
public static function modelToArray($product,$default = null){
if ( $product == null ){
return $default;
}
return ArrayHelper::toArray($product, [
'common\models\Product' => [
'name',
'product_number',
'barcode',
'sale_price',
'stock',
'category' => function ($product) {
return $product->productCategoryName;
},
],
]);
}
}