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_Bundle_Model_Mysql4_Bundle extends Mage_CatalogIndex_Model_Mysql4_Data_Abstract
00036 {
00037
00038
00039
00040
00041
00042
00043
00044
00045 protected function _getSelect($productId, $columns = array())
00046 {
00047 return $this->_getReadAdapter()->select()
00048 ->from(array("bundle_option" => $this->getTable('bundle/option')), array("type", "option_id"))
00049 ->where("bundle_option.parent_id = ?", $productId)
00050 ->where("bundle_option.required = 1")
00051 ->joinLeft(array(
00052 "bundle_selection" => $this->getTable('bundle/selection')),
00053 "bundle_selection.option_id = bundle_option.option_id", $columns);
00054 }
00055
00056
00057
00058
00059
00060
00061
00062 public function getSelectionsData($productId)
00063 {
00064 return $this->_getReadAdapter()->fetchAll($this->_getSelect(
00065 $productId,
00066 array("*")
00067 ));
00068 }
00069
00070
00071
00072
00073
00074
00075 public function dropAllQuoteChildItems($productId)
00076 {
00077 $result = $this->_getReadAdapter()->fetchRow(
00078 $this->_getReadAdapter()->select()
00079 ->from($this->getTable('sales/quote_item'), "GROUP_CONCAT(`item_id`) as items")
00080 ->where("product_id = ?", $productId));
00081
00082 if ($result['items'] != '') {
00083 $this->_getWriteAdapter()
00084 ->query("DELETE FROM ".$this->getTable('sales/quote_item')."
00085 WHERE `parent_item_id` in (". $result['items'] .")");
00086 }
00087 }
00088
00089
00090
00091
00092
00093
00094
00095 public function dropAllUnneededSelections($productId, $ids)
00096 {
00097 $this->_getWriteAdapter()
00098 ->query("DELETE FROM ".$this->getTable('bundle/selection')."
00099 WHERE `parent_product_id` = ". $productId . ( count($ids) > 0 ? " and selection_id not in (" . implode(',', $ids) . ")": ''));
00100 }
00101 }