1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @category Zookal_Mock |
5
|
|
|
* @package Block |
6
|
|
|
* @author Cyrill Schumacher | {firstName}@{lastName}.fm | @SchumacherFM |
7
|
|
|
* @copyright Copyright (c) Zookal Pty Ltd |
8
|
|
|
* @license OSL - Open Software Licence 3.0 | http://opensource.org/licenses/osl-3.0.php |
9
|
|
|
*/ |
10
|
|
|
class Zookal_Mock_Block_Payment_Backend extends Zookal_Mock_Model_Mocks_Abstract |
|
|
|
|
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var Mage_Sales_Model_Order_Payment |
14
|
|
|
*/ |
15
|
|
|
protected $_payment = null; |
16
|
|
|
|
17
|
|
|
protected $_html = '<strong>Mock Payment Info:</strong>{{paymentInfo}}'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param Mage_Sales_Model_Order_Payment $payment |
21
|
|
|
* |
22
|
|
|
* @return $this |
23
|
|
|
*/ |
24
|
|
|
public function setInfo(Mage_Sales_Model_Order_Payment $payment) |
25
|
|
|
{ |
26
|
|
|
$this->_payment = $payment; |
27
|
|
|
return $this; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @return string |
32
|
|
|
*/ |
33
|
|
|
public function toHtml() |
34
|
|
|
{ |
35
|
|
|
Mage::dispatchEvent( |
36
|
|
|
'mock_payment_backend_block_to_html_before', |
37
|
|
|
array('block' => $this, 'payment' => $this->_payment) |
38
|
|
|
); |
39
|
|
|
$return = $this->_html; |
40
|
|
|
if (strpos($this->_html, '{{paymentInfo}}') !== false) { |
41
|
|
|
$return = str_replace('{{paymentInfo}}', $this->_getPaymentInfoTable(), $this->_html); |
42
|
|
|
} |
43
|
|
|
return $return; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Moving that into a phtml file could be a little bit complicated and it's only backend ;-) |
48
|
|
|
* Use the observer to change the content. |
49
|
|
|
* |
50
|
|
|
* @return string |
51
|
|
|
*/ |
52
|
|
|
protected function _getPaymentInfoTable() |
53
|
|
|
{ |
54
|
|
|
$debug = $this->_getPaymentDebug(); |
55
|
|
|
$data = array(); |
56
|
|
|
foreach ($debug as $k => $v) { |
57
|
|
|
if (false === empty($v)) { |
58
|
|
|
$data[] = $this->_getPaymentInfoTableRow($k, $v); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
return '<table>' . PHP_EOL . implode("\n", $data) . PHP_EOL . '</table>'; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* you can translate here the column names into nicer names via the .csv files for the backend users |
66
|
|
|
* |
67
|
|
|
* @param string $k |
68
|
|
|
* @param string $v |
69
|
|
|
* |
70
|
|
|
* @return string |
71
|
|
|
*/ |
72
|
|
|
protected function _getPaymentInfoTableRow($k, $v) |
73
|
|
|
{ |
74
|
|
|
// The white space between the TDs is needed for nice output in PDF generation |
75
|
|
|
return '<tr><td>' . Mage::helper('zookal_mock')->__($k) . '</td> <td>' . $v . '</td></tr>'; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return array |
80
|
|
|
*/ |
81
|
|
|
protected function _getPaymentDebug() |
82
|
|
|
{ |
83
|
|
|
$debug = $this->_payment->debug(); |
84
|
|
|
if (isset($debug['additional_information']) && is_array($debug['additional_information'])) { |
85
|
|
|
$ai = $debug['additional_information']; |
86
|
|
|
unset($debug['additional_information']); |
87
|
|
|
$debug = array_merge($debug, $ai); |
88
|
|
|
} |
89
|
|
|
ksort($debug); |
90
|
|
|
return $debug; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param string $html |
95
|
|
|
*/ |
96
|
|
|
public function setHtml($html) |
97
|
|
|
{ |
98
|
|
|
$this->_html = $html; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return string |
103
|
|
|
*/ |
104
|
|
|
public function getHtml() |
105
|
|
|
{ |
106
|
|
|
return $this->_html; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Render as PDF |
111
|
|
|
* @return string |
112
|
|
|
*/ |
113
|
|
|
public function toPdf() |
114
|
|
|
{ |
115
|
|
|
return strip_tags($this->toHtml()); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.