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: * Total model for recurring profiles
29: */
30: abstract class Mage_Sales_Model_Quote_Address_Total_Nominal_RecurringAbstract
31: extends Mage_Sales_Model_Quote_Address_Total_Abstract
32: {
33: /**
34: * Don't add amounts to address
35: *
36: * @var bool
37: */
38: protected $_canAddAmountToAddress = false;
39:
40: /**
41: * By what key to set data into item
42: *
43: * @var string
44: */
45: protected $_itemRowTotalKey = null;
46:
47: /**
48: * By what key to get data from profile
49: *
50: * @var string
51: */
52: protected $_profileDataKey = null;
53:
54: /**
55: * Collect recurring item parameters and copy to the address items
56: *
57: * @param Mage_Sales_Model_Quote_Address $address
58: * @return Mage_Sales_Model_Quote_Address_Total_Nominal_RecurringAbstract
59: */
60: public function collect(Mage_Sales_Model_Quote_Address $address)
61: {
62: parent::collect($address);
63: $items = $this->_getAddressItems($address);
64: foreach ($items as $item) {
65: if ($item->getProduct()->isRecurring()) {
66: $profileData = $item->getProduct()->getRecurringProfile();
67: if (!empty($profileData[$this->_profileDataKey])) {
68: $item->setData(
69: $this->_itemRowTotalKey,
70: $address->getQuote()->getStore()->convertPrice($profileData[$this->_profileDataKey])
71: );
72: $this->_afterCollectSuccess($address, $item);
73: }
74: }
75: }
76: return $this;
77: }
78:
79: /**
80: * Don't fetch anything
81: *
82: * @param Mage_Sales_Model_Quote_Address $address
83: * @return array
84: */
85: public function fetch(Mage_Sales_Model_Quote_Address $address)
86: {
87: return Mage_Sales_Model_Quote_Address_Total_Abstract::fetch($address);
88: }
89:
90: /**
91: * Get nominal items only
92: *
93: * @param Mage_Sales_Model_Quote_Address $address
94: * @return array
95: */
96: protected function _getAddressItems(Mage_Sales_Model_Quote_Address $address)
97: {
98: return $address->getAllNominalItems();
99: }
100:
101: /**
102: * Hook for successful collecting of a recurring amount
103: *
104: * @param Mage_Sales_Model_Quote_Address $address
105: * @param Mage_Sales_Model_Quote_Item_Abstract $item
106: */
107: protected function _afterCollectSuccess($address, $item)
108: {
109: }
110: }
111: