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_Checkout_Block_Onepage_Success extends Mage_Core_Block_Template
35: {
36: 37: 38:
39: private $_order;
40:
41: 42: 43: 44: 45: 46:
47: public function getOrderId()
48: {
49: return $this->_getData('order_id');
50: }
51:
52: 53: 54: 55: 56: 57:
58: public function canPrint()
59: {
60: return $this->_getData('can_view_order');
61: }
62:
63: 64: 65: 66: 67: 68:
69: public function getPrintUrl()
70: {
71: return $this->_getData('print_url');
72: }
73:
74: 75: 76: 77: 78: 79:
80: public function getViewOrderUrl()
81: {
82: return $this->_getData('view_order_id');
83: }
84:
85: 86: 87: 88: 89:
90: public function isOrderVisible()
91: {
92: return (bool)$this->_getData('is_order_visible');
93: }
94:
95: 96: 97: 98: 99:
100: public function getProfileUrl(Varien_Object $profile)
101: {
102: return $this->getUrl('sales/recurring_profile/view', array('profile' => $profile->getId()));
103: }
104:
105: 106: 107:
108: protected function _beforeToHtml()
109: {
110: $this->_prepareLastOrder();
111: $this->_prepareLastBillingAgreement();
112: $this->_prepareLastRecurringProfiles();
113: return parent::_beforeToHtml();
114: }
115:
116: 117: 118:
119: protected function _prepareLastOrder()
120: {
121: $orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
122: if ($orderId) {
123: $order = Mage::getModel('sales/order')->load($orderId);
124: if ($order->getId()) {
125: $isVisible = !in_array($order->getState(),
126: Mage::getSingleton('sales/order_config')->getInvisibleOnFrontStates());
127: $this->addData(array(
128: 'is_order_visible' => $isVisible,
129: 'view_order_id' => $this->getUrl('sales/order/view/', array('order_id' => $orderId)),
130: 'print_url' => $this->getUrl('sales/order/print', array('order_id'=> $orderId)),
131: 'can_print_order' => $isVisible,
132: 'can_view_order' => Mage::getSingleton('customer/session')->isLoggedIn() && $isVisible,
133: 'order_id' => $order->getIncrementId(),
134: ));
135: }
136: }
137: }
138:
139: 140: 141:
142: protected function _prepareLastBillingAgreement()
143: {
144: $agreementId = Mage::getSingleton('checkout/session')->getLastBillingAgreementId();
145: $customerId = Mage::getSingleton('customer/session')->getCustomerId();
146: if ($agreementId && $customerId) {
147: $agreement = Mage::getModel('sales/billing_agreement')->load($agreementId);
148: if ($agreement->getId() && $customerId == $agreement->getCustomerId()) {
149: $this->addData(array(
150: 'agreement_ref_id' => $agreement->getReferenceId(),
151: 'agreement_url' => $this->getUrl('sales/billing_agreement/view',
152: array('agreement' => $agreementId)
153: ),
154: ));
155: }
156: }
157: }
158:
159: 160: 161:
162: protected function _prepareLastRecurringProfiles()
163: {
164: $profileIds = Mage::getSingleton('checkout/session')->getLastRecurringProfileIds();
165: if ($profileIds && is_array($profileIds)) {
166: $collection = Mage::getModel('sales/recurring_profile')->getCollection()
167: ->addFieldToFilter('profile_id', array('in' => $profileIds))
168: ;
169: $profiles = array();
170: foreach ($collection as $profile) {
171: $profiles[] = $profile;
172: }
173: if ($profiles) {
174: $this->setRecurringProfiles($profiles);
175: if (Mage::getSingleton('customer/session')->isLoggedIn()) {
176: $this->setCanViewProfiles(true);
177: }
178: }
179: }
180: }
181: }
182: