1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Sales
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Nominal items total
29: * Collects only items segregated by isNominal property
30: * Aggregates row totals per item
31: */
32: class Mage_Sales_Model_Quote_Address_Total_Nominal extends Mage_Sales_Model_Quote_Address_Total_Abstract
33: {
34: /**
35: * Invoke collector for nominal items
36: *
37: * @param Mage_Sales_Model_Quote_Address $address
38: * @param Mage_Sales_Model_Quote_Address_Total_Nominal
39: */
40: public function collect(Mage_Sales_Model_Quote_Address $address)
41: {
42: $collector = Mage::getSingleton('sales/quote_address_total_nominal_collector',
43: array('store' => $address->getQuote()->getStore())
44: );
45:
46: // invoke nominal totals
47: foreach ($collector->getCollectors() as $model) {
48: $model->collect($address);
49: }
50:
51: // aggregate collected amounts into one to have sort of grand total per item
52: foreach ($address->getAllNominalItems() as $item) {
53: $rowTotal = 0; $baseRowTotal = 0;
54: $totalDetails = array();
55: foreach ($collector->getCollectors() as $model) {
56: $itemRowTotal = $model->getItemRowTotal($item);
57: if ($model->getIsItemRowTotalCompoundable($item)) {
58: $rowTotal += $itemRowTotal;
59: $baseRowTotal += $model->getItemBaseRowTotal($item);
60: $isCompounded = true;
61: } else {
62: $isCompounded = false;
63: }
64: if ((float)$itemRowTotal > 0 && $label = $model->getLabel()) {
65: $totalDetails[] = new Varien_Object(array(
66: 'label' => $label,
67: 'amount' => $itemRowTotal,
68: 'is_compounded' => $isCompounded,
69: ));
70: }
71: }
72: $item->setNominalRowTotal($rowTotal);
73: $item->setBaseNominalRowTotal($baseRowTotal);
74: $item->setNominalTotalDetails($totalDetails);
75: }
76:
77: return $this;
78: }
79:
80: /**
81: * Fetch collected nominal items
82: *
83: * @param Mage_Sales_Model_Quote_Address $address
84: * @return Mage_Sales_Model_Quote_Address_Total_Nominal
85: */
86: public function fetch(Mage_Sales_Model_Quote_Address $address)
87: {
88: $items = $address->getAllNominalItems();
89: if ($items) {
90: $address->addTotal(array(
91: 'code' => $this->getCode(),
92: 'title' => Mage::helper('sales')->__('Nominal Items'),
93: 'items' => $items,
94: 'area' => 'footer',
95: ));
96: }
97: return $this;
98: }
99: }
100: