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_CatalogIndex_Model_Mysql4_Data_Grouped extends Mage_CatalogIndex_Model_Mysql4_Data_Abstract
00036 {
00037
00038
00039
00040
00041
00042
00043
00044
00045 public function getMinimalPrice($products, $priceAttributes, $store)
00046 {
00047 $result = array();
00048 $store = Mage::app()->getStore($store);
00049
00050 $select = $this->_getReadAdapter()->select()
00051 ->from($this->getTable('catalogindex/price'), array(
00052 'customer_group_id', 'value', 'tax_class_id'))
00053 ->where('entity_id IN(?)', $products)
00054 ->where('attribute_id IN(?)', $priceAttributes)
00055 ->where('website_id=?', $store->getWebsiteId());
00056 $prices = $select->query()->fetchAll();
00057
00058 $groups = Mage::getSingleton('catalogindex/retreiver')->getCustomerGroups();
00059 foreach ($groups as $group) {
00060 $resultMinimal = null;
00061 $resultTaxClassId = 0;
00062 $taxClassId = 0;
00063 $customerGroup = $group->getId();
00064
00065 $typedProducts = Mage::getSingleton('catalogindex/retreiver')
00066 ->assignProductTypes($products);
00067 foreach ($typedProducts as $type=>$typeIds) {
00068 $retreiver = Mage::getSingleton('catalogindex/retreiver')->getRetreiver($type);
00069 foreach ($typeIds as $id) {
00070 $finalPrice = $retreiver->getFinalPrice($id, $store, $group);
00071 if ((null === $resultMinimal) || ($finalPrice < $resultMinimal)) {
00072 $resultMinimal = $finalPrice;
00073 $resultTaxClassId = $retreiver->getTaxClassId($id, $store);
00074 }
00075
00076 $tiers = $retreiver->getTierPrices($id, $store);
00077 foreach ($tiers as $tier) {
00078 if ($tier['customer_group_id'] != $customerGroup && !$tier['all_groups']) {
00079 continue;
00080 }
00081 if ((null === $resultMinimal) || ($tier['value'] < $resultMinimal)) {
00082 $resultMinimal = $tier['value'];
00083 $resultTaxClassId = $retreiver->getTaxClassId($tier['entity_id'], $store);
00084 }
00085 }
00086 }
00087 }
00088
00089 foreach ($prices as $one) {
00090 if ($one['customer_group_id'] != $customerGroup) {
00091 continue;
00092 }
00093
00094 if ((null === $resultMinimal) || ($one['value'] < $resultMinimal)) {
00095 $resultMinimal = $one['value'];
00096 $taxClassId = $one['tax_class_id'];
00097 } else {
00098 $taxClassId = $resultTaxClassId;
00099 }
00100 }
00101
00102 if (!is_null($resultMinimal)){
00103 $result[] = array(
00104 'customer_group_id' => $customerGroup,
00105 'minimal_value' => $resultMinimal,
00106 'tax_class_id' => $taxClassId
00107 );
00108 }
00109 }
00110
00111 return $result;
00112 }
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 protected function _prepareLinkFetchSelect($store, $table, $idField, $whereField, $id, $additionalWheres = array())
00125 {
00126 $this->_addAttributeFilter($this->_getLinkSelect(), 'required_options', 'l', $idField, $store, 0);
00127 }
00128 }