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: class Mage_Sales_Block_Recurring_Profiles extends Mage_Core_Block_Template
31: {
32: 33: 34: 35: 36:
37: protected $_profiles = null;
38:
39: 40: 41:
42: public function prepareProfilesGrid()
43: {
44: $this->_prepareProfiles(array('reference_id', 'state', 'created_at', 'updated_at', 'method_code'));
45:
46: $pager = $this->getLayout()->createBlock('page/html_pager')
47: ->setCollection($this->_profiles)->setIsOutputRequired(false);
48: $this->setChild('pager', $pager);
49:
50:
51: $profile = Mage::getModel('sales/recurring_profile');
52:
53: $this->setGridColumns(array(
54: new Varien_Object(array(
55: 'index' => 'reference_id',
56: 'title' => $profile->getFieldLabel('reference_id'),
57: 'is_nobr' => true,
58: 'width' => 1,
59: )),
60: new Varien_Object(array(
61: 'index' => 'state',
62: 'title' => $profile->getFieldLabel('state'),
63: )),
64: new Varien_Object(array(
65: 'index' => 'created_at',
66: 'title' => $profile->getFieldLabel('created_at'),
67: 'is_nobr' => true,
68: 'width' => 1,
69: 'is_amount' => true,
70: )),
71: new Varien_Object(array(
72: 'index' => 'updated_at',
73: 'title' => $profile->getFieldLabel('updated_at'),
74: 'is_nobr' => true,
75: 'width' => 1,
76: )),
77: new Varien_Object(array(
78: 'index' => 'method_code',
79: 'title' => $profile->getFieldLabel('method_code'),
80: 'is_nobr' => true,
81: 'width' => 1,
82: )),
83: ));
84:
85: $profiles = array();
86: $store = Mage::app()->getStore();
87: $locale = Mage::app()->getLocale();
88: foreach($this->_profiles as $profile) {
89: $profile->setStore($store)->setLocale($locale);
90: $profiles[] = new Varien_Object(array(
91: 'reference_id' => $profile->getReferenceId(),
92: 'reference_id_link_url' => $this->getUrl('sales/recurring_profile/view/', array('profile' => $profile->getId())),
93: 'state' => $profile->renderData('state'),
94: 'created_at' => $this->formatDate($profile->getData('created_at'), 'medium', true),
95: 'updated_at' => $profile->getData('updated_at') ? $this->formatDate($profile->getData('updated_at'), 'short', true) : '',
96: 'method_code' => $profile->renderData('method_code'),
97: ));
98: }
99: if ($profiles) {
100: $this->setGridElements($profiles);
101: }
102: $orders = array();
103: }
104:
105: 106: 107: 108: 109:
110: protected function _prepareProfiles($fields = '*')
111: {
112: $this->_profiles = Mage::getModel('sales/recurring_profile')->getCollection()
113: ->addFieldToFilter('customer_id', Mage::registry('current_customer')->getId())
114: ->addFieldToSelect($fields)
115: ->setOrder('profile_id', 'desc')
116: ;
117: }
118:
119: 120: 121: 122: 123:
124: protected function _beforeToHtml()
125: {
126: $this->setBackUrl($this->getUrl('customer/account/'));
127: return parent::_beforeToHtml();
128: }
129: }
130: