00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Catalog_Model_Product_Visibility extends Varien_Object
00036 {
00037 const VISIBILITY_NOT_VISIBLE = 1;
00038 const VISIBILITY_IN_CATALOG = 2;
00039 const VISIBILITY_IN_SEARCH = 3;
00040 const VISIBILITY_BOTH = 4;
00041
00042
00043
00044
00045
00046
00047 protected $_attribute;
00048
00049
00050
00051
00052
00053 public function __construct()
00054 {
00055 parent::__construct();
00056 $this->setIdFieldName('visibility_id');
00057 }
00058
00059
00060
00061
00062
00063
00064
00065
00066 public function addVisibleInCatalogFilterToCollection(Mage_Eav_Model_Entity_Collection_Abstract $collection)
00067 {
00068 $collection->setVisibility($this->getVisibleInCatalogIds());
00069
00070 return $this;
00071 }
00072
00073
00074
00075
00076
00077
00078
00079
00080 public function addVisibleInSearchFilterToCollection(Mage_Eav_Model_Entity_Collection_Abstract $collection)
00081 {
00082 $collection->setVisibility($this->getVisibleInSearchIds());
00083
00084 return $this;
00085 }
00086
00087
00088
00089
00090
00091
00092
00093
00094 public function addVisibleInSiteFilterToCollection(Mage_Eav_Model_Entity_Collection_Abstract $collection)
00095 {
00096 $collection->setVisibility($this->getVisibleInSiteIds());
00097
00098 return $this;
00099 }
00100
00101
00102
00103
00104
00105
00106 public function getVisibleInCatalogIds()
00107 {
00108 return array(self::VISIBILITY_IN_CATALOG, self::VISIBILITY_BOTH);
00109 }
00110
00111
00112
00113
00114
00115
00116 public function getVisibleInSearchIds()
00117 {
00118 return array(self::VISIBILITY_IN_SEARCH, self::VISIBILITY_BOTH);
00119 }
00120
00121
00122
00123
00124
00125
00126 public function getVisibleInSiteIds()
00127 {
00128 return array(self::VISIBILITY_IN_SEARCH, self::VISIBILITY_IN_CATALOG, self::VISIBILITY_BOTH);
00129 }
00130
00131
00132
00133
00134
00135
00136 static public function getOptionArray()
00137 {
00138 return array(
00139 self::VISIBILITY_NOT_VISIBLE=> Mage::helper('catalog')->__('Nowhere'),
00140 self::VISIBILITY_IN_CATALOG => Mage::helper('catalog')->__('Catalog'),
00141 self::VISIBILITY_IN_SEARCH => Mage::helper('catalog')->__('Search'),
00142 self::VISIBILITY_BOTH => Mage::helper('catalog')->__('Catalog, Search')
00143 );
00144 }
00145
00146
00147
00148
00149
00150
00151 static public function getAllOption()
00152 {
00153 $options = self::getOptionArray();
00154 array_unshift($options, array('value'=>'', 'label'=>''));
00155 return $options;
00156 }
00157
00158
00159
00160
00161
00162
00163 static public function getAllOptions()
00164 {
00165 $res = array();
00166 $res[] = array('value'=>'', 'label'=> Mage::helper('catalog')->__('-- Please Select --'));
00167 foreach (self::getOptionArray() as $index => $value) {
00168 $res[] = array(
00169 'value' => $index,
00170 'label' => $value
00171 );
00172 }
00173 return $res;
00174 }
00175
00176
00177
00178
00179
00180
00181
00182 static public function getOptionText($optionId)
00183 {
00184 $options = self::getOptionArray();
00185 return isset($options[$optionId]) ? $options[$optionId] : null;
00186 }
00187
00188
00189
00190
00191
00192
00193 public function getFlatColums()
00194 {
00195 return array();
00196 }
00197
00198
00199
00200
00201
00202
00203 public function getFlatIndexes()
00204 {
00205 return array();
00206 }
00207
00208
00209
00210
00211
00212
00213
00214
00215 public function getFlatUpdateSelect($store)
00216 {
00217 return null;
00218 }
00219
00220
00221
00222
00223
00224
00225
00226 public function setAttribute($attribute)
00227 {
00228 $this->_attribute = $attribute;
00229 return $this;
00230 }
00231
00232
00233
00234
00235
00236
00237 public function getAttribute()
00238 {
00239 return $this->_attribute;
00240 }
00241
00242
00243
00244
00245
00246
00247
00248
00249 public function addValueSortToCollection($collection, $dir = 'asc')
00250 {
00251 if ($this->getAttribute()->isScopeGlobal()) {
00252 $tableName = $this->getAttribute()->getAttributeCode() . '_t';
00253 $collection->getSelect()
00254 ->joinLeft(
00255 array($tableName => $this->getAttribute()->getBackend()->getTable()),
00256 "`e`.`entity_id`=`{$tableName}`.`entity_id`"
00257 . " AND `{$tableName}`.`attribute_id`='{$this->getAttribute()->getId()}'"
00258 . " AND `{$tableName}`.`store_id`='0'",
00259 array());
00260 $valueExpr = $tableName . '.value';
00261 }
00262 else {
00263 $valueTable1 = $this->getAttribute()->getAttributeCode() . '_t1';
00264 $valueTable2 = $this->getAttribute()->getAttributeCode() . '_t2';
00265 $collection->getSelect()
00266 ->joinLeft(
00267 array($valueTable1 => $this->getAttribute()->getBackend()->getTable()),
00268 "`e`.`entity_id`=`{$valueTable1}`.`entity_id`"
00269 . " AND `{$valueTable1}`.`attribute_id`='{$this->getAttribute()->getId()}'"
00270 . " AND `{$valueTable1}`.`store_id`='0'",
00271 array())
00272 ->joinLeft(
00273 array($valueTable2 => $this->getAttribute()->getBackend()->getTable()),
00274 "`e`.`entity_id`=`{$valueTable2}`.`entity_id`"
00275 . " AND `{$valueTable2}`.`attribute_id`='{$this->getAttribute()->getId()}'"
00276 . " AND `{$valueTable2}`.`store_id`='{$collection->getStoreId()}'",
00277 array()
00278 );
00279 $valueExpr = new Zend_Db_Expr("IFNULL(`{$valueTable2}`.`value`, `{$valueTable1}`.`value`)");
00280 }
00281
00282 $collection->getSelect()->order($valueExpr . ' ' . $dir);
00283 return $this;
00284 }
00285 }