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_Bundle_Model_Mysql4_Option_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
00035 {
00036 protected $_selectionsAppended = false;
00037 protected function _construct()
00038 {
00039 $this->_init('bundle/option');
00040 }
00041
00042 public function joinValues($storeId)
00043 {
00044 $this->getSelect()->joinLeft(array('option_value_default' => $this->getTable('bundle/option_value')),
00045 '`main_table`.`option_id` = `option_value_default`.`option_id` and `option_value_default`.`store_id` = "0"',
00046 array())
00047 ->from('', array('default_title' => 'option_value_default.title'));
00048
00049 if ($storeId !== null) {
00050 $this->getSelect()
00051 ->from('', array('title' => 'IFNULL(`option_value`.`title`, `option_value_default`.`title`)'))
00052 ->joinLeft(array('option_value' => $this->getTable('bundle/option_value')),
00053 '`main_table`.`option_id` = `option_value`.`option_id` and `option_value`.`store_id` = "' . $storeId . '"',
00054 array());
00055 }
00056 return $this;
00057 }
00058
00059 public function setProductIdFilter($productId)
00060 {
00061 $this->addFieldToFilter('`main_table`.`parent_id`', $productId);
00062 return $this;
00063 }
00064
00065 public function setPositionOrder()
00066 {
00067 $this->getSelect()->order('main_table.position asc')
00068 ->order('main_table.option_id asc');
00069 return $this;
00070 }
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 public function appendSelections($selectionsCollection, $stripBefore = false, $appendAll = true)
00083 {
00084 if ($stripBefore) {
00085 $this->_stripSelections();
00086 }
00087
00088 if (!$this->_selectionsAppended) {
00089 foreach ($selectionsCollection->getItems() as $key=>$_selection) {
00090 if ($_option = $this->getItemById($_selection->getOptionId())) {
00091 if ((!$appendAll && $_selection->isSalable() && !$_selection->getRequiredOptions()) || $appendAll) {
00092 $_selection->setOption($_option);
00093 $_option->addSelection($_selection);
00094 } else {
00095 $selectionsCollection->removeItemByKey($key);
00096 }
00097 }
00098 }
00099 $this->_selectionsAppended = true;
00100 }
00101 return $this->getItems();
00102 }
00103
00104
00105
00106
00107
00108
00109 protected function _stripSelections()
00110 {
00111 foreach ($this->getItems() as $option) {
00112 $option->setSelections(array());
00113 }
00114 $this->_selectionsAppended = false;
00115 return $this;
00116 }
00117
00118
00119 public function setIdFilter($ids)
00120 {
00121 if (is_array($ids)) {
00122 $this->addFieldToFilter('`main_table`.`option_id`', array('in' => $ids));
00123 } else if ($ids != '') {
00124 $this->addFieldToFilter('`main_table`.`option_id`', $ids);
00125 }
00126 return $this;
00127 }
00128
00129 }