public function beforeAction($action) { $this->language_id = LanguageModel::getLanguageIdByCode(Yii::app()->language); if (isset($_POST['dropUpload']) && $_POST['dropUpload'] == 1) { $this->handleUploads(); } return true; }
/** * @return array relational rules. */ public function relations() { // NOTE: you may need to adjust the relation name and the related // class name for the relations automatically generated below. return array( 'value_description' => array(self::HAS_ONE, 'ValueDescription', 'value_id', 'condition' => 'value_description.language_id = ' . LanguageModel::getLanguageIdByCode(Yii::app()->language)), ); }
/** * @return array relational rules. */ public function relations() { // NOTE: you may need to adjust the relation name and the related // class name for the relations automatically generated below. return array( 'variation_description' => array(self::HAS_ONE, 'VariationDescription', 'variation_id', 'condition' => 'variation_description.language_id = ' . LanguageModel::getLanguageIdByCode(Yii::app()->language)), 'attributes' => array(self::MANY_MANY, 'Attribute', 'variation2attribute(attribute_id, variation_id)', 'condition' => 'attributes.status = 1'), ); }
/** * @return array relational rules. */ public function relations() { // NOTE: you may need to adjust the relation name and the related // class name for the relations automatically generated below. return array( 'category' => array( self::BELONGS_TO, 'Category', 'category_id', 'on' => 'category_description.language_id=' . LanguageModel::getLanguageIdByCode(Yii::app()->language) ), ); }
/** * @return array relational rules. */ public function relations() { // NOTE: you may need to adjust the relation name and the related // class name for the relations automatically generated below. return array( 'product_description' => array(self::HAS_ONE, 'ProductDescription', 'product_id', 'condition' => 'product_description.language_id = ' . LanguageModel::getLanguageIdByCode(Yii::app()->language)), 'variations' => array(self::MANY_MANY, 'Variation', 'product2variation(product_id, variation_id)'), 'category' => array( self::MANY_MANY, 'Category', 'category2product(product_id, category_id)', ), 'category2product' => array(self::MANY_MANY, 'Category', 'category2product(product_id, category_id)'), ); }
/** * @return array relational rules. */ public function relations() { // NOTE: you may need to adjust the relation name and the related // class name for the relations automatically generated below. return array( 'category_description' => array( self::HAS_ONE, 'CategoryDescription', 'category_id', 'on' => 'category_description.language_id = ' . LanguageModel::getLanguageIdByCode(Yii::app()->language) ), 'parent' => array( self::HAS_ONE, 'CategoryDescription', '', 'on' => 't.parent_id = parent.category_id AND parent.language_id = ' . LanguageModel::getLanguageIdByCode(Yii::app()->language) ), 'children' => array(self::HAS_MANY, 'Category', array('parent_id' => 'category_id'), 'order' => 'children.sort_order, children.category_id', 'on' => 'children.status = 1 OR children.category_id IS NULL', 'joinType' => 'LEFT JOIN'), 'products' => array(self::MANY_MANY, 'Product', 'category2product(category_id, product_id)'), ); }
public function actionSearchProductByName() { if ($_GET['product_name']) { $c = new CDbCriteria(); $c->with = array('product_description' => array('with' => array('product')), 'variations' => array('with' => array('variation_description'))); //$c->together = true; $c->compare('product.status', 1); $c->compare('product_description.language_id', LanguageModel::getLanguageIdByCode(Yii::app()->language)); $c->compare('variation_description.language_id', LanguageModel::getLanguageIdByCode(Yii::app()->language)); $c->addCondition('product_name LIKE :product_name OR variation_name LIKE :variation_name OR variation_description LIKE :variation_description'); $c->params[':product_name'] = '%' . $_GET['product_name'] . '%'; $c->params[':variation_name'] = '%' . $_GET['product_name'] . '%'; $c->params[':variation_description'] = '%' . $_GET['product_name'] . '%'; $products = Product::model()->findAll($c); //CVarDumper::dump($products, 10, true); if (count($products) > 0) { $aResultProducts = array(); foreach ($products as $product) { $aResultProducts[$product->product_description->product_id] = $product->product_description->product_name; if (!empty($product->variations)) { foreach ($product->variations as $variation) { if (strripos($variation->variation_description->variation_name, $_GET['product_name']) !== false) { $aResultProducts[$product->product_description->product_id] .= ' (' . $variation->variation_description->variation_name . ')'; break; } } } } echo json_encode(array('success' => 1, 'products' => $aResultProducts)); } else { echo json_encode(array('success' => 0)); } } die; }