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 class Mage_Catalog_Model_Product_Type
00035 {
00036
00037
00038
00039 const TYPE_SIMPLE = 'simple';
00040 const TYPE_BUNDLE = 'bundle';
00041 const TYPE_CONFIGURABLE = 'configurable';
00042 const TYPE_GROUPED = 'grouped';
00043 const TYPE_VIRTUAL = 'virtual';
00044
00045 const DEFAULT_TYPE = 'simple';
00046 const DEFAULT_TYPE_MODEL = 'catalog/product_type_simple';
00047 const DEFAULT_PRICE_MODEL = 'catalog/product_type_price';
00048
00049 static protected $_types;
00050 static protected $_compositeTypes;
00051 static protected $_priceModels;
00052
00053
00054
00055
00056
00057
00058
00059
00060 public static function factory($product, $singleton = false)
00061 {
00062 $types = self::getTypes();
00063
00064 if (!empty($types[$product->getTypeId()]['model'])) {
00065 $typeModelName = $types[$product->getTypeId()]['model'];
00066 } else {
00067 $typeModelName = self::DEFAULT_TYPE_MODEL;
00068 }
00069
00070 if ($singleton === true) {
00071 $typeModel = Mage::getSingleton($typeModelName);
00072 }
00073 else {
00074 $typeModel = Mage::getModel($typeModelName);
00075 $typeModel->setProduct($product);
00076 }
00077 $typeModel->setConfig($types[$product->getTypeId()]);
00078 return $typeModel;
00079 }
00080
00081
00082
00083
00084
00085
00086
00087 public static function priceFactory($productType)
00088 {
00089 if (isset(self::$_priceModels[$productType])) {
00090 return self::$_priceModels[$productType];
00091 }
00092
00093 $types = self::getTypes();
00094
00095 if (!empty($types[$productType]['price_model'])) {
00096 $priceModelName = $types[$productType]['price_model'];
00097 } else {
00098 $priceModelName = self::DEFAULT_PRICE_MODEL;
00099 }
00100
00101 self::$_priceModels[$productType] = Mage::getModel($priceModelName);
00102 return self::$_priceModels[$productType];
00103 }
00104
00105 static public function getOptionArray()
00106 {
00107 $options = array();
00108 foreach(self::getTypes() as $typeId=>$type) {
00109 $options[$typeId] = $type['label'];
00110 }
00111
00112 return $options;
00113 }
00114
00115 static public function getAllOption()
00116 {
00117 $options = self::getOptionArray();
00118 array_unshift($options, array('value'=>'', 'label'=>''));
00119 return $options;
00120 }
00121
00122 static public function getAllOptions()
00123 {
00124 $res = array();
00125 $res[] = array('value'=>'', 'label'=>'');
00126 foreach (self::getOptionArray() as $index => $value) {
00127 $res[] = array(
00128 'value' => $index,
00129 'label' => $value
00130 );
00131 }
00132 return $res;
00133 }
00134
00135 static public function getOptions()
00136 {
00137 $res = array();
00138 foreach (self::getOptionArray() as $index => $value) {
00139 $res[] = array(
00140 'value' => $index,
00141 'label' => $value
00142 );
00143 }
00144 return $res;
00145 }
00146
00147 static public function getOptionText($optionId)
00148 {
00149 $options = self::getOptionArray();
00150 return isset($options[$optionId]) ? $options[$optionId] : null;
00151 }
00152
00153 static public function getTypes()
00154 {
00155 if (is_null(self::$_types)) {
00156 self::$_types = Mage::getConfig()->getNode('global/catalog/product/type')->asArray();
00157 }
00158
00159 return self::$_types;
00160 }
00161
00162
00163
00164
00165
00166
00167 static public function getCompositeTypes()
00168 {
00169 if (is_null(self::$_compositeTypes)) {
00170 self::$_compositeTypes = array();
00171 $types = self::getTypes();
00172 foreach ($types as $typeId=>$typeInfo) {
00173 if (array_key_exists('composite', $typeInfo) && $typeInfo['composite']) {
00174 self::$_compositeTypes[] = $typeId;
00175 }
00176 }
00177 }
00178 return self::$_compositeTypes;
00179 }
00180 }