/** * Displays a particular model. * @param integer $id the ID of the model to be displayed */ public function actionAdditem($item_id) { $user_id = Yii::app()->user->id; // find the users cart $user = User::model()->find(array('condition' => 'id=:user_id', 'params' => array(':user_id' => $user_id))); // find the users cart $cart = Cart::model()->find(array('condition' => 'cart_owner=:cart_owner', 'params' => array(':cart_owner' => $user_id))); // find the item being reffered to by item_id $item = Item::model()->find(array('condition' => 'id=:item_id', 'params' => array(':item_id' => $item_id))); if (is_null($cart)) { // if the cart is not found. create a cart for the user. $cart = new Cart(); $cart->cart_owner = $user->id; $cart->save(); } // check if the same order was already made & increment else, create new $order = Order::model()->find(array('condition' => 'item_id=:item_id AND cart_id=:cart_id AND order_by=:order_by', 'params' => array(':item_id' => $item_id, ':cart_id' => $cart->id, ':order_by' => $user->id))); if (is_null($order)) { $order = new Order(); $order->create_time = time(); $order->quantity = 1; $order->item_id = $item->id; $order->cart_id = $cart->id; $order->order_by = $user->id; } else { $order->quantity = 1 + $order->quantity; $order->update_time = time(); } $order->save(); // find all orders by this user. $orders = Order::model()->findAll('cart_id=:cart_id AND order_by=:order_by', array(':cart_id' => $cart->id, ':order_by' => $user->id)); $return = array('success' => true, 'data' => $orders); echo CJavaScript::jsonEncode($return); Yii::app()->end(); }
public function run($id) { $item_info = Item::model()->findByPk($id); if ($item_info->delete()) { $this->controller->success(''); } }
public function actionIndex($key) { $category = Category::model()->findByPk(3); $model = $category->findByAttributes(array('url' => $key)); if ($model) { $childs = $model->descendants()->findAll(); $ids = array($model->id); foreach ($childs as $child) { $ids[] = $child->id; } $cid = implode(',', $ids); $criteria = new CDbCriteria(array('condition' => 'category_id in ( ' . $cid . ')', 'order' => 'item_id desc, sort_order desc')); $count = Item::model()->count($criteria); $pages = new CPagination($count); // results per page $pages->pageSize = 20; $pages->applyLimit($criteria); $items = Item::model()->findAll($criteria); // $items = new CActiveDataProvider('Item', array( // 'criteria' => $criteria // )); $criteria = new CDbCriteria(array('condition' => 'is_hot = 1 and category_id in ( ' . $cid . ')', 'limit' => '4', 'order' => 'item_id desc, sort_order desc')); $hotItems = Item::model()->findAll($criteria); $this->render('index', array('model' => $model, 'items' => $items, 'pages' => $pages, 'hotItems' => $hotItems, 'key' => $key)); } else { $this->render('index'); } }
public function actionIndex() { // renders the view file 'protected/views/site/index.php' // using the default layout 'protected/views/layouts/main.php' $cri = new CDbCriteria(array('condition' => 'is_show = 1 and is_best = 1')); $best_items = Item::model()->findAll($cri); $this->render('index', array('best_items' => $best_items)); }
/** * 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 loadItemsModel($criteria) { $items = Item::model()->findAll($criteria); if ($items === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $items; }
{ unset(Yii::app()->request->cookies['history']); } /** * 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)
{ parent::init(); } public function getItems() { if (isset(Yii::app()->request->cookies['history'])) { $ids = Yii::app()->request->cookies['history']->value; $item_ids = explode(',', $ids); foreach ($item_ids as $item_id) { $items[] = Item::model()->findByPk($item_id); }
public function run() { $id = Yii::app()->request->getParam('id', 0); $item_model = Item::model()->findByPk($id); if (isset($_POST['Item'])) { $item_model->attributes = $_POST['Item']; if ($item_model->save()) { $this->controller->redirect("/mama/item/index/"); } } $this->controller->render('update', array('item_model' => $item_model)); }
public static function getCategory($category) { $criteria = new CDbCriteria(); $criteria->select = $category; // only select the 'title' column $criteria->distinct = true; $rs = Item::model()->findAll($criteria); // $params is not needed foreach ($rs as $row) { $retVal[]["value"] = $row[$category]; } return $retVal; }
private function ini() { if (!$this->ini) { $this->_precision = Yii::app()->user->getSetting('company.precision'); $this->iVatRate = Item::model()->findByPK($this->item_id)->vat; $this->rate = Currates::model()->GetRate($this->currency_id); if ($this->doc_rate == 0) { $doc = Docs::model()->findByPk($this->doc_id); $this->doc_rate = Currates::model()->GetRate($doc->currency_id); } $this->ini != $this->ini; } }
public function actionShow($id) { $model = Item::model()->published()->with(array('producer', 'categories' => array('scopes' => 'published', 'order' => 'categories.sort ASC'), 'reasons' => array('scopes' => 'active', 'order' => 'reasons.sort ASC'), 'products' => array('scopes' => 'active', 'order' => 'products.sort ASC'), 'images' => array('scopes' => 'published', 'order' => 'images.sort ASC')))->findByPk($id); if (!$model) { throw new CHttpException(404); } // Учитываем фильтр в каталоге $filter = Yii::app()->user->getState('chemicalCatalogFilter'); // Определяем следующий товар $nextProduct = $model->getNextProduct($filter); // Определяем предыдущий товар $prevProduct = $model->getPrevProduct($filter); $this->render('item', array('model' => $model, 'nextProduct' => $nextProduct, 'prevProduct' => $prevProduct, 'returnUrl' => Yii::app()->user->getState('stoneCatalogReturnUrl'))); }
public function actionIndex($key) { $model = Category::model()->findByAttributes(array('url' => $key)); $ids = $model->getMeChildsId($model->category_id); $cid = implode(',', $ids); $criteria = new CDbCriteria(array('condition' => 'category_id in ( ' . $cid . ')')); $count = Item::model()->count($criteria); $pages = new CPagination($count); // results per page $pages->pageSize = 20; $pages->applyLimit($criteria); $items = Item::model()->findAll($criteria); $criteria = new CDbCriteria(array('condition' => 'is_hot = 1 and category_id in ( ' . $cid . ')', 'limit' => '4')); $hotItems = Item::model()->findAll($criteria); $this->render('index', array('model' => $model, 'items' => $items, 'pages' => $pages, 'hotItems' => $hotItems)); }
function checkoutAction($params) { if ($this->isGuest()) { $this->redirect("Site", "login"); } $userId = $this->signedInUser()->id; $itemId = $params["itemId"]; $item = Item::model()->find($itemId); $item->quantity--; $transaction = new Transaction(); $transaction->userId = $userId; $transaction->itemId = $item->id; $transaction->date = date("Y-m-d H:i:s"); $item->save(); $transaction->save(); $this->addFlash("Item bought successfully!"); return $this->redirect("Site", "index"); }
public function actionTestManyToMany() { $items = Item::model()->findAll(); $ingredients = Ingredient::model()->findAll(); foreach ($items as $item) { echo $item->name . " has " . count($item->ingredients) . " ingredients. They are:<br />"; foreach ($item->ingredients as $ingredient) { echo $ingredient->name . "<br />"; } echo "<br />"; } echo "<hr />"; foreach ($ingredients as $ingredient) { echo $ingredient->name . " is associated with " . count($ingredient->items) . " items. They are:<br />"; foreach ($ingredient->items as $item) { echo $item->name . "<br />"; } echo "<br />"; } }
public static function addCart($items, $item_id, $quantity, $discount, $price_tier, $price, $cost_price, $unit_price, $description, $expire_date) { $models = Item::model()->getItemPriceTierWS($item_id, $price_tier); if (empty($models)) { $models = Item::model()->getItemPriceTierItemNumWS($item_id, $price_tier); foreach ($models as $model) { $item_id = $model["id"]; } } if (!$models) { return false; } foreach ($models as $model) { $item_data = array((int) $item_id => array('item_id' => $model["id"], 'currency_code' => $model["currency_code"], 'currency_id' => $model["currency_id"], 'currency_symbol' => $model["currency_symbol"], 'name' => $model["name"], 'item_number' => $model["item_number"], 'quantity' => $quantity, 'cost_price' => $cost_price != null ? round($cost_price, Common::getDecimalPlace()) : round($model->cost_price, Common::getDecimalPlace()), 'unit_price' => $unit_price != null ? round($unit_price, Common::getDecimalPlace()) : round($model->unit_price, Common::getDecimalPlace()), 'price' => $price != null ? round($price, Common::getDecimalPlace()) : round($model["price"], Common::getDecimalPlace()), 'to_val' => 1, 'discount' => $discount, 'expire_date' => $expire_date, 'description' => $description != null ? $description : $model["description"])); } if (isset($items[$item_id])) { $items[$item_id]['quantity'] += $quantity; } else { $items += $item_data; } return $items; }
public function actionAddCart() { $qty = $_POST['qty']; $id = $_POST['item_id']; $cart = Yii::app()->cart; $mycart = $cart->contents(); $model = Item::model()->findByPk($id); $insert_data = array('id' => $id, 'pic_url' => $model->getSmallThumb(), 'sn' => $model->sn, 'title' => $model->title, 'name' => $id, 'price' => $model->shop_price, 'qty' => $qty); if (empty($mycart)) { $data = $insert_data; } else { //当购物车里存在此商品,则数量相加 foreach ($mycart as $key => $value) { if ($id === $value['id']) { $mycart[$key]['qty'] = $qty + $value['qty']; } if (!$mycart[$key][$id]) { $cart->insert($insert_data); } } $data = $mycart; } $cart->insert($data); }
public function actionView() { // Check if id was submitted via GET if (!isset($_GET['id'])) { $this->_sendResponse(500, 'Error: Parameter <b>id</b> is missing'); } switch ($_GET['model']) { // Find respective model case 'category': $model = Category::model()->findByPk($_GET['id']); break; case 'item': if (!isset($_GET['category'])) { $model = Item::model()->findByPk($_GET['id']); } else { switch ($_GET['category']) { case 'category': $model = Item::model()->findAll('cat_id=:cat_id', array(':cat_id' => $_GET['id'])); break; default: $this->_sendResponse(501, sprintf('Mode <b>view</b> is not implemented for model <b>%s</b>', $_GET['model'])); exit; } } break; default: $this->_sendResponse(501, sprintf('Mode <b>view</b> is not implemented for model <b>%s</b>', $_GET['model'])); exit; } // Did we find the requested model? If not, raise an error if (is_null($model)) { $this->_sendResponse(404, 'No Item found with id ' . $_GET['id']); } else { $this->_sendResponse(200, CJSON::encode($model)); } }
public function addItemToCart($id) { $session = Yii::app()->session; $arr_session = array(); $model = Item::model()->findbyPk($id); $my_product = $model->attributes; if (isset($session['cart'])) { $arr_session = $session['cart']; if (array_key_exists($id, $session['cart'])) { $arr_session = $session['cart']; $arr_session[$id]['quantity']++; $session['cart'] = $arr_session; } else { $arr_session = $session['cart']; $arr_session[$id] = $my_product; $arr_session[$id]['quantity'] = 1; $arr_session[$id]['discount'] = 0; //$arr_session['0']['payment_amount']=0; $session['cart'] = $arr_session; } } else { $session['cart'] = array($id => $my_product); $arr_session = $session['cart']; $arr_session[$id]['quantity'] = 1; $arr_session[$id]['discount'] = 0; //$arr_session['0']['payment_amount']=0; $session['cart'] = $arr_session; } }
</th> <th><?php echo Yii::t('app', 'Total'); ?> </th> <th></th> </tr> </thead> <tbody id="cart_contents"> <?php foreach (array_reverse($items, true) as $id => $item) { ?> <?php $total_item = Common::calTotalAfterDiscount($item['discount'], $item['cost_price'], $item['quantity']); $item_id = $item['item_id']; $cur_item_info = Item::model()->findbyPk($item_id); $qty_in_stock = $cur_item_info->quantity; ?> <tr> <td> <?php echo $item['name']; ?> <br/> <span class="text-info"><?php echo $qty_in_stock . ' ' . Yii::t('app', 'in stock'); ?> </span> </td> <td>
public function afterSave() { $num = OrderItem::model()->count(array('condition' => 'item_id=:item_id ', 'params' => array(':item_id' => $this->item_id))); $model = Item::model()->findByPk($this->item_id); $model->deal_count = $num; $model->save(); return parent::afterSave(); }
<div class="form"> <?php $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array('id' => 'item-form', 'enableAjaxValidation' => true)); ?> <?php $temp = CHtml::listData(Item::model()->findAll(), 'id', 'name'); $temp[0] = Yii::t('app', 'None'); ?> <div class="row"> <?php echo $form->errorSummary($model); ?> </div> <div class="row"> <div class="col-md-4 col-sm-6"> <?php $this->beginWidget('TbPanel', array('header' => Yii::t('app', "Item General Details"))); ?> <?php echo $form->textFieldRow($model, 'name', array('maxlength' => 100)); ?> <?php echo $form->textFieldRow($model, 'sku', array('maxlength' => 255)); ?> <?php echo $form->dropDownListRow($model, 'category_id', $cat); ?> <?php echo $form->textAreaRow($model, 'description');
public function outofStock($item_id) { if (!is_numeric($item_id)) { $item_id = 'NULL'; } $item = Item::model()->findbyPk($item_id); if (!$item) { return false; } $quanity_added = $this->getQuantityAdded($item_id); if ($item->quantity - $quanity_added < 0) { return true; } return false; }
public function testLazyRelation() { // test belongsTo $post = Post::model()->findByPk(2); $this->assertTrue($post->author instanceof User); $this->assertEquals(array('id' => 2, 'username' => 'user2', 'password' => 'pass2', 'email' => 'email2'), $post->author->attributes); // test hasOne $post = Post::model()->findByPk(2); $this->assertTrue($post->firstComment instanceof Comment); $this->assertEquals(array('id' => 4, 'content' => 'comment 4', 'post_id' => 2, 'author_id' => 2), $post->firstComment->attributes); $post = Post::model()->findByPk(4); $this->assertNull($post->firstComment); // test hasMany $post = Post::model()->findByPk(2); $this->assertEquals(2, count($post->comments)); $this->assertEquals(array('id' => 5, 'content' => 'comment 5', 'post_id' => 2, 'author_id' => 2), $post->comments[0]->attributes); $this->assertEquals(array('id' => 4, 'content' => 'comment 4', 'post_id' => 2, 'author_id' => 2), $post->comments[1]->attributes); $post = Post::model()->findByPk(4); $this->assertEquals(array(), $post->comments); // test manyMany $post = Post::model()->findByPk(2); $this->assertEquals(2, count($post->categories)); $this->assertEquals(array('id' => 4, 'name' => 'cat 4', 'parent_id' => 1), $post->categories[0]->attributes); $this->assertEquals(array('id' => 1, 'name' => 'cat 1', 'parent_id' => null), $post->categories[1]->attributes); $post = Post::model()->findByPk(4); $this->assertEquals(array(), $post->categories); // test self join $category = Category::model()->findByPk(5); $this->assertEquals(array(), $category->posts); $this->assertEquals(2, count($category->children)); $this->assertEquals(array('id' => 6, 'name' => 'cat 6', 'parent_id' => 5), $category->children[0]->attributes); $this->assertEquals(array('id' => 7, 'name' => 'cat 7', 'parent_id' => 5), $category->children[1]->attributes); $this->assertTrue($category->parent instanceof Category); $this->assertEquals(array('id' => 1, 'name' => 'cat 1', 'parent_id' => null), $category->parent->attributes); $category = Category::model()->findByPk(2); $this->assertEquals(1, count($category->posts)); $this->assertEquals(array(), $category->children); $this->assertNull($category->parent); // test composite key $order = Order::model()->findByPk(array('key1' => 1, 'key2' => 2)); $this->assertEquals(2, count($order->items)); $order = Order::model()->findByPk(array('key1' => 2, 'key2' => 1)); $this->assertEquals(0, count($order->items)); $item = Item::model()->findByPk(4); $this->assertTrue($item->order instanceof Order); $this->assertEquals(array('key1' => 2, 'key2' => 2, 'name' => 'order 22'), $item->order->attributes); }
?> <div class="nav btn-group background-color-5"> <div class="table-cell"> <div class="btn btn-small arrow-left-white-large background-color-hover-6"></div> </div> <div class="table-cell full-width"> <div class="btn btn-large cursor-default">同类推荐</div> </div> <div class="table-cell"> <div class="btn btn-small arrow-right-white-large no-border background-color-hover-6"></div> </div> </div> <div class="recommend-item-list"> <?php $cri = new CDbCriteria(array('condition' => 'item_id != ' . $model->item_id . ' and category_id =' . $model->category_id, 'limit' => '7')); $items = Item::model()->findAll($cri); if ($items) { echo '<ul>'; foreach ($items as $i) { ?> <li> <div class="image"><?php echo $i->getMainPic('150', '150'); ?> </div> <div class="title"><?php echo $i->getTitle(); ?> </div> <div class="clear"></div> <div class="price">零售价:<span
public function actionPriceHistory($item_id) { $model = new ItemPrice('search'); $model->unsetAttributes(); // $item = Item::model()->getItemInfo($item_id); if (Yii::app()->request->isAjaxRequest) { $cs = Yii::app()->clientScript; $cs->scriptMap = array('jquery.js' => false, 'bootstrap.js' => false, 'jquery.ba-bbq.min.js' => false, 'jquery.yiigridview.js' => false, 'bootstrap.min.js' => false, 'jquery.min.js' => false, 'bootstrap.notify.js' => false, 'bootstrap.bootbox.min.js' => false); Yii::app()->clientScript->scriptMap['*.js'] = false; //Yii::app()->clientScript->scriptMap['*.css'] = false; if (isset($_GET['ajax']) && $_GET['ajax'] == 'pricehistory-grid') { $this->render('_price_history', array('model' => $model, 'item_id' => $item_id, 'item' => $item)); } else { echo CJSON::encode(array('status' => 'render', 'div' => $this->renderPartial('_price_history', array('model' => $model, 'item_id' => $item_id, 'item' => $item), true, true))); Yii::app()->end(); } } else { $this->render('_price_history', array('model' => $model, 'item_id' => $item_id, 'item' => $item)); } }
public function undodeleteItem($id) { Item::model()->updateByPk((int) $id, array('status' => Yii::app()->params['active_status'])); }
/** * ajax 成功后一般返回json数据 * 然后jquery读取出来 * 在写个function, 转为html */ public function actionGetPropValues() { $category_id = $_POST['category_id'] ? $_POST['category_id'] : NULL; $item_id = $_POST['item_id'] ? $_POST['item_id'] : NULL; $item = Item::model()->findByPk($item_id); $props_arr = CJSON::decode($item->props, TRUE); $skus_arr = CJSON::decode($item->skus, TRUE); // $props_arr = explode(';', $props_list->props); // foreach ($props_arr as $k => $v) { // $arr[] = explode(':', $v); // if(is_array($arr)){ // // } // } // foreach ($newarr as $k => $v) { // $v_arr = explode(',', $v[1]); // $arr[$v[0]] = $v_arr; // } // $arr = array('3'=>'106', '1'=>'78', '2'=>'82'); // 关键属性 $cri = new CDbCriteria(array('condition' => 'is_key_prop=1 and category_id =' . $category_id)); $props = ItemProp::model()->findAll($cri); foreach ($props as $p) { echo '<div class="row">'; if ($p->must == 1) { echo '<label class="span2 control-label" for="">' . $p->prop_name . '<span class="required">*</span></label>'; } else { echo '<label class="span2 control-label" for="">' . $p->prop_name . '</label>'; } echo '<div class="span10">'; if ($p->type == 'input') { echo $p->getPropTextFieldValues($p->prop_name, $props_arr[$p->prop_id]); } elseif ($p->type == 'optional') { echo $p->getPropOptionValues($p->prop_name, $props_arr[$p->prop_id]); } elseif ($p->type == 'multiCheck') { echo $p->getPropCheckBoxListValues($p->prop_name, $props_arr[$p->prop_id]); } echo '</div>'; echo '</div>'; } // 非关键属性 $cri = new CDbCriteria(array('condition' => 'is_key_prop=0 and is_sale_prop=0 and category_id =' . $category_id)); $props = ItemProp::model()->findAll($cri); foreach ($props as $p) { echo '<div class="row">'; if ($p->must == 1) { echo '<label class="span2 control-label" for="">' . $p->prop_name . '<span class="required">*</span></label>'; } else { echo '<label class="span2 control-label" for="">' . $p->prop_name . '</label>'; } echo '<div class="span9">'; if ($p->type == 'input') { echo $p->getPropTextFieldValues($p->prop_name, $props_arr[$p->prop_id][0]); } elseif ($p->type == 'optional') { echo $p->getPropOptionValues($p->prop_name, $props_arr[$p->prop_id]); } elseif ($p->type == 'multiCheck') { echo $p->getPropCheckBoxListValues($p->prop_name, $props_arr[$p->prop_id]); } echo '</div>'; echo '</div>'; } //销售属性 $cri = new CDbCriteria(array('condition' => 'is_sale_prop=1 and category_id =' . $category_id)); $props = ItemProp::model()->findAll($cri); if ($props) { echo '<div class="row">'; echo '<label class="span2 control-label" for="">商品规格</label>'; echo '<div class="span9">'; echo '<div class="sku-wrap">'; $ii = 0; foreach ($props as $p) { echo '<div class="sku-group"><label class="sku-head">' . $p->prop_name . '</label>'; echo '<div class="sku-box sku-color">'; if ($p->type == 'multiCheck') { echo $p->getPropCheckBoxListValues($p->prop_name, $skus_arr['checkbox'][$p->prop_id], 'change', 'skus', 'checkbox'); } $thead .= '<th> <span id="thop_' . $ii . '">' . $p->prop_name . '</span></th>'; $ii++; echo '</div></div>'; } echo '<p id="output"></p>'; echo '</div>'; echo '</div>'; echo '</div>'; echo <<<EOF \t <div class="row" style='margin-bottom:10px' style="visibility:hidden"> \t <div class="span2"> </div> \t <div class="span9" style="padding-left:0"> \t <div class="sku-map"> \t <table id="sku" class="table table-bordered"> \t <thead> \t <tr> \t\t{$thead} \t\t<th>价格</th><th>数量</th><th>商家编码</th><th>操作</th></tr> \t </thead> \t <tbody> \t </tbody> \t </table> \t </div> \t</div> </div> EOF; } }
public static function findByPk($pk, $fromDate, $toDate, $periodFrom, $periodTo) { $itStat = new ItemStatistics(); $itStat->item = Item::model()->findByPk($pk); return ItemStatistics::find($itStat, $fromDate, $toDate, $periodFrom, $periodTo); }
$condition = 'is_best = 1 and '; } elseif ($key == 'promote') { $condition = 'is_promote = 1 and '; } elseif ($key == 'all') { $condition = ''; } else { $condition = ''; } $cid = $category->getDescendantsId(); if ($cid) { $extra = 'category_id in (' . $category->id . ', ' . $cid . ')'; } else { $extra = 'category_id in (' . $category->id . ')'; } $criteria = new CDbCriteria(array('condition' => $condition . $extra, 'limit' => '10')); $items = Item::model()->findAll($criteria); if ($items) { foreach ($items as $i) { ?> <li> <?php echo CHtml::hiddenField('id', $i->item_id); ?> <?php echo CHtml::hiddenField('pic_url', $i->getSmallThumb()); ?> <?php echo CHtml::hiddenField('sn', $i->sn); ?> <?php
public static function treeRemove($nItemId) { $oItem = Item::model()->findByPk($nItemId); if (!$oItem) { Yii::log('Cannot find Item ID:' . $nItemId, CLogger::LEVEL_ERROR); return FALSE; } if (count(Item::getChildren($nItemId))) { Yii::log('Cannot delete Item having children ID:' . $nItemId, CLogger::LEVEL_WARNING); return FALSE; } $aSiblings = Item::getChildren($oItem->parentId); if ($oItem->position < count($aSiblings) - 1) { foreach ($aSiblings as $oSibling) { if ($oSibling->position > $oItem->position) { $oSibling->position -= 1; $oSibling->save(); } } } if (!$oItem->delete()) { Yii::log('Cannot delete Item ID:' . $nItemId, CLogger::LEVEL_ERROR); return FALSE; } return TRUE; }