Created
September 13, 2011 23:32
-
-
Save VarunBatraIT/1215480 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$this->breadcrumbs=array( | |
'Products'=>array('index'), | |
'Manage', | |
); | |
$this->menu=array( | |
array('label'=>'List Products', 'url'=>array('index')), | |
array('label'=>'Create Products', 'url'=>array('create')), | |
); | |
Yii::app()->clientScript->registerScript('search', " | |
$('.search-button').click(function(){ | |
$('.search-form').toggle(); | |
return false; | |
}); | |
$('.search-form form').submit(function(){ | |
$.fn.yiiGridView.update('products-grid', { | |
data: $(this).serialize() | |
}); | |
return false; | |
}); | |
"); | |
?> | |
<h1>Manage Products</h1> | |
<p> | |
You may optionally enter a comparison operator (<b><</b>, <b><=</b>, <b>></b>, <b>>=</b>, <b><></b> | |
or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done. | |
</p> | |
<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?> | |
<div class="search-form" style="display:none"> | |
<?php $this->renderPartial('_search',array( | |
'model'=>$model, | |
)); ?> | |
</div><!-- search-form --> | |
<?php $this->widget('zii.widgets.grid.CGridView', array( | |
'id'=>'products-grid', | |
'dataProvider'=>$model->search(), | |
'filter'=>$model, | |
'columns'=>array( | |
'products_id', | |
'products_type', | |
'products_quantity', | |
'products_moq', | |
'products_max_order_quantity', | |
'products_price', | |
array( | |
'name'=>'products_name', | |
'header'=>'Products Name', | |
'type'=>'raw', | |
'value'=>'ProductsDescription::getProductsName($data->products_id)' | |
), | |
/* | |
'products_sku', | |
'products_model', | |
'products_date_added', | |
'products_last_modified', | |
'products_date_available', | |
'products_weight', | |
'products_weight_class', | |
'products_status', | |
'products_tax_class_id', | |
'manufacturers_id', | |
'products_ordered', | |
'quantity_discount_groups_id', | |
'quantity_unit_class', | |
'order_increment', | |
'products_attributes_groups_id', | |
*/ | |
array( | |
'class'=>'CButtonColumn', | |
), | |
), | |
)); ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This is the model class for table "vb_products". | |
* | |
* The followings are the available columns in table 'vb_products': | |
* @property integer $products_id | |
* @property integer $products_type | |
* @property integer $products_quantity | |
* @property integer $products_moq | |
* @property integer $products_max_order_quantity | |
* @property string $products_price | |
* @property string $products_sku | |
* @property string $products_model | |
* @property string $products_date_added | |
* @property string $products_last_modified | |
* @property string $products_date_available | |
* @property string $products_weight | |
* @property integer $products_weight_class | |
* @property integer $products_status | |
* @property integer $products_tax_class_id | |
* @property integer $manufacturers_id | |
* @property integer $products_ordered | |
* @property integer $quantity_discount_groups_id | |
* @property integer $quantity_unit_class | |
* @property integer $order_increment | |
* @property integer $products_attributes_groups_id | |
* | |
* The followings are the available model relations: | |
* @property CustomizationFields[] $customizationFields | |
* @property OrdersProducts[] $ordersProducts | |
* @property TaxClass $productsTaxClass | |
* @property Manufacturers $manufacturers | |
* @property QuantityDiscountGroups $quantityDiscountGroups | |
* @property ProductsAttributesGroups $productsAttributesGroups | |
* @property ProductsAccessories[] $productsAccessories | |
* @property ProductsAttachments[] $vbProductsAttachments | |
* @property ProductsAttributes[] $productsAttributes | |
* @property Languages[] $vbLanguages | |
* @property ProductsDownloadables[] $productsDownloadables | |
* @property ProductsFrontpage $productsFrontpage | |
* @property ProductsGiftCertificates $productsGiftCertificates | |
* @property ProductsImages[] $productsImages | |
* @property Customers[] $vbCustomers | |
* @property Categories[] $vbCategories | |
* @property ProductsVariants[] $productsVariants | |
* @property ProductsXsell[] $productsXsells | |
* @property Reviews[] $reviews | |
* @property Specials[] $specials | |
* @property VendorsProductsMap $vendorsProductsMap | |
* @property WishlistsProducts[] $wishlistsProducts | |
*/ | |
class Products extends CActiveRecord | |
{ | |
public $products_name; | |
/** | |
* Returns the static model of the specified AR class. | |
* @return Products the static model class | |
*/ | |
public static function model($className=__CLASS__) | |
{ | |
return parent::model($className); | |
} | |
/** | |
* @return string the associated database table name | |
*/ | |
public function tableName() | |
{ | |
return 'vb_products'; | |
} | |
/** | |
* @return array validation rules for model attributes. | |
*/ | |
public function rules() | |
{ | |
// NOTE: you should only define rules for those attributes that | |
// will receive user inputs. | |
return array( | |
array('products_price, products_sku, products_model, products_date_added, products_weight, products_weight_class, products_status, products_tax_class_id, quantity_unit_class', 'required'), | |
array('products_type, products_quantity, products_moq, products_max_order_quantity, products_weight_class, products_status, products_tax_class_id, manufacturers_id, products_ordered, quantity_discount_groups_id, quantity_unit_class, order_increment, products_attributes_groups_id', 'numerical', 'integerOnly'=>true), | |
array('products_price', 'length', 'max'=>15), | |
array('products_sku, products_model', 'length', 'max'=>64), | |
array('products_weight', 'length', 'max'=>5), | |
array('products_last_modified, products_date_available', 'safe'), | |
// The following rule is used by search(). | |
// Please remove those attributes that should not be searched. | |
array('products_id, products_type, products_quantity, products_moq, products_max_order_quantity, products_price, products_sku, products_model, products_date_added, products_last_modified, products_date_available, products_weight, products_weight_class, products_status, products_tax_class_id, manufacturers_id, products_ordered, quantity_discount_groups_id, quantity_unit_class, order_increment, products_attributes_groups_id', 'safe', 'on'=>'search'), | |
); | |
} | |
/** | |
* @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( | |
'QuantityDiscountGroups' => array(self::BELONGS_TO, 'QuantityDiscountGroups', 'quantity_discount_groups_id'), | |
'WeightClasses' => array(self::BELONGS_TO, 'WeightClasses', 'products_weight_class'), | |
'Manufacturers' => array(self::BELONGS_TO, 'Manufacturers', 'manufacturers_id'), | |
'TaxClass' => array(self::BELONGS_TO, 'TaxClass', 'products_tax_class_id'), | |
'productsTypes' => array(self::BELONGS_TO, 'ProductsTypes', 'products_type'), | |
'customizationFields' => array(self::HAS_MANY, 'CustomizationFields', 'products_id'), | |
'ordersProducts' => array(self::HAS_MANY, 'OrdersProducts', 'products_id'), | |
'productsTaxClass' => array(self::BELONGS_TO, 'TaxClass', 'products_tax_class_id'), | |
'manufacturers' => array(self::BELONGS_TO, 'Manufacturers', 'manufacturers_id'), | |
'quantityDiscountGroups' => array(self::BELONGS_TO, 'QuantityDiscountGroups', 'quantity_discount_groups_id'), | |
'productsAttributesGroups' => array(self::BELONGS_TO, 'ProductsAttributesGroups', 'products_attributes_groups_id'), | |
'productsAccessories' => array(self::HAS_MANY, 'ProductsAccessories', 'products_id'), | |
'vbProductsAttachments' => array(self::MANY_MANY, 'ProductsAttachments', 'vb_products_attachments_to_products(products_id, attachments_id)'), | |
'productsAttributes' => array(self::HAS_MANY, 'ProductsAttributes', 'products_id'), | |
'vbLanguages' => array(self::MANY_MANY, 'Languages', 'vb_products_description(products_id, language_id)'), | |
'productsDownloadables' => array(self::HAS_MANY, 'ProductsDownloadables', 'products_id'), | |
'productsFrontpage' => array(self::HAS_ONE, 'ProductsFrontpage', 'products_id'), | |
'productsGiftCertificates' => array(self::HAS_ONE, 'ProductsGiftCertificates', 'products_id'), | |
'productsImages' => array(self::HAS_MANY, 'ProductsImages', 'products_id'), | |
'vbCustomers' => array(self::MANY_MANY, 'Customers', 'vb_products_notifications(products_id, customers_id)'), | |
'vbCategories' => array(self::MANY_MANY, 'Categories', 'vb_products_to_categories(products_id, categories_id)'), | |
'productsVariants' => array(self::HAS_MANY, 'ProductsVariants', 'products_id'), | |
'productsXsells' => array(self::HAS_MANY, 'ProductsXsell', 'products_id'), | |
'reviews' => array(self::HAS_MANY, 'Reviews', 'products_id'), | |
'specials' => array(self::HAS_MANY, 'Specials', 'products_id'), | |
'vendorsProductsMap' => array(self::HAS_ONE, 'VendorsProductsMap', 'products_id'), | |
'wishlistsProducts' => array(self::HAS_MANY, 'WishlistsProducts', 'products_id'), | |
//'vbLanguages' => array(self::MANY_MANY, 'Languages', 'vb_Products_description(products_id, language_id)'), | |
); | |
} | |
/** | |
* @return array customized attribute labels (name=>label) | |
*/ | |
public function attributeLabels() | |
{ | |
return array( | |
'products_id' => 'Products', | |
'products_type' => 'Products Type', | |
'products_quantity' => 'Products Quantity', | |
'products_moq' => 'Products Moq', | |
'products_max_order_quantity' => 'Products Max Order Quantity', | |
'products_price' => 'Products Price', | |
'products_sku' => 'Products Sku', | |
'products_model' => 'Products Model', | |
'products_date_added' => 'Products Date Added', | |
'products_last_modified' => 'Products Last Modified', | |
'products_date_available' => 'Products Date Available', | |
'products_weight' => 'Products Weight', | |
'products_weight_class' => 'Products Weight Class', | |
'products_status' => 'Products Status', | |
'products_tax_class_id' => 'Products Tax Class', | |
'manufacturers_id' => 'Manufacturers', | |
'products_ordered' => 'Products Ordered', | |
'quantity_discount_groups_id' => 'Quantity Discount Groups', | |
'quantity_unit_class' => 'Quantity Unit Class', | |
'order_increment' => 'Order Increment', | |
'products_attributes_groups_id' => 'Products Attributes Groups', | |
); | |
} | |
/** | |
* Retrieves a list of models based on the current search/filter conditions. | |
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. | |
*/ | |
public function search() | |
{ | |
$this->products_name = $this->products_id; | |
// Warning: Please modify the following code to remove attributes that | |
// should not be searched. | |
$criteria=new CDbCriteria; | |
//Edited to enable Products Descriptions | |
$criteria->join="LEFT JOIN vb_products_description t1 ON t.products_id = t1.products_id"; | |
//$criteria->with = array('ProductsDescription'); | |
//$criteria->together = true; | |
//$criteria->compare('t1.products_name',$this->products_id,true); | |
$criteria->compare('t1.products_id',$this->products_id); | |
$criteria->compare('t1.products_name',$this->products_name,true); | |
//$criteria->compare('products_type',$this->products_type); | |
$criteria->compare('products_quantity',$this->products_quantity); | |
//$criteria->compare('products_moq',$this->products_moq); | |
$criteria->compare('products_max_order_quantity',$this->products_max_order_quantity); | |
$criteria->compare('products_price',$this->products_price,true); | |
$criteria->compare('products_sku',$this->products_sku,true); | |
//$criteria->compare('products_model',$this->products_model,true); | |
//$criteria->compare('products_date_added',$this->products_date_added,true); | |
//$criteria->compare('products_last_modified',$this->products_last_modified,true); | |
//$criteria->compare('products_date_available',$this->products_date_available,true); | |
$criteria->compare('products_weight',$this->products_weight,true); | |
//$criteria->compare('products_weight_class',$this->products_weight_class); | |
$criteria->compare('products_status',$this->products_status); | |
//$criteria->compare('products_tax_class_id',$this->products_tax_class_id); | |
//$criteria->compare('manufacturers_id',$this->manufacturers_id); | |
//$criteria->compare('products_ordered',$this->products_ordered); | |
//$criteria->compare('quantity_discount_groups_id',$this->quantity_discount_groups_id); | |
//$criteria->compare('quantity_unit_class',$this->quantity_unit_class); | |
//$criteria->compare('order_increment',$this->order_increment); | |
//$criteria->compare('products_attributes_groups_id',$this->products_attributes_groups_id); | |
return new CActiveDataProvider($this, array( | |
'criteria'=>$criteria, | |
)); | |
} | |
public function ReturnProductypeName($products_id,$prouct_type_id,$return=false) | |
{ | |
$foo = ProductsTypes::model()->findByAttributes(array('products_id'=>$products_id,'product_type_id'=>$product_type_id)); | |
if($return){ | |
return $foo->product_type_name; | |
}else{ | |
echo $foo->product_type_name; | |
} | |
} | |
public function beforeSave() | |
{ | |
if ($this->isNewRecord){ | |
$this->products_last_modified = new CDbExpression('NOW()'); | |
$this->products_last_modified = new CDbExpression('NOW()'); | |
return true; | |
}else{ | |
$this->products_last_modified; | |
return true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment