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: class Mage_Catalog_Model_Product_Type_Configurable_Price extends Mage_Catalog_Model_Product_Type_Price
35: {
36: 37: 38: 39: 40: 41: 42:
43: public function getFinalPrice($qty=null, $product)
44: {
45: if (is_null($qty) && !is_null($product->getCalculatedFinalPrice())) {
46: return $product->getCalculatedFinalPrice();
47: }
48:
49: $basePrice = $this->getBasePrice($product, $qty);
50: $finalPrice = $basePrice;
51: $product->setFinalPrice($finalPrice);
52: Mage::dispatchEvent('catalog_product_get_final_price', array('product' => $product, 'qty' => $qty));
53: $finalPrice = $product->getData('final_price');
54:
55: $finalPrice += $this->getTotalConfigurableItemsPrice($product, $finalPrice);
56: $finalPrice += $this->_applyOptionsPrice($product, $qty, $basePrice) - $basePrice;
57: $finalPrice = max(0, $finalPrice);
58:
59: $product->setFinalPrice($finalPrice);
60: return $finalPrice;
61: }
62:
63: 64: 65: 66: 67: 68: 69:
70: public function getTotalConfigurableItemsPrice($product, $finalPrice)
71: {
72: $price = 0.0;
73:
74: $product->getTypeInstance(true)
75: ->setStoreFilter($product->getStore(), $product);
76: $attributes = $product->getTypeInstance(true)
77: ->getConfigurableAttributes($product);
78:
79: $selectedAttributes = array();
80: if ($product->getCustomOption('attributes')) {
81: $selectedAttributes = unserialize($product->getCustomOption('attributes')->getValue());
82: }
83:
84: foreach ($attributes as $attribute) {
85: $attributeId = $attribute->getProductAttribute()->getId();
86: $value = $this->_getValueByIndex(
87: $attribute->getPrices() ? $attribute->getPrices() : array(),
88: isset($selectedAttributes[$attributeId]) ? $selectedAttributes[$attributeId] : null
89: );
90: $product->setParentId(true);
91: if ($value) {
92: if ($value['pricing_value'] != 0) {
93: $product->setConfigurablePrice($this->_calcSelectionPrice($value, $finalPrice));
94: Mage::dispatchEvent(
95: 'catalog_product_type_configurable_price',
96: array('product' => $product)
97: );
98: $price += $product->getConfigurablePrice();
99: }
100: }
101: }
102: return $price;
103: }
104:
105: 106: 107: 108: 109: 110: 111:
112: protected function _calcSelectionPrice($priceInfo, $productPrice)
113: {
114: if($priceInfo['is_percent']) {
115: $ratio = $priceInfo['pricing_value']/100;
116: $price = $productPrice * $ratio;
117: } else {
118: $price = $priceInfo['pricing_value'];
119: }
120: return $price;
121: }
122:
123: protected function _getValueByIndex($values, $index) {
124: foreach ($values as $value) {
125: if($value['value_index'] == $index) {
126: return $value;
127: }
128: }
129: return false;
130: }
131: }
132: