Lema21_CustomExport - Version 0.9.0

Version Notes

Beta version

Download this release

Release Info

Developer Marcelo Linhares
Extension Lema21_CustomExport
Version 0.9.0
Comparing to
See all releases


Version 0.9.0

app/code/local/Lema21/CustomExport/Helper/Data.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Lema21_CustomExport_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+
6
+ /**
7
+ * Get array of itens in template line
8
+ *
9
+ * @return array
10
+ */
11
+ public static function loadTemplate()
12
+ {
13
+ $io = new Varien_Io_File();
14
+
15
+ $pathToTile = Mage::getBaseDir('app') . DS .
16
+ 'code/local/Lema21/CustomExport/Template/template.csv';
17
+
18
+ // load csv
19
+ $contentTemplate = file_get_contents($pathToTile);
20
+
21
+ $templateLine = explode("|", $contentTemplate);
22
+
23
+ return $templateLine;
24
+ }
25
+ }
app/code/local/Lema21/CustomExport/Model/Observer.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Lema21_CustomExport_Model_Observer {
4
+
5
+ public function includeOption($observer)
6
+ {
7
+ // Get code of grid
8
+ $idBlockObserver = $observer->getEvent()->getBlock()->getId();
9
+
10
+ if ($idBlockObserver=="sales_order_grid" ) {
11
+
12
+ // copy+paste by "delete orders" module, thanks Stefan Wieczorek
13
+ $block = $observer->getEvent()
14
+ ->getBlock()
15
+ ->getMassactionBlock();
16
+
17
+ if ($block) {
18
+ $block->addItem('custom_export', array(
19
+ 'label'=> Mage::helper('custom_export')->__('Custom Export Data to CSV'),
20
+ 'url' => Mage::getUrl('lema21_custom_export', array('_secure'=>true)),
21
+ ));
22
+ }
23
+ }
24
+ }
25
+
26
+ }
app/code/local/Lema21/CustomExport/Service/GenerateCSV.php ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Lema21_CustomExport_Service_GenerateCSV {
4
+
5
+ private $_orderIds;
6
+ private $_collectionOrders;
7
+ private $_contentCSV;
8
+
9
+ public function __construct($ordersId) {
10
+ $this->_orderIds = $ordersId;
11
+ }
12
+
13
+ private function _loadOrderObjects()
14
+ {
15
+ $this->_collectionOrders = array();
16
+
17
+ foreach($this->_orderIds as $id) {
18
+ $instance = Mage::getModel("sales/order")->load($id);
19
+ array_push($this->_collectionOrders, $instance);
20
+ }
21
+ }
22
+
23
+ private function _prepareData($templateLine)
24
+ {
25
+ $this->_contentCSV = "";
26
+
27
+ //iterate on the orders selected
28
+ foreach($this->_collectionOrders as $order) {
29
+
30
+ $lineItem = "";
31
+
32
+ // iterate on the itens in template
33
+ foreach($templateLine as $t) {
34
+
35
+ // order.increment_id => $order->getData("increment_id");
36
+ // getAttributeByCode($attribute, $order)
37
+ $item = "";
38
+ list($object, $attribute) = explode(".", $t);
39
+
40
+ switch($object) {
41
+
42
+ case "order":
43
+
44
+ $item = $order->getData($attribute);
45
+ break;
46
+
47
+ case "customer":
48
+
49
+ if ($attribute=="name") {
50
+ $item = $order->getData("customer_firstname") . " " .
51
+ $order->getData("customer_lastname");
52
+ } else {
53
+ $item = $order->getData("customer_{$attribute}");
54
+ }
55
+
56
+ break;
57
+
58
+ case "address":
59
+
60
+ $address = $order->getShippingAddress();
61
+
62
+ if (strpos($attribute, "street_")!==false) {
63
+ $street = explode("_", $attribute);
64
+ $item = $address->getStreet($street[1]);
65
+ } else {
66
+ $item = $address->getData($attribute);
67
+ }
68
+
69
+ break;
70
+ }
71
+
72
+ $lineItem.="{$item},";
73
+ }
74
+
75
+ // endline
76
+ $this->_contentCSV .=$lineItem ."\n";
77
+ }
78
+ }
79
+
80
+ public function call()
81
+ {
82
+ $this->_loadOrderObjects();
83
+
84
+ $templateLine = Mage::helper("custom_export")->loadTemplate();
85
+
86
+ $this->_prepareData($templateLine);
87
+
88
+ return $this->_contentCSV;
89
+ }
90
+
91
+ }
app/code/local/Lema21/CustomExport/Template/template.csv ADDED
@@ -0,0 +1 @@
 
1
+ order.increment_id|order.status|order.created_at|customer.name|customer.email|customer.taxvat|address.street_1|address.street_2|address.street_3|address.street_4|address.city|address.region|address.postcode|address.telephone|order.shipping_description
app/code/local/Lema21/CustomExport/controllers/IndexController.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ require_once 'Mage/Adminhtml/controllers/Sales/OrderController.php';
5
+
6
+ class Lema21_CustomExport_IndexController
7
+ extends Mage_Adminhtml_Sales_OrderController {
8
+
9
+ const FILENAME = 'custom_orders.csv';
10
+
11
+ public function indexAction()
12
+ {
13
+
14
+ $post = $this->getRequest()->getPost();
15
+
16
+ $orderIdsList = $post['order_ids'];
17
+
18
+ $serviceGenerateCSV = new Lema21_CustomExport_Service_GenerateCSV($orderIdsList);
19
+ $contentCSV = $serviceGenerateCSV->call();
20
+
21
+ $this->_prepareDownloadResponse(self::FILENAME, $contentCSV);
22
+ }
23
+ }
app/code/local/Lema21/CustomExport/etc/config.xml ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Lema21_CustomExport>
5
+ <version>0.9</version>
6
+ </Lema21_CustomExport>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <custom_export>
11
+ <class>Lema21_CustomExport_Model</class>
12
+ </custom_export>
13
+ </models>
14
+ <helpers>
15
+ <custom_export>
16
+ <class>Lema21_CustomExport_Helper</class>
17
+ </custom_export>
18
+ </helpers>
19
+ </global>
20
+ <admin>
21
+ <routers>
22
+ <Lema21_CustomExport>
23
+ <use>admin</use>
24
+ <args>
25
+ <module>Lema21_CustomExport</module>
26
+ <frontName>lema21_custom_export</frontName>
27
+ </args>
28
+ </Lema21_CustomExport>
29
+ </routers>
30
+ </admin>
31
+ <adminhtml>
32
+ <events>
33
+ <adminhtml_block_html_before>
34
+ <observers>
35
+ <option_in_custom_export>
36
+ <class>custom_export/Observer</class>
37
+ <method>includeOption</method>
38
+ </option_in_custom_export>
39
+ </observers>
40
+ </adminhtml_block_html_before>
41
+ </events>
42
+
43
+ <translate>
44
+ <modules>
45
+ <qualquer_id_unico_aqui>
46
+ <files>
47
+ <default>Lema21_CustomExport.csv</default>
48
+ </files>
49
+ </qualquer_id_unico_aqui>
50
+ </modules>
51
+ </translate>
52
+ </adminhtml>
53
+ </config>
app/etc/modules/Lema21_CustomExport.xml ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Lema21
5
+ * @category Lema21
6
+ * @package Lema21_CustomExport
7
+ * @copyright Copyright (c) 2010-2011 Unicode Systems. (http://www.unicodesystems.in)
8
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
9
+
10
+ Module to export orders to custom CSV
11
+
12
+ CSV template file available in Lema21/CustomExport/Template/template.csv
13
+
14
+ Possible Entities: order|customer|address
15
+
16
+ Example:
17
+ order.increment_id | order.status | order.grand_total | customer.email
18
+
19
+ */-->
20
+ <config>
21
+ <modules>
22
+ <Lema21_CustomExport>
23
+ <active>true</active>
24
+ <codePool>local</codePool>
25
+ </Lema21_CustomExport>
26
+ </modules>
27
+ </config>
app/locale/pt_BR/Lema21_CustomExport.csv ADDED
@@ -0,0 +1 @@
 
1
+ "Custom Export Data to CSV","Exportar pedidos para Controle"
package.xml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Lema21_CustomExport</name>
4
+ <version>0.9.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="https://github.com/lema21/magent_custom_export">GNU General Public License (GPL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Module to export sales in Magento to custom CSV</summary>
10
+ <description>With this module is possible to export sales in custom CSV!&#xD;
11
+ &#xD;
12
+ &#xD;
13
+ Possible Entities to export: order|customer|address&#xD;
14
+ &#xD;
15
+ Example (file Template/template.csv):&#xD;
16
+ &#xD;
17
+ order.increment_id | order.status | order.grand_total | customer.email</description>
18
+ <notes>Beta version</notes>
19
+ <authors><author><name>Marcelo Linhares</name><user>marcelolinhares</user><email>marcelolinhares@gmail.com</email></author></authors>
20
+ <date>2013-05-30</date>
21
+ <time>02:44:01</time>
22
+ <contents><target name="magelocal"><dir name="Lema21"><dir name="CustomExport"><dir name="Helper"><file name="Data.php" hash="1747c5c9e93a060724c8164c6e0ba322"/></dir><dir name="Model"><file name="Observer.php" hash="108f09a1ab28ea5d0b1e60685284a0b3"/></dir><dir name="Service"><file name="GenerateCSV.php" hash="d468e43d84bb9718b35688efeec70518"/></dir><dir name="Template"><file name="template.csv" hash="9b009f1f2aff39761d6e39f5ce670d70"/></dir><dir name="controllers"><file name="IndexController.php" hash="e93200cbf72dc408e5c08cf026b1a950"/></dir><dir name="etc"><file name="config.xml" hash="effcb99ff4b2f9af9a4e3fc9d48b4c85"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Lema21_CustomExport.xml" hash="e1dd042ae15ca61db6eeaa766c2db125"/></dir></target><target name="magelocale"><dir name="pt_BR"><file name="Lema21_CustomExport.csv" hash="3fd135fcccb6beedcb8462c2898c6ab3"/></dir></target></contents>
23
+ <compatible/>
24
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
25
+ </package>