api
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
namespace common\services;
|
||||
|
||||
use common\models\Company;
|
||||
use common\models\ProductCategory;
|
||||
use Yii;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
@ -61,4 +62,14 @@ class CompanyService
|
||||
return ArrayHelper::map($this->getAddressesByUser($id), 'id', 'address');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return array
|
||||
*/
|
||||
public function getCategoryByCompanyId(int $id): array
|
||||
{
|
||||
return ProductCategory::find()->where(['company_id' => $id])->all();
|
||||
}
|
||||
|
||||
|
||||
}
|
30
common/services/ProductService.php
Normal file
30
common/services/ProductService.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace common\services;
|
||||
|
||||
use common\models\Product;
|
||||
|
||||
class ProductService
|
||||
{
|
||||
|
||||
public Product $model;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new Product();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $company_id
|
||||
* @param int|null $category_id
|
||||
* @return array
|
||||
*/
|
||||
public function findBy(int $company_id, int $category_id = null): array
|
||||
{
|
||||
return $this->model->find()->where(['company_id' => $company_id])
|
||||
->andWhere(['status' => Product::STATUS_ACTIVE])
|
||||
->andFilterWhere(['product_category_id' => $category_id])
|
||||
->all();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user