1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27:
28: 29: 30: 31: 32: 33: 34:
35: class Mage_CatalogIndex_Model_Resource_Data_Grouped extends Mage_CatalogIndex_Model_Resource_Data_Abstract
36: {
37: 38: 39: 40: 41: 42: 43: 44:
45: public function getMinimalPrice($products, $priceAttributes, $store)
46: {
47: $result = array();
48: $store = Mage::app()->getStore($store);
49:
50: $select = $this->_getReadAdapter()->select()
51: ->from($this->getTable('catalogindex/price'), array(
52: 'customer_group_id', 'value', 'tax_class_id'))
53: ->where('entity_id IN(?)', $products)
54: ->where('attribute_id IN(?)', $priceAttributes)
55: ->where('website_id=?', $store->getWebsiteId());
56: $prices = $select->query()->fetchAll();
57:
58: $groups = Mage::getSingleton('catalogindex/retreiver')->getCustomerGroups();
59: foreach ($groups as $group) {
60: $resultMinimal = null;
61: $resultTaxClassId = 0;
62: $taxClassId = 0;
63: $customerGroup = $group->getId();
64:
65: $typedProducts = Mage::getSingleton('catalogindex/retreiver')
66: ->assignProductTypes($products);
67: foreach ($typedProducts as $type=>$typeIds) {
68: $retreiver = Mage::getSingleton('catalogindex/retreiver')->getRetreiver($type);
69: foreach ($typeIds as $id) {
70: $finalPrice = $retreiver->getFinalPrice($id, $store, $group);
71: if ((null === $resultMinimal) || ($finalPrice < $resultMinimal)) {
72: $resultMinimal = $finalPrice;
73: $resultTaxClassId = $retreiver->getTaxClassId($id, $store);
74: }
75:
76: $tiers = $retreiver->getTierPrices($id, $store);
77: foreach ($tiers as $tier) {
78: if ($tier['customer_group_id'] != $customerGroup && !$tier['all_groups']) {
79: continue;
80: }
81: if ((null === $resultMinimal) || ($tier['value'] < $resultMinimal)) {
82: $resultMinimal = $tier['value'];
83: $resultTaxClassId = $retreiver->getTaxClassId($tier['entity_id'], $store);
84: }
85: }
86: }
87: }
88:
89: foreach ($prices as $one) {
90: if ($one['customer_group_id'] != $customerGroup) {
91: continue;
92: }
93:
94: if ((null === $resultMinimal) || ($one['value'] < $resultMinimal)) {
95: $resultMinimal = $one['value'];
96: $taxClassId = $one['tax_class_id'];
97: } else {
98: $taxClassId = $resultTaxClassId;
99: }
100: }
101:
102: if (!is_null($resultMinimal)){
103: $result[] = array(
104: 'customer_group_id' => $customerGroup,
105: 'minimal_value' => $resultMinimal,
106: 'tax_class_id' => $taxClassId
107: );
108: }
109: }
110:
111: return $result;
112: }
113:
114: 115: 116: 117: 118: 119: 120: 121: 122: 123:
124: protected function _prepareLinkFetchSelect($store, $table, $idField, $whereField, $id, $additionalWheres = array())
125: {
126: $this->_addAttributeFilter($this->_getLinkSelect(), 'required_options', 'l', $idField, $store, 0);
127: }
128: }
129: