本文整理汇总了PHP中app\modules\shop\models\Product::className方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::className方法的具体用法?PHP Product::className怎么用?PHP Product::className使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\modules\shop\models\Product
的用法示例。
在下文中一共展示了Product::className方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* @return string
*/
public function run()
{
parent::run();
if (null === $this->rootCategory) {
return '';
}
$cacheKey = $this->className() . ':' . implode('_', [$this->viewFile, $this->rootCategory, null === $this->depth ? 'null' : intval($this->depth), intval($this->includeRoot), intval($this->fetchModels), intval($this->onlyNonEmpty), implode(',', $this->excludedCategories), \Yii::$app->request->url]) . ':' . json_encode($this->additional);
if (false !== ($cache = \Yii::$app->cache->get($cacheKey))) {
return $cache;
}
/** @var array|Category[] $tree */
$tree = Category::getMenuItems(intval($this->rootCategory), $this->depth, boolval($this->fetchModels));
if (true === $this->includeRoot) {
if (null !== ($_root = Category::findById(intval($this->rootCategory)))) {
$tree = [['label' => $_root->name, 'url' => Url::toRoute(['@category', 'category_group_id' => $_root->category_group_id, 'last_category_id' => $_root->id]), 'id' => $_root->id, 'model' => $this->fetchModels ? $_root : null, 'items' => $tree]];
}
}
if (true === $this->onlyNonEmpty) {
$_sq1 = (new Query())->select('main_category_id')->distinct()->from(Product::tableName());
$_sq2 = (new Query())->select('category_id')->distinct()->from('{{%product_category}}');
$_query = (new Query())->select('id')->from(Category::tableName())->andWhere(['not in', 'id', $_sq1])->andWhere(['not in', 'id', $_sq2])->all();
$this->excludedCategories = array_merge($this->excludedCategories, array_column($_query, 'id'));
}
$tree = $this->filterTree($tree);
$cache = $this->render($this->viewFile, ['tree' => $tree, 'fetchModels' => $this->fetchModels, 'additional' => $this->additional, 'activeClass' => $this->activeClass, 'activateParents' => $this->activateParents]);
\Yii::$app->cache->set($cacheKey, $cache, 0, new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(Category::className()), ActiveRecordHelper::getCommonTag(Product::className())]]));
return $cache;
}
示例2: actionPrint
/**
* @return string
*/
public function actionPrint()
{
$this->layout = 'print';
$products = ProductCompareHelper::getProductsList(true);
$object = Object::getForClass(Product::className());
return $this->render('print', ['error' => empty($products) || null === $object, 'message' => Yii::t('app', 'No products for comparing'), 'object' => $object, 'products' => $products]);
}
示例3: function
function __construct($filename)
{
if (is_file($filename)) {
$this->filename = $filename;
$xml = new \XMLReader();
if (false !== $xml->open($filename)) {
$this->xml = $xml;
$rootCategory = Category::findOne(['parent_id' => 0]);
if (empty($rootCategory)) {
if (null === ($rootCategory = Category::createEmptyCategory(0, null, 'Каталог'))) {
$this->xml->close();
$this->xml = null;
}
$this->rootCategoryCache = $rootCategory->id;
} else {
$this->rootCategoryCache = $rootCategory->id;
}
if (empty(static::$propertiesCache)) {
static::$propertiesCache = array_reduce(CommercemlGuid::find([['>', 'model_id', 0], ['type' => 'PROPERTY']])->all(), function ($result, $item) {
$result[$item['guid']] = $item->property;
return $result;
}, []);
}
$this->objectProduct = Object::getForClass(Product::className());
}
}
}
示例4: actionIndex
public function actionIndex($category_id = null)
{
$searchModel = new Category();
$searchModel->active = 1;
$params = Yii::$app->request->get();
$dataProvider = $searchModel->search($params);
$selectedCategory = null;
if ($category_id !== null) {
$selectedCategory = Category::findById($category_id);
}
if ($selectedCategory !== null) {
if (Yii::$app->request->isPost === true) {
$newProperty = isset($_GET['add_property_id']) ? Property::findById($_GET['add_property_id']) : null;
if ($newProperty !== null) {
$filterSet = new FilterSets();
$filterSet->category_id = $selectedCategory->id;
$filterSet->property_id = $newProperty->id;
$filterSet->sort_order = 65535;
$filterSet->save();
}
}
}
$groups = PropertyGroup::getForObjectId(Object::getForClass(Product::className())->id, false);
$propertiesDropdownItems = [];
foreach ($groups as $group) {
$item = ['label' => $group->name, 'url' => '#', 'items' => []];
$properties = Property::getForGroupId($group->id);
foreach ($properties as $prop) {
$item['items'][] = ['label' => $prop->name, 'url' => '?category_id=' . $category_id . '&add_property_id=' . $prop->id, 'linkOptions' => ['class' => 'add-property-to-filter-set', 'data-property-id' => $prop->id, 'data-action' => 'post']];
}
$propertiesDropdownItems[] = $item;
}
return $this->render('index', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel, 'selectedCategory' => $selectedCategory, 'propertiesDropdownItems' => $propertiesDropdownItems]);
}
示例5: actionEdit
public function actionEdit($id = null)
{
$model = new PrefilteredPages();
$model->loadDefaultValues();
if ($id !== null) {
$model = PrefilteredPages::findOne($id);
}
$static_values_properties = [];
$property_groups_ids_for_object = (new Query())->select('id')->from(PropertyGroup::tableName())->where(['object_id' => Object::getForClass(Product::className())->id])->column();
$properties = Property::find()->andWhere(['in', 'property_group_id', $property_groups_ids_for_object])->all();
foreach ($properties as $prop) {
/** @var Property $prop */
$static_values_properties[$prop->id] = ['property' => $prop, 'static_values_select' => PropertyStaticValues::getSelectForPropertyId($prop->id), 'has_static_values' => $prop->has_static_values === 1];
}
$post = \Yii::$app->request->post();
if ($model->load($post) && $model->validate()) {
$save_result = $model->save();
if ($save_result) {
Yii::$app->session->setFlash('info', Yii::t('app', 'Object saved'));
$returnUrl = Yii::$app->request->get('returnUrl', ['index', 'id' => $model->id]);
switch (Yii::$app->request->post('action', 'save')) {
case 'next':
return $this->redirect(['edit', 'returnUrl' => $returnUrl]);
case 'back':
return $this->redirect($returnUrl);
default:
return $this->redirect(Url::toRoute(['edit', 'id' => $model->id, 'returnUrl' => $returnUrl]));
}
//return $this->redirect(['/backend/prefiltered-pages/edit', 'id' => $model->id]);
} else {
\Yii::$app->session->setFlash('error', Yii::t('app', 'Cannot update data'));
}
}
return $this->render('prefiltered-page-form', ['model' => $model, 'static_values_properties' => $static_values_properties]);
}
示例6: getLinks
protected function getLinks()
{
if (!is_null($this->frontendLink) || !is_null($this->backendLink)) {
return true;
}
/** @var Image $image */
$image = Image::findById($this->img_id);
if (is_null($image) || is_null($object = Object::findById($image->object_id))) {
return false;
}
/** @var \app\models\Object $object */
switch ($object->object_class) {
case Page::className():
$this->getPageLinks($image->object_model_id);
break;
case Category::className():
$this->getCategoryLinks($image->object_model_id);
break;
case Product::className():
$this->getProductLinks($image->object_model_id);
break;
default:
return false;
}
return true;
}
示例7: down
public function down()
{
$this->dropTable('{{%special_price_list_type}}');
$this->dropTable('{{%special_price_object}}');
$this->dropColumn('{{%special_price_list}}', 'type_id');
$this->addColumn('{{%special_price_list}}', 'type', "ENUM('core', 'discount', 'delivery', 'project') DEFAULT 'project'");
$this->update('{{%special_price_list}}', ['type' => 'core'], ['class' => 'app\\modules\\shop\\models\\Currency', 'object_id' => Object::getForClass(Product::className())->id]);
$this->update('{{%special_price_list}}', ['type' => 'discount'], ['class' => 'app\\modules\\shop\\models\\Discount', 'object_id' => Object::getForClass(Product::className())->id]);
$this->delete('{{%special_price_list}}', ['class' => 'app\\modules\\shop\\models\\Discount', 'object_id' => Object::getForClass(Order::className())->id]);
}
示例8: up
public function up()
{
// return false;
$this->addColumn('{{%special_price_list}}', 'handler', Schema::TYPE_STRING);
$this->update('{{%special_price_list}}', ['class' => 'app\\modules\\shop\\helpers\\PriceHandlers', 'handler' => 'getCurrencyPriceProduct'], ['class' => 'app\\modules\\shop\\models\\Currency', 'object_id' => \app\models\Object::getForClass(\app\modules\shop\models\Product::className())->id]);
$this->update('{{%special_price_list}}', ['class' => 'app\\modules\\shop\\helpers\\PriceHandlers', 'handler' => 'getDiscountPriceProduct'], ['class' => 'app\\modules\\shop\\models\\Discount', 'object_id' => \app\models\Object::getForClass(\app\modules\shop\models\Product::className())->id]);
$this->update('{{%special_price_list}}', ['class' => 'app\\modules\\shop\\helpers\\PriceHandlers', 'handler' => 'getDiscountPriceOrder'], ['class' => 'app\\modules\\shop\\models\\Discount', 'object_id' => \app\models\Object::getForClass(\app\modules\shop\models\Order::className())->id]);
$this->insert('{{%special_price_list}}', ['object_id' => \app\models\Object::getForClass(\app\modules\shop\models\Order::className())->id, 'class' => 'app\\modules\\shop\\helpers\\PriceHandlers', 'active' => 1, 'sort_order' => 12, 'handler' => 'getDeliveryPriceOrder', 'type_id' => (new \yii\db\Query())->select('id')->from('{{%special_price_list_type}}')->where(['key' => 'delivery'])->scalar()]);
$this->insert('{{%events}}', ['owner_class_name' => 'app\\modules\\shop\\ShopModule', 'event_name' => 'order_calculate', 'event_class_name' => 'app\\modules\\shop\\events\\OrderCalculateEvent', 'selector_prefix' => '', 'event_description' => '', 'documentation_link' => '']);
$eventId = $this->db->lastInsertID;
$this->insert('{{%event_handlers}}', ['event_id' => $eventId, 'sort_order' => 0, 'handler_class_name' => 'app\\modules\\shop\\helpers\\PriceHandlers', 'handler_function_name' => 'handleSaveDiscounts', 'is_active' => 1, 'non_deletable' => 0, 'triggering_type' => 'application_trigger']);
}
示例9: run
/**
* @return string
*/
public function run()
{
parent::run();
if (!$this->product instanceof Product) {
return '';
}
$cacheKey = 'RelatedProduct:' . implode('_', [$this->viewFile, $this->product, json_encode($this->additional)]);
if (false !== ($cache = \Yii::$app->cache->get($cacheKey))) {
return $cache;
}
$result = $this->render($this->viewFile, ['model' => $this->product, 'products' => $this->product->relatedProducts, 'additional' => $this->additional]);
\Yii::$app->cache->set($cacheKey, $result, 0, new TagDependency(['tags' => [ActiveRecordHelper::getObjectTag(Product::className(), $this->product->id), ActiveRecordHelper::getCommonTag(\app\modules\shop\models\RelatedProduct::className())]]));
return $result;
}
示例10: run
public function run()
{
app\backend\assets\FrontendEditingAsset::register($this->view);
$items = [['label' => Icon::show('dashboard') . ' ' . Yii::t('app', 'Backend'), 'url' => ['/backend/']]];
switch (Yii::$app->requestedRoute) {
case 'shop/product/list':
if (isset($_GET['properties'])) {
$apply_if_params = [];
foreach ($_GET['properties'] as $property_id => $values) {
if (isset($values[0])) {
$apply_if_params[$property_id] = $values[0];
}
}
if (Yii::$app->response->dynamic_content_trait === true) {
$items[] = ['label' => Icon::show('puzzle') . ' ' . Yii::t('app', 'Edit Dynamic Content'), 'url' => ['/backend/dynamic-content/edit', 'id' => Yii::$app->response->matched_dynamic_content_trait_model->id]];
} else {
if (isset($_GET['properties'], $_GET['last_category_id'])) {
$items[] = ['label' => Icon::show('puzzle') . ' ' . Yii::t('app', 'Add Dynamic Content'), 'url' => ['/backend/dynamic-content/edit', 'DynamicContent' => ['apply_if_params' => Json::encode($apply_if_params), 'apply_if_last_category_id' => $_GET['last_category_id'], 'object_id' => Object::getForClass(app\modules\shop\models\Product::className())->id, 'route' => 'shop/product/list']]];
}
}
} else {
// no properties selected - go to category edit page
if (isset($_GET['last_category_id'])) {
$reviewsLink = $this->getReviewEditParams("Category", intval($_GET['last_category_id']));
$cat = app\modules\shop\models\Category::findById($_GET['last_category_id']);
$items[] = ['label' => Icon::show('pencil') . ' ' . Yii::t('app', 'Edit category'), 'url' => ['/shop/backend-category/edit', 'id' => $cat->id, 'parent_id' => $cat->parent_id]];
}
}
break;
case 'shop/product/show':
if (isset($_GET['model_id'])) {
$reviewsLink = $this->getReviewEditParams("Product", intval($_GET['model_id']));
$items[] = ['label' => Icon::show('pencil') . ' ' . Yii::t('app', 'Edit product'), 'url' => ['/shop/backend-product/edit', 'id' => intval($_GET['model_id'])]];
}
break;
case '/page/page/show':
case '/page/page/list':
if (isset($_GET['id'])) {
$page = app\modules\page\models\Page::findById($_GET['id']);
$reviewsLink = $this->getReviewEditParams("Page", $_GET['id']);
$items[] = ['label' => Icon::show('pencil') . ' ' . Yii::t('app', 'Edit page'), 'url' => ['/page/backend/edit', 'id' => $page->id, 'parent_id' => $page->parent_id]];
}
break;
}
if (!empty($reviewsLink)) {
$items[] = $reviewsLink;
}
return $this->render('floating-panel', ['items' => $items, 'bottom' => $this->bottom]);
}
示例11: editQuery
public static function editQuery(SearchEvent $event)
{
/** @var \app\modules\shop\ShopModule $module */
$module = \Yii::$app->modules['shop'];
/** @var \app\modules\shop\ShopModule $module */
$properties = (new Query())->select('`id`')->from(PropertyStaticValues::tableName())->where('`name` LIKE :q')->addParams([':q' => '%' . $event->q . '%'])->all();
$event->activeQuery->select('{{%object_static_values}}.object_model_id')->distinct(true)->from(ObjectStaticValues::tableName())->where('{{%object_static_values}}.object_id = :objectId')->addParams([':objectId' => Object::getForClass(Product::className())->id])->andWhere(['in', '{{%object_static_values}}.property_static_value_id', ArrayHelper::getColumn($properties, 'id')]);
if ($module->allowSearchGeneratedProducts != 1) {
$event->activeQuery->innerJoin('{{%product}}', '{{%product}}.id = {{%object_static_values}}.object_model_id');
$event->activeQuery->andWhere(['{{%product}}.parent_id' => 0, '{{%product}}.active' => 1]);
}
$event->setFunctionSearch(function ($activeQuery) {
return ArrayHelper::getColumn($activeQuery->all(), 'object_model_id');
});
}
示例12: run
/**
* @inheritdoc
*/
public function run()
{
$n = 0;
switch ($this->action) {
case CategoryMovementsButtons::ADD_ACTION:
$n = $this->add();
break;
case CategoryMovementsButtons::MOVE_ACTION:
$n = $this->move();
break;
}
$tags = [];
foreach ($this->items as $id) {
$tags[] = ActiveRecordHelper::getObjectTag(Product::className(), $id);
}
TagDependency::invalidate(Yii::$app->cache, $tags);
Yii::$app->session->setFlash('info', Yii::t('app', 'Items updated: {n}', ['n' => $n]));
}
示例13: getPossibleSelections
public function getPossibleSelections()
{
$allowed_category_ids = [];
if ($this->onlyAvailableProducts) {
$object = Object::getForClass(Product::className());
if (!is_null($object) && isset($this->current_selections['last_category_id'])) {
$cacheKey = 'CategoriesFilterWidget: ' . $object->id . ':' . $this->current_selections['last_category_id'] . ':' . Json::encode($this->current_selections['properties']);
$allowed_category_ids = Yii::$app->cache->get($cacheKey);
if ($allowed_category_ids === false) {
$query = new Query();
$query = $query->select($object->categories_table_name . '.category_id')->distinct()->from($object->categories_table_name);
if (count($this->current_selections['properties']) > 0) {
foreach ($this->current_selections['properties'] as $property_id => $values) {
$joinTableName = 'OSVJoinTable' . $property_id;
$query->join('JOIN', ObjectStaticValues::tableName() . ' ' . $joinTableName, $joinTableName . '.object_id = :objectId AND ' . $joinTableName . '.object_model_id = ' . $object->categories_table_name . '.object_model_id ', [':objectId' => $object->id]);
$imploded_values = implode(', ', array_map('intval', $values));
$query->andWhere(new Expression('`' . $joinTableName . '`.`property_static_value_id`' . ' in (' . $imploded_values . ')'));
}
}
$allowed_category_ids = $query->column();
Yii::$app->cache->set($cacheKey, $allowed_category_ids, 86400, new \yii\caching\TagDependency(['tags' => [\devgroup\TagDependencyHelper\ActiveRecordHelper::getCommonTag($object->object_class), \devgroup\TagDependencyHelper\ActiveRecordHelper::getCommonTag(Category::className())]]));
$object = null;
}
}
}
$this->possible_selections = [];
$models = Category::getByLevel($this->category_group_id);
if (isset($models[0]) && $this->omit_root == true) {
$models = Category::getByParentId($models[0]->id);
}
$this->possible_selections = [];
foreach ($models as $model) {
if ($this->onlyAvailableProducts === true && !in_array($model->id, $allowed_category_ids)) {
continue;
}
$this->possible_selections[] = $this->recursiveGetTree($model, $allowed_category_ids);
}
return $this->possible_selections;
}
示例14: actionClone
/**
* Clone product action.
* @param integer $id
* @throws \yii\web\NotFoundHttpException
*/
public function actionClone($id, $returnUrl = ['index'])
{
/** @var Product|HasProperties $model */
$model = Product::findOne($id);
if ($model === null) {
throw new NotFoundHttpException();
}
/** @var Product|HasProperties $newModel */
$newModel = new Product();
$newModel->setAttributes($model->attributes, false);
$time = time();
$newModel->name .= ' (copy ' . date('Y-m-d h:i:s', $time) . ')';
$newModel->slug .= '-copy-' . date('Ymdhis', $time);
$newModel->id = null;
if ($newModel->validate() === false) {
$newModel->slug = substr(uniqid() . "-" . $model->slug, 0, 80);
}
if ($newModel->save()) {
$object = Object::getForClass(get_class($newModel));
// save categories
$categoriesTableName = Object::getForClass(Product::className())->categories_table_name;
$query = new Query();
$params = $query->select(['category_id', 'sort_order'])->from($categoriesTableName)->where(['object_model_id' => $model->id])->all();
if (!empty($params)) {
$rows = [];
foreach ($params as $param) {
$rows[] = [$param['category_id'], $newModel->id, $param['sort_order']];
}
Yii::$app->db->createCommand()->batchInsert($categoriesTableName, ['category_id', 'object_model_id', 'sort_order'], $rows)->execute();
}
// save images bindings
$params = $query->select(['object_id', 'filename', 'image_title', 'image_alt', 'sort_order'])->from(Image::tableName())->where(['object_id' => $object->id, 'object_model_id' => $model->id])->all();
if (!empty($params)) {
$rows = [];
foreach ($params as $param) {
$rows[] = [$param['object_id'], $newModel->id, $param['filename'], $param['image_title'], $param['image_alt'], $param['sort_order']];
}
Yii::$app->db->createCommand()->batchInsert(Image::tableName(), ['object_id', 'object_model_id', 'filename', 'image_title', 'image_alt', 'sort_order'], $rows)->execute();
}
$newModelProps = [];
foreach (array_keys($model->propertyGroups) as $key) {
$opg = new ObjectPropertyGroup();
$opg->attributes = ['object_id' => $object->id, 'object_model_id' => $newModel->id, 'property_group_id' => $key];
$opg->save();
$props = Property::getForGroupId($key);
foreach ($props as $prop) {
$propValues = $model->getPropertyValuesByPropertyId($prop->id);
if ($propValues !== null) {
foreach ($propValues->values as $val) {
$valueToSave = ArrayHelper::getValue($val, 'psv_id', $val['value']);
$newModelProps[$prop->key][] = $valueToSave;
}
}
}
}
$newModel->saveProperties(['Properties_Product_' . $newModel->id => $newModelProps]);
Yii::$app->session->setFlash('success', Yii::t('app', 'Product has been cloned successfully.'));
$this->redirect(['edit', 'id' => $newModel->id, 'returnUrl' => $returnUrl]);
}
}
示例15: array_combine
$feed_settings = [];
$feed_settings['product_fields'] = (new \app\modules\shop\models\Product())->attributeLabels();
$feed_settings['relations_keys'] = array_combine(array_keys($feed_relations), array_keys($feed_relations));
$feed_settings['relations_map'] = [];
foreach ($feed_relations as $key => $value) {
$_fields = (new $value())->attributeLabels();
$feed_settings['relations_map'][$key] = ['fields' => $_fields, 'html' => array_reduce($_fields, function ($result, $i) {
$result .= '<option value="' . addslashes(htmlspecialchars($i)) . '">' . addslashes(htmlspecialchars($i)) . '</option>';
return $result;
}, '')];
}
if (true === isset($feed_settings['relations_map']['getImage'])) {
$feed_settings['relations_map']['getImage']['fields']['file'] = Yii::t('app', 'File');
$feed_settings['relations_map']['getImage']['html'] .= '<option value="file">' . Yii::t('app', 'File') . '</option>';
}
$prop_group = \app\models\Object::getForClass(\app\modules\shop\models\Product::className())->id;
$provider = (new \yii\db\Query())->select(['pg.name as pgname', 'p.name', 'p.id', 'p.handler_additional_params'])->from(\app\models\Property::tableName() . ' as p', \app\models\PropertyGroup::tableName() . 'as pg')->leftJoin(\app\models\PropertyGroup::tableName() . 'as pg', 'pg.id=p.property_group_id')->where(['pg.object_id' => $prop_group]);
$prop_group = $provider->all();
$feed_settings['properties_map'] = ['html' => '', 'fields' => []];
$feed_settings['properties_map'] = array_reduce(array_reduce($prop_group, function ($result, $i) {
if (isset($result[$i['pgname']])) {
$result[$i['pgname']]['html'] .= '<option value="' . addslashes(htmlspecialchars($i['id'])) . '">' . addslashes(htmlspecialchars($i['name'])) . '</option>';
$result[$i['pgname']]['fields'][$i['pgname']][$i['id']] = $i['name'];
$result[$i['pgname']]['name'] = $i['pgname'];
}
return $result;
}, array_fill_keys(array_unique(array_column($prop_group, 'pgname')), ['fields' => [], 'html' => '', 'name' => ''])), function ($result, $i) {
$result['fields'] = array_replace($result['fields'], $i['fields']);
$result['html'] .= '<optgroup label="' . addslashes(addslashes($i['name'])) . '">' . addslashes(addslashes($i['html'])) . '</optgroup>';
return $result;
}, $feed_settings['properties_map']);