public function up() { $tableOptions = $this->db->driverName === 'mysql' ? 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=MyISAM' : null; $this->insert('{{%object}}', ['name' => 'Addon', 'object_class' => Addon::className(), 'object_table_name' => Yii::$app->db->schema->getRawTableName(Addon::tableName()), 'column_properties_table_name' => Yii::$app->db->schema->getRawTableName('{{%addon_property}}'), 'eav_table_name' => Yii::$app->db->schema->getRawTableName('{{%addon_eav}}'), 'categories_table_name' => Yii::$app->db->schema->getRawTableName('{{%addon_category}}'), 'link_slug_category' => Yii::$app->db->schema->getRawTableName('{{%addon_category_full_slug}}'), 'link_slug_static_value' => Yii::$app->db->schema->getRawTableName('{{%addon_static_value_category}}'), 'object_slug_attribute' => 'slug']); $this->createTable('{{%addon}}', ['id' => $this->primaryKey(), 'name' => $this->text()->notNull(), 'price' => $this->float()->notNull()->defaultValue(0), 'currency_id' => $this->integer()->notNull()->defaultValue(0), 'price_is_multiplier' => $this->boolean()->notNull()->defaultValue(0), 'is_product_id' => $this->integer()->notNull()->defaultValue(0), 'add_to_order' => $this->boolean()->notNull()->defaultValue(0), 'addon_category_id' => $this->integer()->notNull(), 'can_change_quantity' => $this->boolean()->notNull()->defaultValue(0), 'measure_id' => $this->integer()->notNull()->defaultValue(1)], $tableOptions); $this->createIndex('by_category', '{{%addon}}', ['addon_category_id']); if ($this->db->driverName === 'mysql') { // add fulltext index in mysql for name column :-) $this->execute("ALTER TABLE {{%addon}} ADD FULLTEXT(`name`)"); } $this->createTable('{{%addon_category}}', ['id' => $this->primaryKey(), 'name' => $this->text()->notNull()]); // real bindings of addons to objects $this->createTable('{{%addon_bindings}}', ['id' => $this->primaryKey(), 'addon_id' => $this->integer()->notNull(), 'appliance_object_id' => $this->integer()->notNull(), 'object_model_id' => $this->integer()->notNull(), 'sort_order' => $this->integer()->notNull()->defaultValue(0)], $tableOptions); $this->createIndex('addons4object', '{{%addon_bindings}}', ['appliance_object_id', 'object_model_id']); $this->addColumn('{{%order_item}}', 'addon_id', $this->integer()->notNull()->defaultValue(0)); $tblMenu = '{{%backend_menu}}'; /** @var BackendMenu $shopMenuItem */ $shopMenuItem = BackendMenu::findOne(['name' => 'Shop']); $this->batchInsert($tblMenu, ['parent_id', 'name', 'route', 'icon', 'sort_order', 'added_by_ext', 'rbac_check', 'css_class', 'translation_category'], [[$shopMenuItem->id, 'Addons', 'shop/backend-addons/index', 'cart-plus', 0, 'core', 'product manage', '', 'app']]); \yii\caching\TagDependency::invalidate(Yii::$app->cache, [\devgroup\TagDependencyHelper\ActiveRecordHelper::getCommonTag(\app\backend\models\BackendMenu::className())]); }
public function actionAjaxSearchAddons() { Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $result = ['more' => false, 'results' => []]; $search = Yii::$app->request->get('search'); if (!empty($search['term'])) { $query = new \yii\db\Query(); $query->select('id, name as text, price, currency_id')->from(Addon::tableName())->andWhere(['like', 'name', $search['term']])->orderBy(['name' => SORT_ASC]); $command = $query->createCommand(); $data = $command->queryAll(); $data = array_map(function ($item) { $currency = Currency::findById($item['currency_id']); $price = $currency->format($item['price']); $item['text'] .= ' - ' . $price; return $item; }, $data); $result['results'] = array_values($data); } return $result; }