本文整理汇总了PHP中Product::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::model方法的具体用法?PHP Product::model怎么用?PHP Product::model使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Product
的用法示例。
在下文中一共展示了Product::model方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadModel
public function loadModel($id)
{
if (($model = Product::model()->findByPk($id)) === null) {
throw new CHttpException(404, 'Страница не найдена');
}
return $model;
}
示例2: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate($id)
{
if (!empty($id) && !Yii::app()->user->isGuest) {
$customer_email = Yii::app()->user->name;
$customerModel = Customer::model()->findByAttributes(array('customer_email' => $customer_email));
$productId = $id;
$productModel = Product::model()->findByPk($productId);
$model = new Order();
$model->order_product_id = $productModel->product_id;
$model->order_customer_id = $customerModel->customer_id;
$model->order_amount = $productModel->product_price + $productModel->product_shipping_price;
if ($model->save()) {
$attribuits = Order::model()->findByPk($model->order_id);
$str = "Product Name:{$productModel->product_name}\r\n" . "Order Id:{$attribuits->order_id}\r\n" . "Order Product Id:{$attribuits->order_product_id}\r\n" . "Order Customer Id:{$attribuits->order_customer_id}\r\n" . "Total Amount With Shipping Charges:{$attribuits->order_amount}\r\n";
$message = new YiiMailMessage();
$message->subject = "Your order details";
$message->setBody($str);
$message->addTo(Yii::app()->user->name);
$message->from = $customerModel->customer_email;
Yii::app()->mail->send($message);
$this->redirect(array('view', 'id' => $model->order_id));
} else {
echo "booking failed";
}
}
}
示例3: beforeSave
public function beforeSave()
{
if (Product::model()->exists('id = :product_id', [":product_id" => $this->product_id])) {
$this->variant_ids = array_filter($this->variant_ids);
// удаляем варианты, которые не были выбраны, старые не трогаем, чтобы оставить данные, на случай, если вариант был удален из системы
foreach ($this->oldVariants as $key => $var) {
if (!in_array($var['id'], $this->variant_ids)) {
unset($this->oldVariants[$key]);
}
}
$oldVariantIds = array_map(function ($x) {
return $x['id'];
}, $this->oldVariants);
$newVariants = [];
foreach ($this->variant_ids as $varId) {
if (!in_array($varId, $oldVariantIds)) {
/* @var $variant ProductVariant */
$variant = ProductVariant::model()->findByPk($varId);
if ($variant) {
// сохраняем информацию на случай удаления варианта из системы
$newVariants[] = array_merge($variant->attributes, ['attribute_name' => $variant->attribute->name, 'attribute_title' => $variant->attribute->title, 'optionValue' => $variant->getOptionValue()]);
}
}
}
$combinedVariants = array_merge($this->oldVariants, $newVariants);
$this->variants = serialize($combinedVariants);
}
return parent::beforeSave();
}
示例4: getTotalFoundNum
/**
* get the total number according the search criteria
*
* @author youzhao.zxw<swustnjtu@gmail.com>
* @param string $infoType bug,case or result
* @param int $productId product id
* @param string $whereStr search condition string
* @param boolean $isAllBasicField is the search condition only in basic info table
* @return int total number
*
*/
public static function getTotalFoundNum($infoType, $productId, $whereStr, $isAllBasicField = false)
{
$basicTableName = $infoType . 'view';
if (empty($productId)) {
$accessIdArr = Yii::app()->user->getState('visit_product_id');
$productFilter = 'product_id in (' . join(',', $accessIdArr) . ')';
} else {
$productFilter = 'product_id=' . $productId;
}
$searchSql = $productFilter;
if ('' != $whereStr) {
$searchSql .= ' and ' . $whereStr;
}
if ('1 = 1' == trim($whereStr)) {
$rawData = Yii::app()->db->createCommand()->select('count(*) as totalNum')->from('{{' . $infoType . '_info}}')->where($searchSql)->queryRow();
} else {
if (empty($productId)) {
$rawData = Yii::app()->db->createCommand()->select('count({{' . $basicTableName . '}}.id) as totalNum')->from('{{' . $basicTableName . '}}')->where($searchSql)->queryRow();
} else {
$productInfo = Product::model()->findByPk($productId);
if (!empty($productInfo) && "(({{bugview}}.module_name LIKE '" . $productInfo['name'] . "/%' or {{bugview}}.module_name = '" . $productInfo['name'] . "'))" == $whereStr) {
$rawData = Yii::app()->db->createCommand()->select('count(*) as totalNum')->from('{{' . $infoType . '_info}}')->where($productFilter)->queryRow();
} else {
if ($isAllBasicField) {
$rawData = Yii::app()->db->createCommand()->select('count({{' . $basicTableName . '}}.id) as totalNum')->from('{{' . $basicTableName . '}}')->where($searchSql)->queryRow();
} else {
$addOnTableName = 'etton' . $infoType . '_' . $productId;
$rawData = Yii::app()->db->createCommand()->select('count({{' . $basicTableName . '}}.id) as totalNum')->from('{{' . $basicTableName . '}}')->join('{{' . $addOnTableName . '}}', '{{' . $basicTableName . '}}' . '.id=' . '{{' . $addOnTableName . '}}' . '.' . $infoType . '_id and ' . $productFilter)->where($searchSql)->queryRow();
}
}
}
}
return $rawData['totalNum'];
}
示例5: actionIndex
/**
* View a particular product, with localizations and images associated.
*/
public function actionIndex()
{
if (Yii::app()->user->isGuest) {
$cache_id = Yii::app()->request->hostInfo . " Api/LayoutController:[indexForLanguageGuest] " . Yii::app()->language;
$cache_duration = 600;
//10800;
} else {
$cache_id = Yii::app()->request->hostInfo . " Api/LayoutController:[indexForLanguageUser] " . Yii::app()->language . " - " . Yii::app()->user->user->id;
$cache_duration = 1600;
}
$layout_array = Yii::app()->cache->get($cache_id);
if (!$layout_array) {
$layout_parameters = array('storeid' => Yii::app()->params['outbound_api_user'], 'storekey' => Yii::app()->params['outbound_api_secret'], 'locale' => Yii::app()->language . "_CA", 'layout_type' => Yii::app()->params['mainPageLayout']);
if (!Yii::app()->user->isGuest) {
$layout_parameters["email"] = Yii::app()->user->user->email;
}
$output = Yii::app()->curl->get("https://kle-en-main.com/CloudServices/index.php/Layout/boukem/mobileIndex", $layout_parameters);
$base_dict = json_decode($output);
$layout_array = array();
foreach ($base_dict->promoted as $promoted_id) {
$product = Product::model()->findByPk($promoted_id);
if ($product && $product->visible == 1 && $product->productLocalization) {
$layout_array[] = $product->getStructuredProductArray();
}
}
Yii::app()->cache->set($cache_id, $layout_array, $cache_duration);
}
$this->renderJSON($layout_array);
}
示例6: process
public function process()
{
$model = \Product::model();
foreach ($this->products as $product) {
$model->saveItem($product, $this->popularProductIds);
}
}
示例7: safeUp
public function safeUp()
{
$this->createTable('{{store_product_attribute_value}}', ['id' => 'pk', 'product_id' => 'INTEGER NOT NULL', 'attribute_id' => 'INTEGER NOT NULL', 'number_value' => 'REAL', 'string_value' => 'VARCHAR(250)', 'text_value' => 'TEXT', 'option_value' => 'INTEGER', 'create_time' => 'DATETIME'], $this->getOptions());
//fk
$this->addForeignKey('{{fk_product_attribute_product}}', '{{store_product_attribute_value}}', 'product_id', '{{store_product}}', 'id', 'CASCADE');
$this->addForeignKey('{{fk_product_attribute_attribute}}', '{{store_product_attribute_value}}', 'attribute_id', '{{store_attribute}}', 'id', 'CASCADE');
$this->addForeignKey('{{fk_product_attribute_option}}', '{{store_product_attribute_value}}', 'option_value', '{{store_attribute_option}}', 'id', 'CASCADE');
//ix
$this->createIndex('{{ix_product_attribute_number_value}}', '{{store_product_attribute_value}}', 'number_value');
$this->createIndex('{{ix_product_attribute_string_value}}', '{{store_product_attribute_value}}', 'string_value');
//перенести аттрибуты
$attributes = Yii::app()->getDb()->createCommand('SELECT * FROM {{store_product_attribute_eav}}')->queryAll();
$modelsAttr = [];
foreach ($attributes as $attribute) {
$product = Product::model()->findByPk($attribute['product_id']);
if (null === $product) {
continue;
}
if (!isset($modelsAttr[$attribute['attribute']])) {
$model = Attribute::model()->find('name = :name', [':name' => $attribute['attribute']]);
if (null === $model) {
continue;
}
$modelsAttr[$attribute['attribute']] = $model;
}
$value = new AttributeValue();
$value->store($modelsAttr[$attribute['attribute']]->id, $attribute['value'], $product);
}
$this->dropTable('{{store_product_attribute_eav}}');
}
示例8: getOrderProductByOrderId
/**
* 获取订单的商品列表.
* @param $orderId
*/
public function getOrderProductByOrderId($orderId)
{
if (empty($orderId)) {
return '';
}
$list = OrderProduct::model()->findAllByAttributes(array('order_id' => $orderId));
if (empty($list)) {
return '';
}
// todo 图片待处理
$newList = array();
foreach ($list as $row) {
$temp = $row->getAttributes();
if ($row->type == 1) {
$temp['images']['cover'] = '/images/public/tab.png';
} elseif ($row->type == 2) {
$zineInfo = Zine::model()->findByPk($row['product_id']);
if ($zineInfo) {
$temp['images']['cover'] = '/images/zine/' . $zineInfo['mcover'];
} else {
$temp['images']['cover'] = '';
}
} else {
$temp['images'] = Product::model()->getProductFaceImageByProductId($row->product_id);
}
$temp['total_price'] = $temp['sell_price'] * $temp['quantity'];
$newList[$row->id] = $temp;
}
return $newList;
}
示例9: actionUpdate
public function actionUpdate()
{
$pictures = array();
$lid = Yii::app()->request->getParam('lid');
Until::isUpdateValid(array($lid), $this->companyId, $this);
//0,表示企业任何时候都在云端更新。
$criteria = new CDbCriteria();
$criteria->with = 'productImg';
$criteria->addCondition('t.lid=:lid and t.dpid=:dpid and t.delete_flag=0 ');
$criteria->order = ' t.lid desc ';
$criteria->params[':lid'] = $lid;
$criteria->params[':dpid'] = $this->companyId;
$model = Product::model()->find($criteria);
if (Yii::app()->request->isPostRequest) {
$postData = Yii::app()->request->getPost('productImg');
if (ProductPicture::saveImg($this->companyId, $lid, $postData)) {
Yii::app()->user->setFlash('success', yii::t('app', '修改成功'));
$this->redirect(array('productImg/index', 'companyId' => $this->companyId));
}
}
if (!empty($model->productImg)) {
foreach ($model->productImg as $pic) {
array_push($pictures, $pic->pic_path);
}
}
$this->render('updateProductImg', array('model' => $model, 'pictures' => $pictures));
}
示例10: run
public function run()
{
$model = Product::model()->findAll('image is not null');
$module = Yii::app()->getModule('exchange1c');
$basePath = Yii::app()->uploadManager->getBasePath();
// путь до папки uploads public_html
$path = Yii::getPathOfAlias('webroot') . '/..' . $module->pathOut;
// путь до папки out 1c
$string = "Код товара;Имя файла;Размер в байтах;Время последней модификации\n";
// Описание информации
foreach ($model as $key => $value) {
$file = $basePath . '/' . $value->uploadPath . '/' . $value->image;
if (file_exists($file)) {
$info = stat($file);
$nameImage = $value->image;
$code = substr($value->image, 0, 11);
$size = $info['size'];
$mtime = $info['mtime'];
$string .= "{$code};{$nameImage};{$size};{$mtime}\n";
}
}
file_put_contents($path . '/images.csv', $string);
if ($this->redirect) {
Yii::app()->getController()->redirect(['/exchange1c/exchangeBackend/images']);
}
echo $string;
}
示例11: run
public function run()
{
if (empty($this->model) || empty($this->attribute) || !$this->model->hasAttribute($this->attribute) || $this->model->{$this->attribute} == '') {
return;
}
$productIds = trim($this->model->{$this->attribute});
$productIds = trim($productIds, ',');
$productIds = explode(',', $productIds);
if (empty($productIds)) {
return;
}
array_walk($productIds, function ($data) {
return (int) trim($data);
});
$criteria = new CDbCriteria();
$criteria->addInCondition('t.id', $productIds);
//$criteria->order = 't.category_id ASC, t.sort ASC';
$criteria->order = 'FIELD(t.id, ' . implode(',', $productIds) . ')';
if ($this->limit > 0) {
$criteria->limit = (int) $this->limit;
}
$models = Product::model()->published()->findAll($criteria);
//Yii::app()->user->setState('activeProductsList', CJSON::encode(Product::model()->getProductsTotalList(true, $criteria)));
$this->render($this->view, array('models' => $models, 'model' => $this->model, 'title' => $this->title));
}
示例12: onGenerate
/**
* @param Event $event
*/
public static function onGenerate(Event $event)
{
$generator = $event->getGenerator();
$provider = new CActiveDataProvider(Product::model()->published());
foreach (new CDataProviderIterator($provider) as $item) {
$generator->addItem(ProductHelper::getUrl($item, true), strtotime($item->update_time), SitemapHelper::FREQUENCY_DAILY, 0.5);
}
}
示例13: generateProductGrid
/**
* This function generates the products grid
* based on the criteria. It also generates the
* pagination object need for the users to navigate
* through products.
*
* @return void
*/
public function generateProductGrid()
{
$this->_numberOfRecords = Product::model()->count($this->_productGridCriteria);
$this->_pages = new CPagination($this->_numberOfRecords);
$this->_pages->setPageSize(CPropertyValue::ensureInteger(Yii::app()->params['PRODUCTS_PER_PAGE']));
$this->_pages->applyLimit($this->_productGridCriteria);
$this->_productsGrid = self::createBookends(Product::model()->findAll($this->_productGridCriteria));
}
示例14: run
public function run()
{
$criteria = new CDbCriteria();
$criteria->order = "id DESC";
$criteria->limit = 5;
// $criteria->addCondition("is_deleted = 0");
$this->render('lastProduct', array('product' => Product::model()->findAll($criteria)));
}
示例15: setSku
/**
* Set the product for this order-row
* @param string $sku
* @return \Afosto\ActiveAnts\OrderItem
*/
public function setSku($sku, $validate = true)
{
if ($validate && Product::model()->isNewRecord(array('sku' => $sku))) {
throw new ApiException('Product not available at ActiveAnts');
}
$this->sku = $sku;
return $this;
}