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_Resource_Eav_Mysql4_Product_Option_Value_Collection
00036 extends Mage_Core_Model_Mysql4_Collection_Abstract
00037 {
00038 protected function _construct()
00039 {
00040 $this->_init('catalog/product_option_value');
00041 }
00042
00043 public function getValues($store_id)
00044 {
00045 $this->getSelect()
00046 ->joinLeft(array('default_value_price'=>$this->getTable('catalog/product_option_type_price')),
00047 '`default_value_price`.option_type_id=`main_table`.option_type_id AND '.$this->getConnection()->quoteInto('`default_value_price`.store_id=?',0),
00048 array('default_price'=>'price','default_price_type'=>'price_type'))
00049 ->joinLeft(array('store_value_price'=>$this->getTable('catalog/product_option_type_price')),
00050 '`store_value_price`.option_type_id=`main_table`.option_type_id AND '.$this->getConnection()->quoteInto('`store_value_price`.store_id=?', $store_id),
00051 array('store_price'=>'price','store_price_type'=>'price_type',
00052 'price'=>new Zend_Db_Expr('IFNULL(`store_value_price`.price,`default_value_price`.price)'),
00053 'price_type'=>new Zend_Db_Expr('IFNULL(`store_value_price`.price_type,`default_value_price`.price_type)')))
00054 ->join(array('default_value_title'=>$this->getTable('catalog/product_option_type_title')),
00055 '`default_value_title`.option_type_id=`main_table`.option_type_id',
00056 array('default_title'=>'title'))
00057 ->joinLeft(array('store_value_title'=>$this->getTable('catalog/product_option_type_title')),
00058 '`store_value_title`.option_type_id=`main_table`.option_type_id AND '.$this->getConnection()->quoteInto('`store_value_title`.store_id=?',$store_id),
00059 array('store_title'=>'title','title'=>new Zend_Db_Expr('IFNULL(`store_value_title`.title,`default_value_title`.title)')))
00060 ->where('`default_value_title`.store_id=?',0);
00061 return $this;
00062 }
00063
00064 public function addTitlesToResult($store_id)
00065 {
00066 $this->getSelect()
00067 ->joinLeft(array('default_value_price'=>$this->getTable('catalog/product_option_type_price')),
00068 '`default_value_price`.option_type_id=`main_table`.option_type_id AND '.$this->getConnection()->quoteInto('`default_value_price`.store_id=?',0),
00069 array('default_price'=>'price','default_price_type'=>'price_type'))
00070 ->joinLeft(array('store_value_price'=>$this->getTable('catalog/product_option_type_price')),
00071 '`store_value_price`.option_type_id=`main_table`.option_type_id AND '.$this->getConnection()->quoteInto('`store_value_price`.store_id=?', $store_id),
00072 array('store_price'=>'price','store_price_type'=>'price_type',
00073 'price'=>new Zend_Db_Expr('IFNULL(`store_value_price`.price,`default_value_price`.price)'),
00074 'price_type'=>new Zend_Db_Expr('IFNULL(`store_value_price`.price_type,`default_value_price`.price_type)')))
00075 ->join(array('default_value_title'=>$this->getTable('catalog/product_option_type_title')),
00076 '`default_value_title`.option_type_id=`main_table`.option_type_id',
00077 array('default_title'=>'title'))
00078 ->joinLeft(array('store_value_title'=>$this->getTable('catalog/product_option_type_title')),
00079 '`store_value_title`.option_type_id=`main_table`.option_type_id AND '.$this->getConnection()->quoteInto('`store_value_title`.store_id=?',$store_id),
00080 array('store_title'=>'title','title'=>new Zend_Db_Expr('IFNULL(`store_value_title`.title,`default_value_title`.title)')))
00081 ->where('`default_value_title`.store_id=?',0);
00082
00083 return $this;
00084 }
00085
00086 public function addTitleToResult($store_id)
00087 {
00088 $this->getSelect()
00089 ->join(array('default_value_title'=>$this->getTable('catalog/product_option_type_title')),
00090 '`default_value_title`.option_type_id=`main_table`.option_type_id',
00091 array('default_title'=>'title'))
00092 ->joinLeft(array('store_value_title'=>$this->getTable('catalog/product_option_type_title')),
00093 '`store_value_title`.option_type_id=`main_table`.option_type_id AND '.$this->getConnection()->quoteInto('`store_value_title`.store_id=?',$store_id),
00094 array('store_title'=>'title','title'=>new Zend_Db_Expr('IFNULL(`store_value_title`.title,`default_value_title`.title)')))
00095 ->where('`default_value_title`.store_id=?',0);
00096
00097 return $this;
00098 }
00099
00100 public function addPriceToResult($store_id)
00101 {
00102 $this->getSelect()
00103 ->joinLeft(array('default_value_price'=>$this->getTable('catalog/product_option_type_price')),
00104 '`default_value_price`.option_type_id=`main_table`.option_type_id AND '.$this->getConnection()->quoteInto('`default_value_price`.store_id=?',0),
00105 array('default_price'=>'price','default_price_type'=>'price_type'))
00106 ->joinLeft(array('store_value_price'=>$this->getTable('catalog/product_option_type_price')),
00107 '`store_value_price`.option_type_id=`main_table`.option_type_id AND '.$this->getConnection()->quoteInto('`store_value_price`.store_id=?', $store_id),
00108 array('store_price'=>'price','store_price_type'=>'price_type',
00109 'price'=>new Zend_Db_Expr('IFNULL(`store_value_price`.price,`default_value_price`.price)'),
00110 'price_type'=>new Zend_Db_Expr('IFNULL(`store_value_price`.price_type,`default_value_price`.price_type)')));
00111
00112 return $this;
00113 }
00114
00115 public function getValuesByOption($optionIds, $store_id)
00116 {
00117 if (!is_array($optionIds)) {
00118 $optionIds = array($optionIds);
00119 }
00120
00121 $this->getSelect()
00122 ->where('`main_table`.option_type_id IN (?)', $optionIds);
00123
00124 return $this;
00125 }
00126
00127 public function addOptionToFilter($option)
00128 {
00129 if (empty($option)) {
00130 $this->addFieldToFilter('option_id', '');
00131 } elseif (is_array($option)) {
00132 $this->addFieldToFilter('option_id', array('in' => $option));
00133 } elseif ($option instanceof Mage_Catalog_Model_Product_Option) {
00134 $this->addFieldToFilter('option_id', $option->getId());
00135 } else {
00136 $this->addFieldToFilter('option_id', $option);
00137 }
00138
00139 return $this;
00140 }
00141 }