本文整理汇总了PHP中Products::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Products::model方法的具体用法?PHP Products::model怎么用?PHP Products::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Products
的用法示例。
在下文中一共展示了Products::model方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testTitle
public function testTitle()
{
Yii::app()->settings->set('core', array('siteName' => microtime()));
$this->open('/');
$this->assertEquals(Yii::app()->settings->get('core', 'siteName'), $this->getTitle());
// Find any active product
$product = Products::model()->active()->find();
$this->assertTrue($product instanceof Products);
// Open product page
$this->open(Yii::app()->createUrl('/store/frontProduct/view', array('url' => $product->url)));
$this->assertEquals($product->name . ' / ' . Yii::app()->settings->get('core', 'siteName'), $this->getTitle());
}
示例2: getPriceTotal
public static function getPriceTotal()
{
$price_total = 0;
$tax_total = 0;
foreach (Shop::getCartContent() as $product) {
$model = Products::model()->findByPk($product['product_id']);
$price_total += $model->getPrice(@$product['Variations'], @$product['amount']);
$tax_total += $model->getTaxRate(@$product['Variations'], @$product['amount']);
}
if ($shipping_method = Shop::getShippingMethod()) {
$price_total += $shipping_method->price;
}
$price_total = Shop::t('Price total: {total}', array('{total}' => Shop::priceFormat($price_total)));
$price_total .= '<br />';
$price_total .= Shop::t('All prices are including VAT: {vat}', array('{vat}' => Shop::priceFormat($tax_total))) . '<br />';
$price_total .= Shop::t('All prices excluding shipping costs') . '<br />';
return $price_total;
}
示例3: actionRefresh
public function actionRefresh()
{
$department = Department::model()->findAll();
foreach ($department as $val) {
$dish = Dishes::model()->findAll('t.department_id = :depId', array(':depId' => $val->department_id));
foreach ($dish as $value) {
$this->addDish($value->dish_id, $val->department_id);
}
$stuff = Halfstaff::model()->findAll('t.department_id = :depId', array(':depId' => $val->department_id));
foreach ($stuff as $value) {
$this->addStuff($value->halfstuff_id, $val->department_id);
}
$prod = Products::model()->findAll('t.department_id = :depId', array(':depId' => $val->department_id));
foreach ($prod as $value) {
$this->addProd($value->product_id, $val->department_id);
}
}
$this->redirect(array('site/index'));
}
示例4: run
public function run()
{
if ($this->products === true) {
$this->products = Products::model()->findAll('status = 1');
}
if (!is_array($this->products)) {
$this->products = array($products);
}
if (!$this->selected) {
$this->selected = $this->products[0]->product_id;
}
$products = array();
foreach ($this->products as $product) {
if (is_numeric($product)) {
$products[$product] = Products::model()->findByPk($product);
} else {
$products[$product->product_id] = $product;
}
}
$this->render($this->view, array('selected' => $this->selected, 'ask_for_amount' => $this->ask_for_amount, 'products' => $products));
return parent::run();
}
示例5: actionUpdateAmount
public function actionUpdateAmount()
{
$cart = Shop::getCartContent();
foreach ($_GET as $key => $value) {
if (substr($key, 0, 7) == 'amount_') {
if ($value == '') {
return true;
}
if (!is_numeric($value) || $value <= 0) {
throw new CException('Wrong amount');
}
$position = explode('_', $key);
$position = $position[1];
if (isset($cart[$position]['amount'])) {
$cart[$position]['amount'] = $value;
}
$product = Products::model()->findByPk($cart[$position]['product_id']);
echo Shop::priceFormat(@$product->getPrice($cart[$position]['Variations'], $value));
return Shop::setCartContent($cart);
}
}
}
示例6: actionIndex
public function actionIndex()
{
if (isset($_POST['ajax'])) {
$slideShows = Slideshow::model()->findAll();
$images = array();
if ($slideShows) {
foreach ($slideShows as $slideShow) {
$images[] = $slideShow->imageLink;
}
echo json_encode($images);
}
} else {
$newProducts = NewProducts::model()->findAll();
$hotProducts = HotProducts::model()->findAll(array("limit" => 17));
$amthucs = Amthuc::model()->findAll(array("order" => 'id DESC', "limit" => 4));
if ($newProducts || $hotProducts) {
$newProduct = array();
foreach ($newProducts as $newProduct1) {
$product = Products::model()->findByPk($newProduct1->product_id);
if ($product) {
$newProduct[$newProduct1->id] = $product;
}
}
foreach ($hotProducts as $key => $value) {
$product = Products::model()->find('id=:product_id', array(':product_id' => $value->product_id));
if ($product) {
$products[] = $product;
}
}
if ($newProduct && $products || $amthucs) {
$this->render('index', array('newProduct' => $newProduct, 'products' => $products, 'amthucs' => $amthucs));
} else {
$this->render('index');
}
}
}
}
示例7: actionAdmin
public function actionAdmin()
{
$product = Products::model()->findByPk($_GET['product_id']);
$images = $product->images;
$this->render('admin', array('images' => $images, 'product' => $product));
}
示例8: loadModel
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
*/
public function loadModel()
{
if ($this->_model === null) {
if (isset($_GET['id'])) {
$this->_model = Products::model()->findbyPk($_GET['id']);
}
if (isset($_GET['title'])) {
$this->_model = Products::model()->find('title = :title', array(':title' => $_GET['title']));
}
if ($this->_model === null) {
throw new CHttpException(404, 'The requested page does not exist.');
}
}
return $this->_model;
}
示例9: getCategoryShops
public function getCategoryShops()
{
if(!empty($this->allmodel)){
foreach($this->allmodel as $c){
$cat[] = $c->id;
}
$categories = $cat;
} else {
$categories = $this->model;
}
$shops = null;
if(!Yii::app()->request->getParam('account')) {
$cr = new CDbCriteria;
$cr->select = 't.user_id, t.name';
$cr->group = 't.user_id';
// $cr->distinct = true;
$cr->addCondition('t.user_id IS NOT NULL and t.shop=1');
if(Yii::app()->request->getParam('brand'))
{
$shops = Products::model()
->active()
->withcity()
// ->applyCategories($categories, null)
->applyCategoriesWithSub($categories, null)
->with(array(
'shopmag'=>array(
'with'=>array(
'productsCount'=>array(
'scopes'=>array(
'active',
'withcity',
// 'applyCategories'=>array($categories, null),
// 'applyCategoriesWithSub'=>array($categories, null),
'applyManufacturers'=>array(Yii::app()->request->getParam('brand')),
'applyAttributes'=>array($this->getOwner()->activeAttributes),
'applyMinPrice'=>array($this->convertCurrency(Yii::app()->request->getQuery('min_price'))),
'applyMaxPrice'=>array($this->convertCurrency(Yii::app()->request->getQuery('max_price'))),
),
)
),
)))
->findAll($cr);
} else {
$shops = Products::model()
->active()
->withcity()
// ->applyCategories($categories, null)
->applyCategoriesWithSub($categories, null)
->with(array(
'shopmag'=>array(
'with'=>array(
'productsCount'=>array(
'scopes'=>array(
'active',
'withcity',
// 'applyCategories'=>array($categories, null),
// 'applyCategoriesWithSub'=>array($categories, null),
// 'applyManufacturers'=>array($this->manufacturers),
'applyAttributes'=>array($this->getOwner()->activeAttributes),
'applyMinPrice'=>array($this->convertCurrency(Yii::app()->request->getQuery('min_price'))),
'applyMaxPrice'=>array($this->convertCurrency(Yii::app()->request->getQuery('max_price'))),
))
),
)))
->findAll($cr);
}
}
$data = array(
'title'=>'Магазин',
'selectMany'=>true,
'filters'=>array()
);
if($shops)
{
foreach($shops as $m)
{
//.........这里部分代码省略.........
示例10: loadModel
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param integer the ID of the model to be loaded
*/
public function loadModel($id)
{
$model = Products::model()->findByPk((int) $id);
if ($model === null) {
throw new CHttpException(404, 'The requested page does not exist.');
}
return $model;
}
示例11: refreshBalance
public function refreshBalance($depId)
{
$dish = Dishes::model()->findAll('t.department_id = :depId', array(':depId' => $depId));
foreach ($dish as $value) {
$this->addDish($value->dish_id, $depId);
}
$stuff = Halfstaff::model()->findAll('t.department_id = :depId', array(':depId' => $depId));
foreach ($stuff as $value) {
$this->addStuff($value->halfstuff_id, $depId);
}
$prod = Products::model()->findAll('t.department_id = :depId', array(':depId' => $depId));
foreach ($prod as $value) {
$this->addProd($value->product_id, $depId);
}
}
示例12: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$products = Products::model()->with('measure')->findAll(array('order' => 't.name'));
$curModel = Storage::model()->with('product.measure')->findAll(array('order' => 'product.name'));
//if(empty($curModel)){
$model = new Storage();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Storage'])) {
if (!empty($curModel)) {
$model->deleteAll();
}
if ($_POST['Storage']['curDate'] == '') {
$_POST['Storage']['curDate'] = date('Y-m-d');
}
$transaction = Yii::app()->db->beginTransaction();
try {
$messageType = 'warning';
$message = "There are some errors ";
foreach ($_POST['product_id'] as $key => $value) {
$tempModel = new Storage();
$tempModel->curDate = $_POST['Storage']['curDate'];
$tempModel->prod_id = $value;
$tempModel->curCount = $this->changeToFloat($_POST['count'][$key]);
$tempModel->price = $_POST['price'][$key];
if ($tempModel->save()) {
$messageType = 'success';
$message = "<strong>Well done!</strong> You successfully create data ";
}
}
$transaction->commit();
Yii::app()->user->setFlash($messageType, $message);
$this->redirect(array('index'));
//$model->attributes=$_POST['Storage'];
//$uploadFile=CUploadedFile::getInstance($model,'filename');
/*if($model->save()){
$messageType = 'success';
$message = "<strong>Well done!</strong> You successfully create data ";
/*
$model2 = Storage::model()->findByPk($model->storage_id);
if(!empty($uploadFile)) {
$extUploadFile = substr($uploadFile, strrpos($uploadFile, '.')+1);
if(!empty($uploadFile)) {
if($uploadFile->saveAs(Yii::app()->basePath.DIRECTORY_SEPARATOR.'files'.DIRECTORY_SEPARATOR.'storage'.DIRECTORY_SEPARATOR.$model2->storage_id.DIRECTORY_SEPARATOR.$model2->storage_id.'.'.$extUploadFile)){
$model2->filename=$model2->storage_id.'.'.$extUploadFile;
$model2->save();
$message .= 'and file uploded';
}
else{
$messageType = 'warning';
$message .= 'but file not uploded';
}
}
}
$transaction->commit();
Yii::app()->user->setFlash($messageType, $message);
$this->redirect(array('view','id'=>$model->storage_id));
} */
} catch (Exception $e) {
$transaction->rollBack();
Yii::app()->user->setFlash('error', "{$e->getMessage()}");
//$this->refresh();
}
}
$this->render('create', array('model' => $model, 'curModel' => $curModel, 'products' => $products));
//} else{
// $this->redirect(array('index'));
//}
}
示例13: deleteProduct
/**
* This is method for delete Product from list
* @param string $id
* @return array[] {
* 'code':200,
* 'message':'SUCCESS'
* }
*/
public function deleteProduct($id)
{
$result = Products::model()->findByAttributes(array('id' => $id));
$result->status = '0';
if ($result->save()) {
$data = array('code' => 200, 'message' => 'SUCCESS');
}
return $data;
}
示例14: getAllComments
public static function getAllComments(CActiveRecord $model)
{
$users_adv = Products::model()
->active()
->findAllByAttributes(array(
'user_id'=>$model->id
));
$ids=array();
foreach($users_adv as $adv):
$ids[]=$adv->id;
endforeach;
// $criteria = new CDbCriteria();
// $criteria->addInCondition("object_pk", $ids);
return Comment::model()
->approved()
->orderByCreatedDesc()
->findAllByAttributes(array('object_pk'=>$ids));
}
示例15: actionCreate
public function actionCreate()
{
$products = Products::model()->with('measure')->findAll();
$curModel = DepStorage::model()->with('product.measure')->findAll('t.type = :type', array(':type' => 1));
$model = new DepStorage();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['DepStorage'])) {
if (!empty($curModel) && $curModel->department_id == $_POST['DepStorage']['department_id']) {
$model->deleteAll();
}
if ($_POST['DepStorage']['curDate'] == '') {
$_POST['DepStorage']['curDate'] = date('Y-m-d');
}
$transaction = Yii::app()->db->beginTransaction();
try {
$messageType = 'warning';
$message = "There are some errors";
if (isset($_POST['prod'])) {
foreach ($_POST['prod']['product_id'] as $key => $value) {
$tempModel = new DepStorage();
$tempModel->curDate = $_POST['DepStorage']['curDate'];
$tempModel->prod_id = $value;
$tempModel->curCount = $this->changeToFloat($_POST['prod']['count'][$key]);
//$tempModel->price = $_POST['price'][$key];
$tempModel->department_id = $_POST['DepStorage']['department_id'];
$tempModel->type = 1;
if ($tempModel->save()) {
$messageType = 'success';
$message = "<strong>Well done!</strong> You successfully create data ";
}
}
}
if (isset($_POST['stuff'])) {
foreach ($_POST['stuff']['stuff_id'] as $key => $value) {
$tempModel = new DepStorage();
$tempModel->curDate = $_POST['DepStorage']['curDate'];
$tempModel->prod_id = $value;
$tempModel->curCount = $this->changeToFloat($_POST['stuff']['count'][$key]);
//$tempModel->price = $_POST['price'][$key];
$tempModel->department_id = $_POST['DepStorage']['department_id'];
$tempModel->type = 2;
if ($tempModel->save()) {
$messageType = 'success';
$message = "<strong>Well done!</strong> You successfully create data ";
}
}
}
if (isset($_POST['dish'])) {
foreach ($_POST['dish']['dish_id'] as $key => $value) {
$tempModel = new DepStorage();
$tempModel->curDate = $_POST['DepStorage']['curDate'];
$tempModel->prod_id = $value;
$tempModel->curCount = $this->changeToFloat($_POST['dish']['count'][$key]);
//$tempModel->price = $_POST['price'][$key];
$tempModel->department_id = $_POST['DepStorage']['department_id'];
$tempModel->type = 3;
if ($tempModel->save()) {
$messageType = 'success';
$message = "<strong>Well done!</strong> You successfully create data ";
}
}
}
//$uploadFile=CUploadedFile::getInstance($model,'filename');
$transaction->commit();
Yii::app()->user->setFlash($messageType, $message);
//$this->redirect(array('view','id'=>$model->dep_storage_id));
} catch (Exception $e) {
$transaction->rollBack();
Yii::app()->user->setFlash('error', "{$e->getMessage()}");
//$this->refresh();
}
}
$this->render('create', array('model' => $model, 'curModel' => $curModel, 'products' => $products));
}