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: class Mage_Sales_Model_Quote_Address_Total_Subtotal extends Mage_Sales_Model_Quote_Address_Total_Abstract
29: {
30: 31: 32: 33: 34: 35:
36: public function collect(Mage_Sales_Model_Quote_Address $address)
37: {
38: parent::collect($address);
39: $address->setTotalQty(0);
40:
41: $baseVirtualAmount = $virtualAmount = 0;
42:
43: 44: 45:
46: $items = $this->_getAddressItems($address);
47: foreach ($items as $item) {
48: if ($this->_initItem($address, $item) && $item->getQty() > 0) {
49: 50: 51:
52: if ($item->getProduct()->isVirtual()) {
53: $virtualAmount += $item->getRowTotal();
54: $baseVirtualAmount += $item->getBaseRowTotal();
55: }
56: }
57: else {
58: $this->_removeItem($address, $item);
59: }
60: }
61:
62: $address->setBaseVirtualAmount($baseVirtualAmount);
63: $address->setVirtualAmount($virtualAmount);
64:
65: 66: 67:
68: Mage::helper('sales')->checkQuoteAmount($address->getQuote(), $address->getSubtotal());
69: Mage::helper('sales')->checkQuoteAmount($address->getQuote(), $address->getBaseSubtotal());
70: return $this;
71: }
72:
73: 74: 75: 76: 77: 78:
79: protected function _initItem($address, $item)
80: {
81: if ($item instanceof Mage_Sales_Model_Quote_Address_Item) {
82: $quoteItem = $item->getAddress()->getQuote()->getItemById($item->getQuoteItemId());
83: }
84: else {
85: $quoteItem = $item;
86: }
87: $product = $quoteItem->getProduct();
88: $product->setCustomerGroupId($quoteItem->getQuote()->getCustomerGroupId());
89:
90: 91: 92:
93: if ($item->getQuote()->getIsSuperMode()) {
94: if (!$product) {
95: return false;
96: }
97: }
98: else {
99: if (!$product || !$product->isVisibleInCatalog()) {
100: return false;
101: }
102: }
103:
104: if ($quoteItem->getParentItem() && $quoteItem->isChildrenCalculated()) {
105: $finalPrice = $quoteItem->getParentItem()->getProduct()->getPriceModel()->getChildFinalPrice(
106: $quoteItem->getParentItem()->getProduct(),
107: $quoteItem->getParentItem()->getQty(),
108: $quoteItem->getProduct(),
109: $quoteItem->getQty()
110: );
111: $item->setPrice($finalPrice)
112: ->setBaseOriginalPrice($finalPrice);
113: $item->calcRowTotal();
114: } else if (!$quoteItem->getParentItem()) {
115: $finalPrice = $product->getFinalPrice($quoteItem->getQty());
116: $item->setPrice($finalPrice)
117: ->setBaseOriginalPrice($finalPrice);
118: $item->calcRowTotal();
119: $this->_addAmount($item->getRowTotal());
120: $this->_addBaseAmount($item->getBaseRowTotal());
121: $address->setTotalQty($address->getTotalQty() + $item->getQty());
122: }
123:
124: return true;
125: }
126:
127: 128: 129: 130: 131: 132: 133:
134: protected function _removeItem($address, $item)
135: {
136: if ($item instanceof Mage_Sales_Model_Quote_Item) {
137: $address->removeItem($item->getId());
138: if ($address->getQuote()) {
139: $address->getQuote()->removeItem($item->getId());
140: }
141: }
142: elseif ($item instanceof Mage_Sales_Model_Quote_Address_Item) {
143: $address->removeItem($item->getId());
144: if ($address->getQuote()) {
145: $address->getQuote()->removeItem($item->getQuoteItemId());
146: }
147: }
148:
149: return $this;
150: }
151:
152: 153: 154: 155: 156: 157:
158: public function fetch(Mage_Sales_Model_Quote_Address $address)
159: {
160: $address->addTotal(array(
161: 'code' => $this->getCode(),
162: 'title' => Mage::helper('sales')->__('Subtotal'),
163: 'value' => $address->getSubtotal()
164: ));
165: return $this;
166: }
167:
168: 169: 170: 171: 172:
173: public function getLabel()
174: {
175: return Mage::helper('sales')->__('Subtotal');
176: }
177: }
178: