ShippingTracker - Version 1.0.0

Version Notes

Details reflected in shipping mail and PDF's

Download this release

Release Info

Developer Nikhil K ravindran
Extension ShippingTracker
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

Files changed (22) hide show
  1. app/code/local/Mage/Sales/Model/Order/Pdf/Abstract.php +975 -0
  2. app/code/local/Neo/Shippingtracker/Block/Adminhtml/Shippingtracker.php +12 -0
  3. app/code/local/Neo/Shippingtracker/Block/Adminhtml/Shippingtracker/Edit.php +45 -0
  4. app/code/local/Neo/Shippingtracker/Block/Adminhtml/Shippingtracker/Edit/Form.php +19 -0
  5. app/code/local/Neo/Shippingtracker/Block/Adminhtml/Shippingtracker/Edit/Tab/Form.php +57 -0
  6. app/code/local/Neo/Shippingtracker/Block/Adminhtml/Shippingtracker/Edit/Tabs.php +24 -0
  7. app/code/local/Neo/Shippingtracker/Block/Adminhtml/Shippingtracker/Grid.php +117 -0
  8. app/code/local/Neo/Shippingtracker/Block/Shippingtracker.php +17 -0
  9. app/code/local/Neo/Shippingtracker/Helper/Data.php +6 -0
  10. app/code/local/Neo/Shippingtracker/Model/Mysql4/Shippingtracker.php +10 -0
  11. app/code/local/Neo/Shippingtracker/Model/Mysql4/Shippingtracker/Collection.php +10 -0
  12. app/code/local/Neo/Shippingtracker/Model/Shippingtracker.php +10 -0
  13. app/code/local/Neo/Shippingtracker/Model/Status.php +15 -0
  14. app/code/local/Neo/Shippingtracker/controllers/Adminhtml/ShippingtrackerController.php +214 -0
  15. app/code/local/Neo/Shippingtracker/controllers/IndexController.php +13 -0
  16. app/code/local/Neo/Shippingtracker/etc/config.xml +120 -0
  17. app/code/local/Neo/Shippingtracker/sql/shippingtracker_setup/mysql4-install-0.1.0.php +23 -0
  18. app/design/adminhtml/default/default/layout/shippingtracker.xml +8 -0
  19. app/design/adminhtml/default/default/template/sales/order/shipment/create/tracking.phtml +123 -0
  20. app/design/frontend/default/default/template/email/order/shipment/track.phtml +67 -0
  21. app/etc/modules/Neo_Shippingtracker.xml +9 -0
  22. package.xml +27 -0
app/code/local/Mage/Sales/Model/Order/Pdf/Abstract.php ADDED
@@ -0,0 +1,975 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * Sales Order PDF abstract model
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Sales
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ abstract class Mage_Sales_Model_Order_Pdf_Abstract extends Varien_Object
35
+ {
36
+ /**
37
+ * Y coordinate
38
+ *
39
+ * @var int
40
+ */
41
+ public $y;
42
+
43
+ /**
44
+ * Item renderers with render type key
45
+ *
46
+ * model => the model name
47
+ * renderer => the renderer model
48
+ *
49
+ * @var array
50
+ */
51
+ protected $_renderers = array();
52
+
53
+ /**
54
+ * Predefined constants
55
+ */
56
+ const XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID = 'sales_pdf/invoice/put_order_id';
57
+ const XML_PATH_SALES_PDF_SHIPMENT_PUT_ORDER_ID = 'sales_pdf/shipment/put_order_id';
58
+ const XML_PATH_SALES_PDF_CREDITMEMO_PUT_ORDER_ID = 'sales_pdf/creditmemo/put_order_id';
59
+
60
+ /**
61
+ * Zend PDF object
62
+ *
63
+ * @var Zend_Pdf
64
+ */
65
+ protected $_pdf;
66
+
67
+ /**
68
+ * Default total model
69
+ *
70
+ * @var string
71
+ */
72
+ protected $_defaultTotalModel = 'sales/order_pdf_total_default';
73
+
74
+ /**
75
+ * Retrieve PDF
76
+ *
77
+ * @return Zend_Pdf
78
+ */
79
+ abstract public function getPdf();
80
+
81
+ /**
82
+ * Returns the total width in points of the string using the specified font and
83
+ * size.
84
+ *
85
+ * This is not the most efficient way to perform this calculation. I'm
86
+ * concentrating optimization efforts on the upcoming layout manager class.
87
+ * Similar calculations exist inside the layout manager class, but widths are
88
+ * generally calculated only after determining line fragments.
89
+ *
90
+ * @param string $string
91
+ * @param Zend_Pdf_Resource_Font $font
92
+ * @param float $fontSize Font size in points
93
+ * @return float
94
+ */
95
+ public function widthForStringUsingFontSize($string, $font, $fontSize)
96
+ {
97
+ $drawingString = '"libiconv"' == ICONV_IMPL ?
98
+ iconv('UTF-8', 'UTF-16BE//IGNORE', $string) :
99
+ @iconv('UTF-8', 'UTF-16BE', $string);
100
+
101
+ $characters = array();
102
+ for ($i = 0; $i < strlen($drawingString); $i++) {
103
+ $characters[] = (ord($drawingString[$i++]) << 8) | ord($drawingString[$i]);
104
+ }
105
+ $glyphs = $font->glyphNumbersForCharacters($characters);
106
+ $widths = $font->widthsForGlyphs($glyphs);
107
+ $stringWidth = (array_sum($widths) / $font->getUnitsPerEm()) * $fontSize;
108
+ return $stringWidth;
109
+
110
+ }
111
+
112
+ /**
113
+ * Calculate coordinates to draw something in a column aligned to the right
114
+ *
115
+ * @param string $string
116
+ * @param int $x
117
+ * @param int $columnWidth
118
+ * @param Zend_Pdf_Resource_Font $font
119
+ * @param int $fontSize
120
+ * @param int $padding
121
+ * @return int
122
+ */
123
+ public function getAlignRight($string, $x, $columnWidth, Zend_Pdf_Resource_Font $font, $fontSize, $padding = 5)
124
+ {
125
+ $width = $this->widthForStringUsingFontSize($string, $font, $fontSize);
126
+ return $x + $columnWidth - $width - $padding;
127
+ }
128
+
129
+ /**
130
+ * Calculate coordinates to draw something in a column aligned to the center
131
+ *
132
+ * @param string $string
133
+ * @param int $x
134
+ * @param int $columnWidth
135
+ * @param Zend_Pdf_Resource_Font $font
136
+ * @param int $fontSize
137
+ * @return int
138
+ */
139
+ public function getAlignCenter($string, $x, $columnWidth, Zend_Pdf_Resource_Font $font, $fontSize)
140
+ {
141
+ $width = $this->widthForStringUsingFontSize($string, $font, $fontSize);
142
+ return $x + round(($columnWidth - $width) / 2);
143
+ }
144
+
145
+ /**
146
+ * Insert logo to pdf page
147
+ *
148
+ * @param Zend_Pdf_Page $page
149
+ * @param null $store
150
+ */
151
+ protected function insertLogo(&$page, $store = null)
152
+ {
153
+ $this->y = $this->y ? $this->y : 815;
154
+ $image = Mage::getStoreConfig('sales/identity/logo', $store);
155
+ if ($image) {
156
+ $image = Mage::getBaseDir('media') . '/sales/store/logo/' . $image;
157
+ if (is_file($image)) {
158
+ $image = Zend_Pdf_Image::imageWithPath($image);
159
+ $top = 830; //top border of the page
160
+ $widthLimit = 270; //half of the page width
161
+ $heightLimit = 270; //assuming the image is not a "skyscraper"
162
+ $width = $image->getPixelWidth();
163
+ $height = $image->getPixelHeight();
164
+
165
+ //preserving aspect ratio (proportions)
166
+ $ratio = $width / $height;
167
+ if ($ratio > 1 && $width > $widthLimit) {
168
+ $width = $widthLimit;
169
+ $height = $width / $ratio;
170
+ } elseif ($ratio < 1 && $height > $heightLimit) {
171
+ $height = $heightLimit;
172
+ $width = $height * $ratio;
173
+ } elseif ($ratio == 1 && $height > $heightLimit) {
174
+ $height = $heightLimit;
175
+ $width = $widthLimit;
176
+ }
177
+
178
+ $y1 = $top - $height;
179
+ $y2 = $top;
180
+ $x1 = 25;
181
+ $x2 = $x1 + $width;
182
+
183
+ //coordinates after transformation are rounded by Zend
184
+ $page->drawImage($image, $x1, $y1, $x2, $y2);
185
+
186
+ $this->y = $y1 - 10;
187
+ }
188
+ }
189
+ }
190
+
191
+ /**
192
+ * Insert address to pdf page
193
+ *
194
+ * @param Zend_Pdf_Page $page
195
+ * @param null $store
196
+ */
197
+ protected function insertAddress(&$page, $store = null)
198
+ {
199
+ $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
200
+ $font = $this->_setFontRegular($page, 10);
201
+ $page->setLineWidth(0);
202
+ $this->y = $this->y ? $this->y : 815;
203
+ $top = 815;
204
+ foreach (explode("\n", Mage::getStoreConfig('sales/identity/address', $store)) as $value){
205
+ if ($value !== '') {
206
+ $value = preg_replace('/<br[^>]*>/i', "\n", $value);
207
+ foreach (Mage::helper('core/string')->str_split($value, 45, true, true) as $_value) {
208
+ $page->drawText(trim(strip_tags($_value)),
209
+ $this->getAlignRight($_value, 130, 440, $font, 10),
210
+ $top,
211
+ 'UTF-8');
212
+ $top -= 10;
213
+ }
214
+ }
215
+ }
216
+ $this->y = ($this->y > $top) ? $top : $this->y;
217
+ }
218
+
219
+ /**
220
+ * Format address
221
+ *
222
+ * @param string $address
223
+ * @return array
224
+ */
225
+ protected function _formatAddress($address)
226
+ {
227
+ $return = array();
228
+ foreach (explode('|', $address) as $str) {
229
+ foreach (Mage::helper('core/string')->str_split($str, 45, true, true) as $part) {
230
+ if (empty($part)) {
231
+ continue;
232
+ }
233
+ $return[] = $part;
234
+ }
235
+ }
236
+ return $return;
237
+ }
238
+
239
+ /**
240
+ * Calculate address height
241
+ *
242
+ * @param array $address
243
+ * @return int Height
244
+ */
245
+ protected function _calcAddressHeight($address)
246
+ {
247
+ $y = 0;
248
+ foreach ($address as $value){
249
+ if ($value !== '') {
250
+ $text = array();
251
+ foreach (Mage::helper('core/string')->str_split($value, 55, true, true) as $_value) {
252
+ $text[] = $_value;
253
+ }
254
+ foreach ($text as $part) {
255
+ $y += 15;
256
+ }
257
+ }
258
+ }
259
+ return $y;
260
+ }
261
+
262
+ /**
263
+ * Insert order to pdf page
264
+ *
265
+ * @param Zend_Pdf_Page $page
266
+ * @param Mage_Sales_Model_Order $obj
267
+ * @param bool $putOrderId
268
+ */
269
+ protected function insertOrder(&$page, $obj, $putOrderId = true)
270
+ {
271
+ if ($obj instanceof Mage_Sales_Model_Order) {
272
+ $shipment = null;
273
+ $order = $obj;
274
+ } elseif ($obj instanceof Mage_Sales_Model_Order_Shipment) {
275
+ $shipment = $obj;
276
+ $order = $shipment->getOrder();
277
+ }
278
+
279
+ $this->y = $this->y ? $this->y : 815;
280
+ $top = $this->y;
281
+
282
+ $page->setFillColor(new Zend_Pdf_Color_GrayScale(0.45));
283
+ $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.45));
284
+ $page->drawRectangle(25, $top, 570, $top - 55);
285
+ $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
286
+ $this->setDocHeaderCoordinates(array(25, $top, 570, $top - 55));
287
+ $this->_setFontRegular($page, 10);
288
+
289
+ if ($putOrderId) {
290
+ $page->drawText(
291
+ Mage::helper('sales')->__('Order # ') . $order->getRealOrderId(), 35, ($top -= 30), 'UTF-8'
292
+ );
293
+ }
294
+ $page->drawText(
295
+ Mage::helper('sales')->__('Order Date: ') . Mage::helper('core')->formatDate(
296
+ $order->getCreatedAtStoreDate(), 'medium', false
297
+ ),
298
+ 35,
299
+ ($top -= 15),
300
+ 'UTF-8'
301
+ );
302
+
303
+ $top -= 10;
304
+ $page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
305
+ $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
306
+ $page->setLineWidth(0.5);
307
+ $page->drawRectangle(25, $top, 275, ($top - 25));
308
+ $page->drawRectangle(275, $top, 570, ($top - 25));
309
+
310
+ /* Calculate blocks info */
311
+
312
+ /* Billing Address */
313
+ $billingAddress = $this->_formatAddress($order->getBillingAddress()->format('pdf'));
314
+
315
+ /* Payment */
316
+ $paymentInfo = Mage::helper('payment')->getInfoBlock($order->getPayment())
317
+ ->setIsSecureMode(true)
318
+ ->toPdf();
319
+ $paymentInfo = htmlspecialchars_decode($paymentInfo, ENT_QUOTES);
320
+ $payment = explode('{{pdf_row_separator}}', $paymentInfo);
321
+ foreach ($payment as $key=>$value){
322
+ if (strip_tags(trim($value)) == '') {
323
+ unset($payment[$key]);
324
+ }
325
+ }
326
+ reset($payment);
327
+
328
+ /* Shipping Address and Method */
329
+ if (!$order->getIsVirtual()) {
330
+ /* Shipping Address */
331
+ $shippingAddress = $this->_formatAddress($order->getShippingAddress()->format('pdf'));
332
+ $shippingMethod = $order->getShippingDescription();
333
+ }
334
+
335
+ $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
336
+ $this->_setFontBold($page, 12);
337
+ $page->drawText(Mage::helper('sales')->__('Sold to:'), 35, ($top - 15), 'UTF-8');
338
+
339
+ if (!$order->getIsVirtual()) {
340
+ $page->drawText(Mage::helper('sales')->__('Ship to:'), 285, ($top - 15), 'UTF-8');
341
+ } else {
342
+ $page->drawText(Mage::helper('sales')->__('Payment Method:'), 285, ($top - 15), 'UTF-8');
343
+ }
344
+
345
+ $addressesHeight = $this->_calcAddressHeight($billingAddress);
346
+ if (isset($shippingAddress)) {
347
+ $addressesHeight = max($addressesHeight, $this->_calcAddressHeight($shippingAddress));
348
+ }
349
+
350
+ $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
351
+ $page->drawRectangle(25, ($top - 25), 570, $top - 33 - $addressesHeight);
352
+ $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
353
+ $this->_setFontRegular($page, 10);
354
+ $this->y = $top - 40;
355
+ $addressesStartY = $this->y;
356
+
357
+ foreach ($billingAddress as $value){
358
+ if ($value !== '') {
359
+ $text = array();
360
+ foreach (Mage::helper('core/string')->str_split($value, 45, true, true) as $_value) {
361
+ $text[] = $_value;
362
+ }
363
+ foreach ($text as $part) {
364
+ $page->drawText(strip_tags(ltrim($part)), 35, $this->y, 'UTF-8');
365
+ $this->y -= 15;
366
+ }
367
+ }
368
+ }
369
+
370
+ $addressesEndY = $this->y;
371
+
372
+ if (!$order->getIsVirtual()) {
373
+ $this->y = $addressesStartY;
374
+ foreach ($shippingAddress as $value){
375
+ if ($value!=='') {
376
+ $text = array();
377
+ foreach (Mage::helper('core/string')->str_split($value, 45, true, true) as $_value) {
378
+ $text[] = $_value;
379
+ }
380
+ foreach ($text as $part) {
381
+ $page->drawText(strip_tags(ltrim($part)), 285, $this->y, 'UTF-8');
382
+ $this->y -= 15;
383
+ }
384
+ }
385
+ }
386
+
387
+ $addressesEndY = min($addressesEndY, $this->y);
388
+ $this->y = $addressesEndY;
389
+
390
+ $page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
391
+ $page->setLineWidth(0.5);
392
+ $page->drawRectangle(25, $this->y, 275, $this->y-25);
393
+ $page->drawRectangle(275, $this->y, 570, $this->y-25);
394
+
395
+ $this->y -= 15;
396
+ $this->_setFontBold($page, 12);
397
+ $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
398
+ $page->drawText(Mage::helper('sales')->__('Payment Method'), 35, $this->y, 'UTF-8');
399
+ $page->drawText(Mage::helper('sales')->__('Shipping Method:'), 285, $this->y , 'UTF-8');
400
+
401
+ $this->y -=10;
402
+ $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
403
+
404
+ $this->_setFontRegular($page, 10);
405
+ $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
406
+
407
+ $paymentLeft = 35;
408
+ $yPayments = $this->y - 15;
409
+ }
410
+ else {
411
+ $yPayments = $addressesStartY;
412
+ $paymentLeft = 285;
413
+ }
414
+
415
+ foreach ($payment as $value){
416
+ if (trim($value) != '') {
417
+ //Printing "Payment Method" lines
418
+ $value = preg_replace('/<br[^>]*>/i', "\n", $value);
419
+ foreach (Mage::helper('core/string')->str_split($value, 45, true, true) as $_value) {
420
+ $page->drawText(strip_tags(trim($_value)), $paymentLeft, $yPayments, 'UTF-8');
421
+ $yPayments -= 15;
422
+ }
423
+ }
424
+ }
425
+
426
+ if ($order->getIsVirtual()) {
427
+ // replacement of Shipments-Payments rectangle block
428
+ $yPayments = min($addressesEndY, $yPayments);
429
+ $page->drawLine(25, ($top - 25), 25, $yPayments);
430
+ $page->drawLine(570, ($top - 25), 570, $yPayments);
431
+ $page->drawLine(25, $yPayments, 570, $yPayments);
432
+
433
+ $this->y = $yPayments - 15;
434
+ } else {
435
+ $topMargin = 15;
436
+ $methodStartY = $this->y;
437
+ $this->y -= 15;
438
+
439
+ foreach (Mage::helper('core/string')->str_split($shippingMethod, 45, true, true) as $_value) {
440
+ $page->drawText(strip_tags(trim($_value)), 285, $this->y, 'UTF-8');
441
+ $this->y -= 15;
442
+ }
443
+
444
+ $yShipments = $this->y;
445
+ $totalShippingChargesText = "(" . Mage::helper('sales')->__('Total Shipping Charges') . " "
446
+ . $order->formatPriceTxt($order->getShippingAmount()) . ")";
447
+
448
+ $page->drawText($totalShippingChargesText, 285, $yShipments - $topMargin, 'UTF-8');
449
+ $yShipments -= $topMargin + 10;
450
+
451
+ $tracks = array();
452
+ if ($shipment) {
453
+ $tracks = $shipment->getAllTracks();
454
+ }
455
+ if (count($tracks)) {
456
+ $page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
457
+ $page->setLineWidth(0.5);
458
+ $page->drawRectangle(285, $yShipments, 510, $yShipments - 10);
459
+ $page->drawLine(400, $yShipments, 400, $yShipments - 10);
460
+ //$page->drawLine(510, $yShipments, 510, $yShipments - 10);
461
+
462
+ $this->_setFontRegular($page, 9);
463
+ $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
464
+ //$page->drawText(Mage::helper('sales')->__('Carrier'), 290, $yShipments - 7 , 'UTF-8');
465
+ $page->drawText(Mage::helper('sales')->__('Title'), 290, $yShipments - 7, 'UTF-8');
466
+ $page->drawText(Mage::helper('sales')->__('Number'), 410, $yShipments - 7, 'UTF-8');
467
+
468
+ $yShipments -= 20;
469
+ $this->_setFontRegular($page, 8);
470
+ foreach ($tracks as $track) {
471
+
472
+ $CarrierCode = $track->getCarrierCode();
473
+ if ($CarrierCode != 'custom') {
474
+ /* From here we check whether it is the custom shipping Carrier.
475
+ * @ Nikhil K Ravindran - Shipping Tracker Module Developer.
476
+ */
477
+ $carrier_code_checker = strpos($CarrierCode, 'neotracker');
478
+ if($carrier_code_checker !== false){
479
+ $carrier_code_result = explode(":", $CarrierCode);
480
+ $carrier_code_collection = Mage::getModel('shippingtracker/shippingtracker')->load($carrier_code_result[0]);
481
+ $carrierTitle = $carrier_code_collection->getTitle();
482
+ }
483
+ /* Custom Code for checking Shipper Tracker ends here.
484
+ * @ Nikhil K Ravindran - Shipping Tracker Module Developer.
485
+ */
486
+ else {
487
+ $carrier = Mage::getSingleton('shipping/config')->getCarrierInstance($CarrierCode);
488
+ $carrierTitle = $carrier->getConfigData('title');
489
+ }
490
+ } else {
491
+ $carrierTitle = Mage::helper('sales')->__('Custom Value');
492
+ }
493
+
494
+ //$truncatedCarrierTitle = substr($carrierTitle, 0, 35) . (strlen($carrierTitle) > 35 ? '...' : '');
495
+ $maxTitleLen = 45;
496
+ $endOfTitle = strlen($track->getTitle()) > $maxTitleLen ? '...' : '';
497
+ $truncatedTitle = substr($track->getTitle(), 0, $maxTitleLen) . $endOfTitle;
498
+ //$page->drawText($truncatedCarrierTitle, 285, $yShipments , 'UTF-8');
499
+ $page->drawText($truncatedTitle, 292, $yShipments , 'UTF-8');
500
+ $page->drawText($track->getNumber(), 410, $yShipments , 'UTF-8');
501
+ $yShipments -= $topMargin - 5;
502
+ }
503
+ } else {
504
+ $yShipments -= $topMargin - 5;
505
+ }
506
+
507
+ $currentY = min($yPayments, $yShipments);
508
+
509
+ // replacement of Shipments-Payments rectangle block
510
+ $page->drawLine(25, $methodStartY, 25, $currentY); //left
511
+ $page->drawLine(25, $currentY, 570, $currentY); //bottom
512
+ $page->drawLine(570, $currentY, 570, $methodStartY); //right
513
+
514
+ $this->y = $currentY;
515
+ $this->y -= 15;
516
+ }
517
+ }
518
+
519
+ /**
520
+ * Insert title and number for concrete document type
521
+ *
522
+ * @param Zend_Pdf_Page $page
523
+ * @param string $text
524
+ * @return void
525
+ */
526
+ public function insertDocumentNumber(Zend_Pdf_Page $page, $text)
527
+ {
528
+ $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
529
+ $this->_setFontRegular($page, 10);
530
+ $docHeader = $this->getDocHeaderCoordinates();
531
+ $page->drawText($text, 35, $docHeader[1] - 15, 'UTF-8');
532
+ }
533
+
534
+ /**
535
+ * Sort totals list
536
+ *
537
+ * @param array $a
538
+ * @param array $b
539
+ * @return int
540
+ */
541
+ protected function _sortTotalsList($a, $b) {
542
+ if (!isset($a['sort_order']) || !isset($b['sort_order'])) {
543
+ return 0;
544
+ }
545
+
546
+ if ($a['sort_order'] == $b['sort_order']) {
547
+ return 0;
548
+ }
549
+
550
+ return ($a['sort_order'] > $b['sort_order']) ? 1 : -1;
551
+ }
552
+
553
+ /**
554
+ * Return total list
555
+ *
556
+ * @param Mage_Sales_Model_Abstract $source
557
+ * @return array
558
+ */
559
+ protected function _getTotalsList($source)
560
+ {
561
+ $totals = Mage::getConfig()->getNode('global/pdf/totals')->asArray();
562
+ usort($totals, array($this, '_sortTotalsList'));
563
+ $totalModels = array();
564
+ foreach ($totals as $index => $totalInfo) {
565
+ if (!empty($totalInfo['model'])) {
566
+ $totalModel = Mage::getModel($totalInfo['model']);
567
+ if ($totalModel instanceof Mage_Sales_Model_Order_Pdf_Total_Default) {
568
+ $totalInfo['model'] = $totalModel;
569
+ } else {
570
+ Mage::throwException(
571
+ Mage::helper('sales')->__('PDF total model should extend Mage_Sales_Model_Order_Pdf_Total_Default')
572
+ );
573
+ }
574
+ } else {
575
+ $totalModel = Mage::getModel($this->_defaultTotalModel);
576
+ }
577
+ $totalModel->setData($totalInfo);
578
+ $totalModels[] = $totalModel;
579
+ }
580
+
581
+ return $totalModels;
582
+ }
583
+
584
+ /**
585
+ * Insert totals to pdf page
586
+ *
587
+ * @param Zend_Pdf_Page $page
588
+ * @param Mage_Sales_Model_Abstract $source
589
+ * @return Zend_Pdf_Page
590
+ */
591
+ protected function insertTotals($page, $source){
592
+ $order = $source->getOrder();
593
+ $totals = $this->_getTotalsList($source);
594
+ $lineBlock = array(
595
+ 'lines' => array(),
596
+ 'height' => 15
597
+ );
598
+ foreach ($totals as $total) {
599
+ $total->setOrder($order)
600
+ ->setSource($source);
601
+
602
+ if ($total->canDisplay()) {
603
+ $total->setFontSize(10);
604
+ foreach ($total->getTotalsForDisplay() as $totalData) {
605
+ $lineBlock['lines'][] = array(
606
+ array(
607
+ 'text' => $totalData['label'],
608
+ 'feed' => 475,
609
+ 'align' => 'right',
610
+ 'font_size' => $totalData['font_size'],
611
+ 'font' => 'bold'
612
+ ),
613
+ array(
614
+ 'text' => $totalData['amount'],
615
+ 'feed' => 565,
616
+ 'align' => 'right',
617
+ 'font_size' => $totalData['font_size'],
618
+ 'font' => 'bold'
619
+ ),
620
+ );
621
+ }
622
+ }
623
+ }
624
+
625
+ $this->y -= 20;
626
+ $page = $this->drawLineBlocks($page, array($lineBlock));
627
+ return $page;
628
+ }
629
+
630
+ /**
631
+ * Parse item description
632
+ *
633
+ * @param Varien_Object $item
634
+ * @return array
635
+ */
636
+ protected function _parseItemDescription($item)
637
+ {
638
+ $matches = array();
639
+ $description = $item->getDescription();
640
+ if (preg_match_all('/<li.*?>(.*?)<\/li>/i', $description, $matches)) {
641
+ return $matches[1];
642
+ }
643
+
644
+ return array($description);
645
+ }
646
+
647
+ /**
648
+ * Before getPdf processing
649
+ */
650
+ protected function _beforeGetPdf() {
651
+ $translate = Mage::getSingleton('core/translate');
652
+ /* @var $translate Mage_Core_Model_Translate */
653
+ $translate->setTranslateInline(false);
654
+ }
655
+
656
+ /**
657
+ * After getPdf processing
658
+ */
659
+ protected function _afterGetPdf() {
660
+ $translate = Mage::getSingleton('core/translate');
661
+ /* @var $translate Mage_Core_Model_Translate */
662
+ $translate->setTranslateInline(true);
663
+ }
664
+
665
+ /**
666
+ * Format option value process
667
+ *
668
+ * @param array|string $value
669
+ * @param Mage_Sales_Model_Order $order
670
+ * @return string
671
+ */
672
+ protected function _formatOptionValue($value, $order)
673
+ {
674
+ $resultValue = '';
675
+ if (is_array($value)) {
676
+ if (isset($value['qty'])) {
677
+ $resultValue .= sprintf('%d', $value['qty']) . ' x ';
678
+ }
679
+
680
+ $resultValue .= $value['title'];
681
+
682
+ if (isset($value['price'])) {
683
+ $resultValue .= " " . $order->formatPrice($value['price']);
684
+ }
685
+ return $resultValue;
686
+ } else {
687
+ return $value;
688
+ }
689
+ }
690
+
691
+ /**
692
+ * Initialize renderer process
693
+ *
694
+ * @param string $type
695
+ */
696
+ protected function _initRenderer($type)
697
+ {
698
+ $node = Mage::getConfig()->getNode('global/pdf/' . $type);
699
+ foreach ($node->children() as $renderer) {
700
+ $this->_renderers[$renderer->getName()] = array(
701
+ 'model' => (string)$renderer,
702
+ 'renderer' => null
703
+ );
704
+ }
705
+ }
706
+
707
+ /**
708
+ * Retrieve renderer model
709
+ *
710
+ * @param string $type
711
+ * @throws Mage_Core_Exception
712
+ * @return Mage_Sales_Model_Order_Pdf_Items_Abstract
713
+ */
714
+ protected function _getRenderer($type)
715
+ {
716
+ if (!isset($this->_renderers[$type])) {
717
+ $type = 'default';
718
+ }
719
+
720
+ if (!isset($this->_renderers[$type])) {
721
+ Mage::throwException(Mage::helper('sales')->__('Invalid renderer model'));
722
+ }
723
+
724
+ if (is_null($this->_renderers[$type]['renderer'])) {
725
+ $this->_renderers[$type]['renderer'] = Mage::getSingleton($this->_renderers[$type]['model']);
726
+ }
727
+
728
+ return $this->_renderers[$type]['renderer'];
729
+ }
730
+
731
+ /**
732
+ * Public method of protected @see _getRenderer()
733
+ *
734
+ * Retrieve renderer model
735
+ *
736
+ * @param string $type
737
+ * @return Mage_Sales_Model_Order_Pdf_Items_Abstract
738
+ */
739
+ public function getRenderer($type)
740
+ {
741
+ return $this->_getRenderer($type);
742
+ }
743
+
744
+ /**
745
+ * Draw Item process
746
+ *
747
+ * @param Varien_Object $item
748
+ * @param Zend_Pdf_Page $page
749
+ * @param Mage_Sales_Model_Order $order
750
+ * @return Zend_Pdf_Page
751
+ */
752
+ protected function _drawItem(Varien_Object $item, Zend_Pdf_Page $page, Mage_Sales_Model_Order $order)
753
+ {
754
+ $type = $item->getOrderItem()->getProductType();
755
+ $renderer = $this->_getRenderer($type);
756
+ $renderer->setOrder($order);
757
+ $renderer->setItem($item);
758
+ $renderer->setPdf($this);
759
+ $renderer->setPage($page);
760
+ $renderer->setRenderedModel($this);
761
+
762
+ $renderer->draw();
763
+
764
+ return $renderer->getPage();
765
+ }
766
+
767
+ /**
768
+ * Set font as regular
769
+ *
770
+ * @param Zend_Pdf_Page $object
771
+ * @param int $size
772
+ * @return Zend_Pdf_Resource_Font
773
+ */
774
+ protected function _setFontRegular($object, $size = 7)
775
+ {
776
+ $font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/LinLibertineFont/LinLibertine_Re-4.4.1.ttf');
777
+ $object->setFont($font, $size);
778
+ return $font;
779
+ }
780
+
781
+ /**
782
+ * Set font as bold
783
+ *
784
+ * @param Zend_Pdf_Page $object
785
+ * @param int $size
786
+ * @return Zend_Pdf_Resource_Font
787
+ */
788
+ protected function _setFontBold($object, $size = 7)
789
+ {
790
+ $font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/LinLibertineFont/LinLibertine_Bd-2.8.1.ttf');
791
+ $object->setFont($font, $size);
792
+ return $font;
793
+ }
794
+
795
+ /**
796
+ * Set font as italic
797
+ *
798
+ * @param Zend_Pdf_Page $object
799
+ * @param int $size
800
+ * @return Zend_Pdf_Resource_Font
801
+ */
802
+ protected function _setFontItalic($object, $size = 7)
803
+ {
804
+ $font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/LinLibertineFont/LinLibertine_It-2.8.2.ttf');
805
+ $object->setFont($font, $size);
806
+ return $font;
807
+ }
808
+
809
+ /**
810
+ * Set PDF object
811
+ *
812
+ * @param Zend_Pdf $pdf
813
+ * @return Mage_Sales_Model_Order_Pdf_Abstract
814
+ */
815
+ protected function _setPdf(Zend_Pdf $pdf)
816
+ {
817
+ $this->_pdf = $pdf;
818
+ return $this;
819
+ }
820
+
821
+ /**
822
+ * Retrieve PDF object
823
+ *
824
+ * @throws Mage_Core_Exception
825
+ * @return Zend_Pdf
826
+ */
827
+ protected function _getPdf()
828
+ {
829
+ if (!$this->_pdf instanceof Zend_Pdf) {
830
+ Mage::throwException(Mage::helper('sales')->__('Please define PDF object before using.'));
831
+ }
832
+
833
+ return $this->_pdf;
834
+ }
835
+
836
+ /**
837
+ * Create new page and assign to PDF object
838
+ *
839
+ * @param array $settings
840
+ * @return Zend_Pdf_Page
841
+ */
842
+ public function newPage(array $settings = array())
843
+ {
844
+ $pageSize = !empty($settings['page_size']) ? $settings['page_size'] : Zend_Pdf_Page::SIZE_A4;
845
+ $page = $this->_getPdf()->newPage($pageSize);
846
+ $this->_getPdf()->pages[] = $page;
847
+ $this->y = 800;
848
+
849
+ return $page;
850
+ }
851
+
852
+ /**
853
+ * Draw lines
854
+ *
855
+ * draw items array format:
856
+ * lines array;array of line blocks (required)
857
+ * shift int; full line height (optional)
858
+ * height int;line spacing (default 10)
859
+ *
860
+ * line block has line columns array
861
+ *
862
+ * column array format
863
+ * text string|array; draw text (required)
864
+ * feed int; x position (required)
865
+ * font string; font style, optional: bold, italic, regular
866
+ * font_file string; path to font file (optional for use your custom font)
867
+ * font_size int; font size (default 7)
868
+ * align string; text align (also see feed parametr), optional left, right
869
+ * height int;line spacing (default 10)
870
+ *
871
+ * @param Zend_Pdf_Page $page
872
+ * @param array $draw
873
+ * @param array $pageSettings
874
+ * @throws Mage_Core_Exception
875
+ * @return Zend_Pdf_Page
876
+ */
877
+ public function drawLineBlocks(Zend_Pdf_Page $page, array $draw, array $pageSettings = array())
878
+ {
879
+ foreach ($draw as $itemsProp) {
880
+ if (!isset($itemsProp['lines']) || !is_array($itemsProp['lines'])) {
881
+ Mage::throwException(Mage::helper('sales')->__('Invalid draw line data. Please define "lines" array.'));
882
+ }
883
+ $lines = $itemsProp['lines'];
884
+ $height = isset($itemsProp['height']) ? $itemsProp['height'] : 10;
885
+
886
+ if (empty($itemsProp['shift'])) {
887
+ $shift = 0;
888
+ foreach ($lines as $line) {
889
+ $maxHeight = 0;
890
+ foreach ($line as $column) {
891
+ $lineSpacing = !empty($column['height']) ? $column['height'] : $height;
892
+ if (!is_array($column['text'])) {
893
+ $column['text'] = array($column['text']);
894
+ }
895
+ $top = 0;
896
+ foreach ($column['text'] as $part) {
897
+ $top += $lineSpacing;
898
+ }
899
+
900
+ $maxHeight = $top > $maxHeight ? $top : $maxHeight;
901
+ }
902
+ $shift += $maxHeight;
903
+ }
904
+ $itemsProp['shift'] = $shift;
905
+ }
906
+
907
+ if ($this->y - $itemsProp['shift'] < 15) {
908
+ $page = $this->newPage($pageSettings);
909
+ }
910
+
911
+ foreach ($lines as $line) {
912
+ $maxHeight = 0;
913
+ foreach ($line as $column) {
914
+ $fontSize = empty($column['font_size']) ? 10 : $column['font_size'];
915
+ if (!empty($column['font_file'])) {
916
+ $font = Zend_Pdf_Font::fontWithPath($column['font_file']);
917
+ $page->setFont($font, $fontSize);
918
+ } else {
919
+ $fontStyle = empty($column['font']) ? 'regular' : $column['font'];
920
+ switch ($fontStyle) {
921
+ case 'bold':
922
+ $font = $this->_setFontBold($page, $fontSize);
923
+ break;
924
+ case 'italic':
925
+ $font = $this->_setFontItalic($page, $fontSize);
926
+ break;
927
+ default:
928
+ $font = $this->_setFontRegular($page, $fontSize);
929
+ break;
930
+ }
931
+ }
932
+
933
+ if (!is_array($column['text'])) {
934
+ $column['text'] = array($column['text']);
935
+ }
936
+
937
+ $lineSpacing = !empty($column['height']) ? $column['height'] : $height;
938
+ $top = 0;
939
+ foreach ($column['text'] as $part) {
940
+ if ($this->y - $lineSpacing < 15) {
941
+ $page = $this->newPage($pageSettings);
942
+ }
943
+
944
+ $feed = $column['feed'];
945
+ $textAlign = empty($column['align']) ? 'left' : $column['align'];
946
+ $width = empty($column['width']) ? 0 : $column['width'];
947
+ switch ($textAlign) {
948
+ case 'right':
949
+ if ($width) {
950
+ $feed = $this->getAlignRight($part, $feed, $width, $font, $fontSize);
951
+ }
952
+ else {
953
+ $feed = $feed - $this->widthForStringUsingFontSize($part, $font, $fontSize);
954
+ }
955
+ break;
956
+ case 'center':
957
+ if ($width) {
958
+ $feed = $this->getAlignCenter($part, $feed, $width, $font, $fontSize);
959
+ }
960
+ break;
961
+ }
962
+ $page->drawText($part, $feed, $this->y-$top, 'UTF-8');
963
+ $top += $lineSpacing;
964
+ }
965
+
966
+ $maxHeight = $top > $maxHeight ? $top : $maxHeight;
967
+ }
968
+ $this->y -= $maxHeight;
969
+ }
970
+ }
971
+
972
+ return $page;
973
+ }
974
+ }
975
+
app/code/local/Neo/Shippingtracker/Block/Adminhtml/Shippingtracker.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Neo_Shippingtracker_Block_Adminhtml_Shippingtracker extends Mage_Adminhtml_Block_Widget_Grid_Container
3
+ {
4
+ public function __construct()
5
+ {
6
+ $this->_controller = 'adminhtml_shippingtracker';
7
+ $this->_blockGroup = 'shippingtracker';
8
+ $this->_headerText = Mage::helper('shippingtracker')->__('Item Manager');
9
+ $this->_addButtonLabel = Mage::helper('shippingtracker')->__('Add Item');
10
+ parent::__construct();
11
+ }
12
+ }
app/code/local/Neo/Shippingtracker/Block/Adminhtml/Shippingtracker/Edit.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Neo_Shippingtracker_Block_Adminhtml_Shippingtracker_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+
9
+ $this->_objectId = 'id';
10
+ $this->_blockGroup = 'shippingtracker';
11
+ $this->_controller = 'adminhtml_shippingtracker';
12
+
13
+ $this->_updateButton('save', 'label', Mage::helper('shippingtracker')->__('Save Item'));
14
+ $this->_updateButton('delete', 'label', Mage::helper('shippingtracker')->__('Delete Item'));
15
+
16
+ $this->_addButton('saveandcontinue', array(
17
+ 'label' => Mage::helper('adminhtml')->__('Save And Continue Edit'),
18
+ 'onclick' => 'saveAndContinueEdit()',
19
+ 'class' => 'save',
20
+ ), -100);
21
+
22
+ $this->_formScripts[] = "
23
+ function toggleEditor() {
24
+ if (tinyMCE.getInstanceById('shippingtracker_content') == null) {
25
+ tinyMCE.execCommand('mceAddControl', false, 'shippingtracker_content');
26
+ } else {
27
+ tinyMCE.execCommand('mceRemoveControl', false, 'shippingtracker_content');
28
+ }
29
+ }
30
+
31
+ function saveAndContinueEdit(){
32
+ editForm.submit($('edit_form').action+'back/edit/');
33
+ }
34
+ ";
35
+ }
36
+
37
+ public function getHeaderText()
38
+ {
39
+ if( Mage::registry('shippingtracker_data') && Mage::registry('shippingtracker_data')->getId() ) {
40
+ return Mage::helper('shippingtracker')->__("Edit Item '%s'", $this->htmlEscape(Mage::registry('shippingtracker_data')->getTitle()));
41
+ } else {
42
+ return Mage::helper('shippingtracker')->__('Add Item');
43
+ }
44
+ }
45
+ }
app/code/local/Neo/Shippingtracker/Block/Adminhtml/Shippingtracker/Edit/Form.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Neo_Shippingtracker_Block_Adminhtml_Shippingtracker_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
4
+ {
5
+ protected function _prepareForm()
6
+ {
7
+ $form = new Varien_Data_Form(array(
8
+ 'id' => 'edit_form',
9
+ 'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
10
+ 'method' => 'post',
11
+ 'enctype' => 'multipart/form-data'
12
+ )
13
+ );
14
+
15
+ $form->setUseContainer(true);
16
+ $this->setForm($form);
17
+ return parent::_prepareForm();
18
+ }
19
+ }
app/code/local/Neo/Shippingtracker/Block/Adminhtml/Shippingtracker/Edit/Tab/Form.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Neo_Shippingtracker_Block_Adminhtml_Shippingtracker_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
4
+ {
5
+ protected function _prepareForm()
6
+ {
7
+ $form = new Varien_Data_Form();
8
+ $this->setForm($form);
9
+ $fieldset = $form->addFieldset('shippingtracker_form', array('legend'=>Mage::helper('shippingtracker')->__('Item information')));
10
+
11
+ $fieldset->addField('title', 'text', array(
12
+ 'label' => Mage::helper('shippingtracker')->__('Carrier Name'),
13
+ 'class' => 'required-entry',
14
+ 'required' => true,
15
+ 'name' => 'title',
16
+ ));
17
+
18
+ $fieldset->addField('content', 'text', array(
19
+ 'label' => Mage::helper('shippingtracker')->__('Url'),
20
+ 'class' => 'required-entry',
21
+ 'required' => true,
22
+ 'name' => 'content',
23
+ ));
24
+ /*
25
+ $fieldset->addField('filename', 'file', array(
26
+ 'label' => Mage::helper('shippingtracker')->__('File'),
27
+ 'required' => false,
28
+ 'name' => 'filename',
29
+ ));
30
+ * */
31
+
32
+ $fieldset->addField('status', 'select', array(
33
+ 'label' => Mage::helper('shippingtracker')->__('Status'),
34
+ 'name' => 'status',
35
+ 'values' => array(
36
+ array(
37
+ 'value' => 1,
38
+ 'label' => Mage::helper('shippingtracker')->__('Enabled'),
39
+ ),
40
+
41
+ array(
42
+ 'value' => 2,
43
+ 'label' => Mage::helper('shippingtracker')->__('Disabled'),
44
+ ),
45
+ ),
46
+ ));
47
+
48
+ if ( Mage::getSingleton('adminhtml/session')->getShippingtrackerData() )
49
+ {
50
+ $form->setValues(Mage::getSingleton('adminhtml/session')->getShippingtrackerData());
51
+ Mage::getSingleton('adminhtml/session')->setShippingtrackerData(null);
52
+ } elseif ( Mage::registry('shippingtracker_data') ) {
53
+ $form->setValues(Mage::registry('shippingtracker_data')->getData());
54
+ }
55
+ return parent::_prepareForm();
56
+ }
57
+ }
app/code/local/Neo/Shippingtracker/Block/Adminhtml/Shippingtracker/Edit/Tabs.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Neo_Shippingtracker_Block_Adminhtml_Shippingtracker_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
4
+ {
5
+
6
+ public function __construct()
7
+ {
8
+ parent::__construct();
9
+ $this->setId('shippingtracker_tabs');
10
+ $this->setDestElementId('edit_form');
11
+ $this->setTitle(Mage::helper('shippingtracker')->__('Item Information'));
12
+ }
13
+
14
+ protected function _beforeToHtml()
15
+ {
16
+ $this->addTab('form_section', array(
17
+ 'label' => Mage::helper('shippingtracker')->__('Item Information'),
18
+ 'title' => Mage::helper('shippingtracker')->__('Item Information'),
19
+ 'content' => $this->getLayout()->createBlock('shippingtracker/adminhtml_shippingtracker_edit_tab_form')->toHtml(),
20
+ ));
21
+
22
+ return parent::_beforeToHtml();
23
+ }
24
+ }
app/code/local/Neo/Shippingtracker/Block/Adminhtml/Shippingtracker/Grid.php ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Neo_Shippingtracker_Block_Adminhtml_Shippingtracker_Grid extends Mage_Adminhtml_Block_Widget_Grid
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->setId('shippingtrackerGrid');
9
+ $this->setDefaultSort('shippingtracker_id');
10
+ $this->setDefaultDir('ASC');
11
+ $this->setSaveParametersInSession(true);
12
+ }
13
+
14
+ protected function _prepareCollection()
15
+ {
16
+ $collection = Mage::getModel('shippingtracker/shippingtracker')->getCollection();
17
+ $this->setCollection($collection);
18
+ return parent::_prepareCollection();
19
+ }
20
+
21
+ protected function _prepareColumns()
22
+ {
23
+ $this->addColumn('shippingtracker_id', array(
24
+ 'header' => Mage::helper('shippingtracker')->__('ID'),
25
+ 'align' =>'right',
26
+ 'width' => '50px',
27
+ 'index' => 'shippingtracker_id',
28
+ ));
29
+
30
+ $this->addColumn('title', array(
31
+ 'header' => Mage::helper('shippingtracker')->__('Carrier Name'),
32
+ 'align' =>'left',
33
+ 'index' => 'title',
34
+ ));
35
+
36
+
37
+ $this->addColumn('content', array(
38
+ 'header' => Mage::helper('shippingtracker')->__('Url'),
39
+ 'width' => '800px',
40
+ 'align' =>'left',
41
+ 'index' => 'content',
42
+ ));
43
+
44
+
45
+ $this->addColumn('status', array(
46
+ 'header' => Mage::helper('shippingtracker')->__('Status'),
47
+ 'align' => 'left',
48
+ 'width' => '80px',
49
+ 'index' => 'status',
50
+ 'type' => 'options',
51
+ 'options' => array(
52
+ 1 => 'Enabled',
53
+ 2 => 'Disabled',
54
+ ),
55
+ ));
56
+
57
+ $this->addColumn('action',
58
+ array(
59
+ 'header' => Mage::helper('shippingtracker')->__('Action'),
60
+ 'width' => '100',
61
+ 'type' => 'action',
62
+ 'getter' => 'getId',
63
+ 'actions' => array(
64
+ array(
65
+ 'caption' => Mage::helper('shippingtracker')->__('Edit'),
66
+ 'url' => array('base'=> '*/*/edit'),
67
+ 'field' => 'id'
68
+ )
69
+ ),
70
+ 'filter' => false,
71
+ 'sortable' => false,
72
+ 'index' => 'stores',
73
+ 'is_system' => true,
74
+ ));
75
+
76
+ $this->addExportType('*/*/exportCsv', Mage::helper('shippingtracker')->__('CSV'));
77
+ $this->addExportType('*/*/exportXml', Mage::helper('shippingtracker')->__('XML'));
78
+
79
+ return parent::_prepareColumns();
80
+ }
81
+
82
+ protected function _prepareMassaction()
83
+ {
84
+ $this->setMassactionIdField('shippingtracker_id');
85
+ $this->getMassactionBlock()->setFormFieldName('shippingtracker');
86
+
87
+ $this->getMassactionBlock()->addItem('delete', array(
88
+ 'label' => Mage::helper('shippingtracker')->__('Delete'),
89
+ 'url' => $this->getUrl('*/*/massDelete'),
90
+ 'confirm' => Mage::helper('shippingtracker')->__('Are you sure?')
91
+ ));
92
+
93
+ $statuses = Mage::getSingleton('shippingtracker/status')->getOptionArray();
94
+
95
+ array_unshift($statuses, array('label'=>'', 'value'=>''));
96
+ $this->getMassactionBlock()->addItem('status', array(
97
+ 'label'=> Mage::helper('shippingtracker')->__('Change status'),
98
+ 'url' => $this->getUrl('*/*/massStatus', array('_current'=>true)),
99
+ 'additional' => array(
100
+ 'visibility' => array(
101
+ 'name' => 'status',
102
+ 'type' => 'select',
103
+ 'class' => 'required-entry',
104
+ 'label' => Mage::helper('shippingtracker')->__('Status'),
105
+ 'values' => $statuses
106
+ )
107
+ )
108
+ ));
109
+ return $this;
110
+ }
111
+
112
+ public function getRowUrl($row)
113
+ {
114
+ return $this->getUrl('*/*/edit', array('id' => $row->getId()));
115
+ }
116
+
117
+ }
app/code/local/Neo/Shippingtracker/Block/Shippingtracker.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Neo_Shippingtracker_Block_Shippingtracker extends Mage_Core_Block_Template
3
+ {
4
+ public function _prepareLayout()
5
+ {
6
+ return parent::_prepareLayout();
7
+ }
8
+
9
+ public function getShippingtracker()
10
+ {
11
+ if (!$this->hasData('shippingtracker')) {
12
+ $this->setData('shippingtracker', Mage::registry('shippingtracker'));
13
+ }
14
+ return $this->getData('shippingtracker');
15
+
16
+ }
17
+ }
app/code/local/Neo/Shippingtracker/Helper/Data.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Neo_Shippingtracker_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+
6
+ }
app/code/local/Neo/Shippingtracker/Model/Mysql4/Shippingtracker.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Neo_Shippingtracker_Model_Mysql4_Shippingtracker extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ // Note that the shippingtracker_id refers to the key field in your database table.
8
+ $this->_init('shippingtracker/shippingtracker', 'shippingtracker_id');
9
+ }
10
+ }
app/code/local/Neo/Shippingtracker/Model/Mysql4/Shippingtracker/Collection.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Neo_Shippingtracker_Model_Mysql4_Shippingtracker_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('shippingtracker/shippingtracker');
9
+ }
10
+ }
app/code/local/Neo/Shippingtracker/Model/Shippingtracker.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Neo_Shippingtracker_Model_Shippingtracker extends Mage_Core_Model_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('shippingtracker/shippingtracker');
9
+ }
10
+ }
app/code/local/Neo/Shippingtracker/Model/Status.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Neo_Shippingtracker_Model_Status extends Varien_Object
4
+ {
5
+ const STATUS_ENABLED = 1;
6
+ const STATUS_DISABLED = 2;
7
+
8
+ static public function getOptionArray()
9
+ {
10
+ return array(
11
+ self::STATUS_ENABLED => Mage::helper('shippingtracker')->__('Enabled'),
12
+ self::STATUS_DISABLED => Mage::helper('shippingtracker')->__('Disabled')
13
+ );
14
+ }
15
+ }
app/code/local/Neo/Shippingtracker/controllers/Adminhtml/ShippingtrackerController.php ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Neo_Shippingtracker_Adminhtml_ShippingtrackerController extends Mage_Adminhtml_Controller_action
4
+ {
5
+
6
+ protected function _initAction() {
7
+ $this->loadLayout()
8
+ ->_setActiveMenu('shippingtracker/items')
9
+ ->_addBreadcrumb(Mage::helper('adminhtml')->__('Items Manager'), Mage::helper('adminhtml')->__('Item Manager'));
10
+
11
+ return $this;
12
+ }
13
+
14
+ public function indexAction() {
15
+ $this->_initAction()
16
+ ->renderLayout();
17
+ }
18
+
19
+ public function editAction() {
20
+ $id = $this->getRequest()->getParam('id');
21
+ $model = Mage::getModel('shippingtracker/shippingtracker')->load($id);
22
+
23
+ if ($model->getId() || $id == 0) {
24
+ $data = Mage::getSingleton('adminhtml/session')->getFormData(true);
25
+ if (!empty($data)) {
26
+ $model->setData($data);
27
+ }
28
+
29
+ Mage::register('shippingtracker_data', $model);
30
+
31
+ $this->loadLayout();
32
+ $this->_setActiveMenu('shippingtracker/items');
33
+
34
+ $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item Manager'), Mage::helper('adminhtml')->__('Item Manager'));
35
+ $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item News'), Mage::helper('adminhtml')->__('Item News'));
36
+
37
+ $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
38
+
39
+ $this->_addContent($this->getLayout()->createBlock('shippingtracker/adminhtml_shippingtracker_edit'))
40
+ ->_addLeft($this->getLayout()->createBlock('shippingtracker/adminhtml_shippingtracker_edit_tabs'));
41
+
42
+ $this->renderLayout();
43
+ } else {
44
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('shippingtracker')->__('Item does not exist'));
45
+ $this->_redirect('*/*/');
46
+ }
47
+ }
48
+
49
+ public function newAction() {
50
+ $this->_forward('edit');
51
+ }
52
+
53
+ public function saveAction() {
54
+ if ($data = $this->getRequest()->getPost()) {
55
+
56
+ if(isset($_FILES['filename']['name']) && $_FILES['filename']['name'] != '') {
57
+ try {
58
+ /* Starting upload */
59
+ $uploader = new Varien_File_Uploader('filename');
60
+
61
+ // Any extention would work
62
+ $uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
63
+ $uploader->setAllowRenameFiles(false);
64
+
65
+ // Set the file upload mode
66
+ // false -> get the file directly in the specified folder
67
+ // true -> get the file in the product like folders
68
+ // (file.jpg will go in something like /media/f/i/file.jpg)
69
+ $uploader->setFilesDispersion(false);
70
+
71
+ // We set media as the upload dir
72
+ $path = Mage::getBaseDir('media') . DS ;
73
+ $uploader->save($path, $_FILES['filename']['name'] );
74
+
75
+ } catch (Exception $e) {
76
+
77
+ }
78
+
79
+ //this way the name is saved in DB
80
+ $data['filename'] = $_FILES['filename']['name'];
81
+ }
82
+
83
+
84
+ $model = Mage::getModel('shippingtracker/shippingtracker');
85
+ $model->setData($data)
86
+ ->setId($this->getRequest()->getParam('id'));
87
+
88
+ try {
89
+ if ($model->getCreatedTime == NULL || $model->getUpdateTime() == NULL) {
90
+ $model->setCreatedTime(now())
91
+ ->setUpdateTime(now());
92
+ } else {
93
+ $model->setUpdateTime(now());
94
+ }
95
+
96
+ $model->save();
97
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('shippingtracker')->__('Item was successfully saved'));
98
+ Mage::getSingleton('adminhtml/session')->setFormData(false);
99
+
100
+ if ($this->getRequest()->getParam('back')) {
101
+ $this->_redirect('*/*/edit', array('id' => $model->getId()));
102
+ return;
103
+ }
104
+ $this->_redirect('*/*/');
105
+ return;
106
+ } catch (Exception $e) {
107
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
108
+ Mage::getSingleton('adminhtml/session')->setFormData($data);
109
+ $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
110
+ return;
111
+ }
112
+ }
113
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('shippingtracker')->__('Unable to find item to save'));
114
+ $this->_redirect('*/*/');
115
+ }
116
+
117
+ public function deleteAction() {
118
+ if( $this->getRequest()->getParam('id') > 0 ) {
119
+ try {
120
+ $model = Mage::getModel('shippingtracker/shippingtracker');
121
+
122
+ $model->setId($this->getRequest()->getParam('id'))
123
+ ->delete();
124
+
125
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully deleted'));
126
+ $this->_redirect('*/*/');
127
+ } catch (Exception $e) {
128
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
129
+ $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
130
+ }
131
+ }
132
+ $this->_redirect('*/*/');
133
+ }
134
+
135
+ public function massDeleteAction() {
136
+ $shippingtrackerIds = $this->getRequest()->getParam('shippingtracker');
137
+ if(!is_array($shippingtrackerIds)) {
138
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select item(s)'));
139
+ } else {
140
+ try {
141
+ foreach ($shippingtrackerIds as $shippingtrackerId) {
142
+ $shippingtracker = Mage::getModel('shippingtracker/shippingtracker')->load($shippingtrackerId);
143
+ $shippingtracker->delete();
144
+ }
145
+ Mage::getSingleton('adminhtml/session')->addSuccess(
146
+ Mage::helper('adminhtml')->__(
147
+ 'Total of %d record(s) were successfully deleted', count($shippingtrackerIds)
148
+ )
149
+ );
150
+ } catch (Exception $e) {
151
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
152
+ }
153
+ }
154
+ $this->_redirect('*/*/index');
155
+ }
156
+
157
+ public function massStatusAction()
158
+ {
159
+ $shippingtrackerIds = $this->getRequest()->getParam('shippingtracker');
160
+ if(!is_array($shippingtrackerIds)) {
161
+ Mage::getSingleton('adminhtml/session')->addError($this->__('Please select item(s)'));
162
+ } else {
163
+ try {
164
+ foreach ($shippingtrackerIds as $shippingtrackerId) {
165
+ $shippingtracker = Mage::getSingleton('shippingtracker/shippingtracker')
166
+ ->load($shippingtrackerId)
167
+ ->setStatus($this->getRequest()->getParam('status'))
168
+ ->setIsMassupdate(true)
169
+ ->save();
170
+ }
171
+ $this->_getSession()->addSuccess(
172
+ $this->__('Total of %d record(s) were successfully updated', count($shippingtrackerIds))
173
+ );
174
+ } catch (Exception $e) {
175
+ $this->_getSession()->addError($e->getMessage());
176
+ }
177
+ }
178
+ $this->_redirect('*/*/index');
179
+ }
180
+
181
+ public function exportCsvAction()
182
+ {
183
+ $fileName = 'shippingtracker.csv';
184
+ $content = $this->getLayout()->createBlock('shippingtracker/adminhtml_shippingtracker_grid')
185
+ ->getCsv();
186
+
187
+ $this->_sendUploadResponse($fileName, $content);
188
+ }
189
+
190
+ public function exportXmlAction()
191
+ {
192
+ $fileName = 'shippingtracker.xml';
193
+ $content = $this->getLayout()->createBlock('shippingtracker/adminhtml_shippingtracker_grid')
194
+ ->getXml();
195
+
196
+ $this->_sendUploadResponse($fileName, $content);
197
+ }
198
+
199
+ protected function _sendUploadResponse($fileName, $content, $contentType='application/octet-stream')
200
+ {
201
+ $response = $this->getResponse();
202
+ $response->setHeader('HTTP/1.1 200 OK','');
203
+ $response->setHeader('Pragma', 'public', true);
204
+ $response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
205
+ $response->setHeader('Content-Disposition', 'attachment; filename='.$fileName);
206
+ $response->setHeader('Last-Modified', date('r'));
207
+ $response->setHeader('Accept-Ranges', 'bytes');
208
+ $response->setHeader('Content-Length', strlen($content));
209
+ $response->setHeader('Content-type', $contentType);
210
+ $response->setBody($content);
211
+ $response->sendResponse();
212
+ die;
213
+ }
214
+ }
app/code/local/Neo/Shippingtracker/controllers/IndexController.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Neo_Shippingtracker_IndexController extends Mage_Core_Controller_Front_Action
3
+ {
4
+ public function indexAction()
5
+ {
6
+ $this->getResponse()->setHeader('HTTP/1.1','404 Not Found');
7
+ $this->getResponse()->setHeader('Status','404 File not found');
8
+ $pageId = Mage::getStoreConfig('web/default/cms_no_route');
9
+ if (!Mage::helper('cms/page')->renderPage($this, $pageId)) {
10
+ $this->_forward('defaultNoRoute');
11
+ }
12
+ }
13
+ }
app/code/local/Neo/Shippingtracker/etc/config.xml ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Neo_Shippingtracker>
5
+ <version>0.1.0</version>
6
+ </Neo_Shippingtracker>
7
+ </modules>
8
+ <frontend>
9
+ <routers>
10
+ <shippingtracker>
11
+ <use>standard</use>
12
+ <args>
13
+ <module>Neo_Shippingtracker</module>
14
+ <frontName>shippingtracker</frontName>
15
+ </args>
16
+ </shippingtracker>
17
+ </routers>
18
+ <layout>
19
+ <updates>
20
+ <shippingtracker>
21
+ <file>shippingtracker.xml</file>
22
+ </shippingtracker>
23
+ </updates>
24
+ </layout>
25
+ </frontend>
26
+ <admin>
27
+ <routers>
28
+ <shippingtracker>
29
+ <use>admin</use>
30
+ <args>
31
+ <module>Neo_Shippingtracker</module>
32
+ <frontName>shippingtracker</frontName>
33
+ </args>
34
+ </shippingtracker>
35
+ </routers>
36
+ </admin>
37
+ <adminhtml>
38
+ <menu>
39
+ <shippingtracker module="shippingtracker">
40
+ <title>Shippingtracker</title>
41
+ <sort_order>71</sort_order>
42
+ <children>
43
+ <items module="shippingtracker">
44
+ <title>Manage Items</title>
45
+ <sort_order>0</sort_order>
46
+ <action>shippingtracker/adminhtml_shippingtracker</action>
47
+ </items>
48
+ </children>
49
+ </shippingtracker>
50
+ </menu>
51
+ <acl>
52
+ <resources>
53
+ <all>
54
+ <title>Allow Everything</title>
55
+ </all>
56
+ <admin>
57
+ <children>
58
+ <Neo_Shippingtracker>
59
+ <title>Shippingtracker Module</title>
60
+ <sort_order>10</sort_order>
61
+ </Neo_Shippingtracker>
62
+ </children>
63
+ </admin>
64
+ </resources>
65
+ </acl>
66
+ <layout>
67
+ <updates>
68
+ <shippingtracker>
69
+ <file>shippingtracker.xml</file>
70
+ </shippingtracker>
71
+ </updates>
72
+ </layout>
73
+ </adminhtml>
74
+ <global>
75
+ <models>
76
+ <shippingtracker>
77
+ <class>Neo_Shippingtracker_Model</class>
78
+ <resourceModel>shippingtracker_mysql4</resourceModel>
79
+ </shippingtracker>
80
+ <shippingtracker_mysql4>
81
+ <class>Neo_Shippingtracker_Model_Mysql4</class>
82
+ <entities>
83
+ <shippingtracker>
84
+ <table>shippingtracker</table>
85
+ </shippingtracker>
86
+ </entities>
87
+ </shippingtracker_mysql4>
88
+ </models>
89
+ <resources>
90
+ <shippingtracker_setup>
91
+ <setup>
92
+ <module>Neo_Shippingtracker</module>
93
+ </setup>
94
+ <connection>
95
+ <use>core_setup</use>
96
+ </connection>
97
+ </shippingtracker_setup>
98
+ <shippingtracker_write>
99
+ <connection>
100
+ <use>core_write</use>
101
+ </connection>
102
+ </shippingtracker_write>
103
+ <shippingtracker_read>
104
+ <connection>
105
+ <use>core_read</use>
106
+ </connection>
107
+ </shippingtracker_read>
108
+ </resources>
109
+ <blocks>
110
+ <shippingtracker>
111
+ <class>Neo_Shippingtracker_Block</class>
112
+ </shippingtracker>
113
+ </blocks>
114
+ <helpers>
115
+ <shippingtracker>
116
+ <class>Neo_Shippingtracker_Helper</class>
117
+ </shippingtracker>
118
+ </helpers>
119
+ </global>
120
+ </config>
app/code/local/Neo/Shippingtracker/sql/shippingtracker_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+ $installer->startSetup();
6
+
7
+ $installer->run("
8
+
9
+ -- DROP TABLE IF EXISTS {$this->getTable('shippingtracker')};
10
+ CREATE TABLE {$this->getTable('shippingtracker')} (
11
+ `shippingtracker_id` int(11) unsigned NOT NULL auto_increment,
12
+ `title` varchar(255) NOT NULL default '',
13
+ `filename` varchar(255) NOT NULL default '',
14
+ `content` text NOT NULL default '',
15
+ `status` smallint(6) NOT NULL default '0',
16
+ `created_time` datetime NULL,
17
+ `update_time` datetime NULL,
18
+ PRIMARY KEY (`shippingtracker_id`)
19
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
20
+
21
+ ");
22
+
23
+ $installer->endSetup();
app/design/adminhtml/default/default/layout/shippingtracker.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <shippingtracker_adminhtml_shippingtracker_index>
4
+ <reference name="content">
5
+ <block type="shippingtracker/adminhtml_shippingtracker" name="shippingtracker" />
6
+ </reference>
7
+ </shippingtracker_adminhtml_shippingtracker_index>
8
+ </layout>
app/design/adminhtml/default/default/template/sales/order/shipment/create/tracking.phtml ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-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 design
22
+ * @package default_default
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ *
26
+ * In this it comes first shipping tracking code is added (1 st part to add first shipping tracking code)
27
+ *
28
+ */
29
+ ?>
30
+ <?php /** @var $this Mage_Adminhtml_Block_Sales_Order_Shipment_Create_Tracking */ ?>
31
+ <script type="text/javascript">
32
+ //<![CDATA[
33
+ var trackingControl;
34
+ trackingControl = {
35
+ index : 0,
36
+ add : function () {
37
+ this.index++;
38
+ var data = {index:this.index};
39
+ Element.insert($('track_row_container'), {bottom: this.template.evaluate(data)});
40
+ $('trackingC' + this.index).disabled = false;
41
+ $('trackingT' + this.index).disabled = false;
42
+ $('trackingN' + this.index).disabled = false;
43
+ this.bindCurrierOnchange();
44
+ },
45
+ deleteRow : function(event) {
46
+ var row = Event.findElement(event, 'tr');
47
+ if (row) {
48
+ row.parentNode.removeChild(row)
49
+ }
50
+ },
51
+ bindCurrierOnchange : function() {
52
+ var elems = $('tracking_numbers_table').select('.select');
53
+ elems.each(function (elem) {
54
+ if (!elem.onchangeBound) {
55
+ elem.onchangeBound = true;
56
+ elem.valueInput = $(elem.parentNode.parentNode).select('.number-title')[0];
57
+ elem.observe('change', this.currierOnchange);
58
+ }
59
+ }.bind(this));
60
+ },
61
+ currierOnchange : function(event) {
62
+ var elem = Event.element(event);
63
+ var option = elem.options[elem.selectedIndex];
64
+ if (option.value && option.value != 'custom') {
65
+ elem.valueInput.value = option.text;
66
+ }
67
+ else {
68
+ elem.valueInput.value = '';
69
+ }
70
+ }
71
+ }
72
+ //]]>
73
+ </script>
74
+ <div class="grid">
75
+ <table cellspacing="0" class="data" id="tracking_numbers_table">
76
+ <col width="100" />
77
+ <col />
78
+ <col />
79
+ <col width="80" />
80
+ <thead>
81
+ <tr class="headings">
82
+ <th><?php echo Mage::helper('sales')->__('Carrier') ?></th>
83
+ <th><?php echo Mage::helper('sales')->__('Title') ?></th>
84
+ <th><?php echo Mage::helper('sales')->__('Number') ?> <span class="required">*</span></th>
85
+ <th class="last"><?php echo Mage::helper('sales')->__('Action') ?></th>
86
+ </tr>
87
+ </thead>
88
+ <tfoot>
89
+ <tr>
90
+ <td colspan="4" class="a-center last" style="padding:8px;"><?php echo $this->getChildHtml('add_button') ?></td>
91
+ </tr>
92
+ </tfoot>
93
+ <tbody id="track_row_container">
94
+ <tr id="track_row_template" class="template no-display">
95
+ <td>
96
+ <select name="tracking[__index__][carrier_code]" id="trackingC__index__" class="select carrier" style="width:110px;" disabled="disabled">
97
+ <?php foreach ($this->getCarriers() as $_code=>$_name): ?>
98
+ <?php if($_code != 'custom')
99
+ {
100
+ ?>
101
+ <option value="<?php echo $_code ?>"><?php echo $this->escapeHtml($_name) ?></option>
102
+ <?php
103
+ }
104
+ ?>
105
+ <?php endforeach; ?>
106
+ <?php $shipping_carrier_collection = Mage::getModel('shippingtracker/shippingtracker')->getCollection();?>
107
+ <?php foreach ($shipping_carrier_collection as $shipping_carrier_obj): ?>
108
+ <option value="<?php echo $shipping_carrier_obj->getId().':neotracker' ?>"><?php echo htmlentities($shipping_carrier_obj->getTitle()) ?></option>
109
+ <?php endforeach; ?>
110
+ </select>
111
+ </td>
112
+ <td><input class="input-text number-title" type="text" name="tracking[__index__][title]" id="trackingT__index__" value="" disabled="disabled" /></td>
113
+ <td><input class="input-text required-entry" type="text" name="tracking[__index__][number]" id="trackingN__index__" value="" disabled="disabled" /></td>
114
+ <td class="last"><a href="#" onclick="trackingControl.deleteRow(event);return false"><?php echo $this->__('Delete') ?></a></td>
115
+ </tr>
116
+ </tbody>
117
+ </table>
118
+ </div>
119
+ <script type="text/javascript">
120
+ //<![CDATA[
121
+ trackingControl.template = new Template('<tr>' + $('track_row_template').innerHTML.replace(/__index__/g, '#{index}') + '<\/tr>');
122
+ //]]>
123
+ </script>
app/design/frontend/default/default/template/email/order/shipment/track.phtml ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-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 design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <?php $_shipment=$this->getShipment() ?>
28
+ <?php $_order=$this->getOrder() ?>
29
+ <?php if ($_shipment && $_order && $_shipment->getAllTracks()): ?>
30
+ <table cellspacing="0" cellpadding="0" border="0" width="650" style="border:1px solid #EAEAEA;">
31
+ <thead>
32
+ <tr>
33
+ <th align="left" bgcolor="#EAEAEA" style="font-size:13px; padding:3px 9px"><?php echo $this->__('Shipped By') ?></th>
34
+ <th align="center" bgcolor="#EAEAEA" style="font-size:13px; padding:3px 9px"><?php echo $this->__('Tracking Number') ?></th>
35
+ </tr>
36
+ </thead>
37
+ <tbody>
38
+ <?php $i=0; foreach ($_shipment->getAllTracks() as $_item): $i++ ?>
39
+ <tr <?php echo $i%2?'bgcolor="#F6F6F6"':'' ?>>
40
+ <td align="left" valign="top" style="padding:3px 9px"><?php echo $_item->getTitle() ?></td>
41
+ <?php
42
+ $ship_col = Mage::getResourceModel('sales/order_shipment_track_collection')
43
+ -> addAttributeToFilter('track_number', $_item->getNumber())
44
+ -> load();
45
+ foreach ($ship_col as $sc) {
46
+ $trackMethod = $sc -> getCarrierCode();
47
+ }
48
+ $carrier_code_checker = strpos($trackMethod, 'neotracker');
49
+ if($carrier_code_checker !== false)
50
+ {
51
+ $carrier_code_result = explode(":", $trackMethod);
52
+ $carrier_code_collection = Mage::getModel('shippingtracker/shippingtracker')->load($carrier_code_result[0]);
53
+ $carrier_code_final_link = $carrier_code_collection->getContent();
54
+ echo '<td align="center" valign="top" style="padding:3px 9px"><strong><a target="_blank" style="text-decoration:none;" href="'.$carrier_code_final_link.'">'.$_item->getNumber().'</a></strong></td>';
55
+ }
56
+ else
57
+ {
58
+ ?>
59
+ <td align="center" valign="top" style="padding:3px 9px"><strong><?php echo $_item->getNumber() ?></strong></td>
60
+ <?php
61
+ }
62
+ ?>
63
+ </tr>
64
+ <?php endforeach ?>
65
+ </tbody>
66
+ </table>
67
+ <?php endif; ?>
app/etc/modules/Neo_Shippingtracker.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Neo_Shippingtracker>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </Neo_Shippingtracker>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>ShippingTracker</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL) </license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>It allows the admin to add custom shipping carrier with tracking number .</summary>
10
+ <description>It allows the admin to add shipping carrier with &#xD;
11
+ tracking number .&#xD;
12
+ &#xD;
13
+ &#xD;
14
+ The selected custom carrier details will be send &#xD;
15
+ through email with its respective tracking order &#xD;
16
+ link .&#xD;
17
+ &#xD;
18
+ Shown in customer dashboard on respective &#xD;
19
+ orders .</description>
20
+ <notes>Details reflected in shipping mail and PDF's</notes>
21
+ <authors><author><name>Nikhil K ravindran</name><user>nikhilkr</user><email>nikrmc@gmail.com</email></author></authors>
22
+ <date>2014-06-09</date>
23
+ <time>11:03:39</time>
24
+ <contents><target name="magelocal"><dir name="Mage"><dir name="Sales"><dir name="Model"><dir name="Order"><dir name="Pdf"><file name="Abstract.php" hash="198c4bfc6acc0f2815fc7e4fcf1f521e"/></dir></dir></dir></dir></dir><dir name="Neo"><dir name="Shippingtracker"><dir name="Block"><dir name="Adminhtml"><dir name="Shippingtracker"><dir name="Edit"><file name="Form.php" hash="288b1235868ef0d9e8c8ce1351655637"/><dir name="Tab"><file name="Form.php" hash="242cc515f063c877aba8f05d3aac3b3c"/></dir><file name="Tabs.php" hash="f23acffaf338071b9c1861a086b89534"/></dir><file name="Edit.php" hash="0da9aabc983239b0a215231cfdf60bd8"/><file name="Grid.php" hash="7275496234d2632a04408169d66e2a2c"/></dir><file name="Shippingtracker.php" hash="ff136e79a2981f51b61c7f9bee71ee43"/></dir><file name="Shippingtracker.php" hash="701814367d15235c6a9f379e1445c65f"/></dir><dir name="Helper"><file name="Data.php" hash="b3dfb21ac1c0369e87ad2124d2018a36"/></dir><dir name="Model"><dir name="Mysql4"><dir name="Shippingtracker"><file name="Collection.php" hash="0c94bc71190a2a4c3156ae8ce78f26c4"/></dir><file name="Shippingtracker.php" hash="094a4a8f12137733519087f83b1fa8b0"/></dir><file name="Shippingtracker.php" hash="4af406cf68ac9d604612288d8d6b570b"/><file name="Status.php" hash="a599c1c9ab1b270ca4931347028ed733"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="ShippingtrackerController.php" hash="f85d33c1fac705f4283c4e1bdff67f3a"/></dir><file name="IndexController.php" hash="f394ffb993d9b938cf5d8599eaf350b1"/></dir><dir name="etc"><file name="config.xml" hash="68e1d5012b7a280bd7a8da07d34da255"/></dir><dir name="sql"><dir name="shippingtracker_setup"><file name="mysql4-install-0.1.0.php" hash="0198c2fa123cf4268abd676217d82350"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="shippingtracker.xml" hash="36aec37a435d1e9dbaa3fe52f58df130"/></dir><dir name="template"><dir name="sales"><dir name="order"><dir name="shipment"><dir name="create"><file name="tracking.phtml" hash="3c278d96e990a37bcd8ecc494defcd90"/></dir></dir></dir></dir></dir></dir></dir></dir><dir name="sales"><dir name="order"><dir name="shipment"><dir name="view"><file name="tracking.phtml" hash=""/></dir></dir></dir></dir><dir name="frontend"><dir name="default"><dir name="default"><dir name="template"><dir name="email"><dir name="order"><dir name="shipment"><file name="track.phtml" hash="bda60d09fdad7858d612ac6898af6af8"/></dir></dir></dir></dir></dir></dir></dir><dir name="default"><dir name="default"><dir name="template"><dir name="shipping"><dir name="tracking"><file name="popup.phtml" hash=""/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Neo_Shippingtracker.xml" hash="cd1b41c882c1a237752cfebb08bd634c"/></dir></target></contents>
25
+ <compatible/>
26
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
27
+ </package>