VasiliiB_CustomerInvoices - Version 1.0.0

Version Notes

The first delivery of the module.

Download this release

Release Info

Developer Vasilii
Extension VasiliiB_CustomerInvoices
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/local/VasiliiB/CustomerInvoices/Block/Index.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class VasiliiB_CustomerInvoices_Block_Index extends Mage_Core_Block_Template
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->setTemplate('customer/account/invoices.phtml');
9
+
10
+ $this->setInvoices( $this->getAllInvoices() );
11
+ }
12
+
13
+ public function getAllInvoices()
14
+ {
15
+ $invoices = Mage::getResourceModel('sales/order_invoice_collection');
16
+ $select = $invoices->getSelect();
17
+ $select->joinLeft(array('order' => Mage::getModel('core/resource')->getTableName('sales/order')), 'order.entity_id=main_table.order_id', array('customer_id' => 'customer_id'));
18
+ $customerId = Mage::getSingleton('customer/session')->getCustomer()->getId();
19
+ $invoices->addFieldToFilter('customer_id',$customerId);
20
+ return $invoices;
21
+ }
22
+
23
+ protected function _prepareLayout()
24
+ {
25
+ parent::_prepareLayout();
26
+
27
+ $pager = $this->getLayout()->createBlock('page/html_pager', 'invoices.pager');
28
+ $pager->setAvailableLimit(array(10=>10, 15=>15, 30=>30, $this->getInvoices()->getSize() => $this->__('All') ));
29
+ $pager->setCollection( $this->getInvoices() );
30
+
31
+ $this->setChild('pager', $pager);
32
+ $this->getInvoices()->load();
33
+
34
+ return $this;
35
+ }
36
+
37
+ public function getPagerHtml()
38
+ {
39
+ return $this->getChildHtml('pager');
40
+ }
41
+ }
app/code/local/VasiliiB/CustomerInvoices/controllers/CustomerInvoiceController.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class VasiliiB_CustomerInvoices_CustomerInvoiceController extends Mage_Core_Controller_Front_Action {
3
+
4
+ public function indexAction() {
5
+ $this->loadLayout();
6
+ $this->getLayout()->getBlock("head")->setTitle($this->__("Invoices"));
7
+ $breadcrumbs = $this->getLayout()->getBlock("breadcrumbs");
8
+ $breadcrumbs->addCrumb("home", array(
9
+ "label" => $this->__("Home Page"),
10
+ "title" => $this->__("Home Page"),
11
+ "link" => Mage::getBaseUrl()
12
+ ));
13
+
14
+ $breadcrumbs->addCrumb("customer-invoices", array(
15
+ "label" => $this->__("Invoices"),
16
+ "title" => $this->__("Invoices")
17
+ ));
18
+ $this->renderLayout();
19
+ }
20
+
21
+
22
+ public function viewAction() {
23
+ $orderId = (int) $this->getRequest()->getParam('order_id');
24
+ $order = Mage::getModel('sales/order')->load($orderId);
25
+
26
+ if ($this->_canViewOrder($order)) {
27
+ $invoices = Mage::getResourceModel('sales/order_invoice_collection')
28
+ ->setOrderFilter($order->getId())
29
+ ->load();
30
+ if ($invoices->getSize() > 0) {
31
+ $pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf($invoices);
32
+
33
+ return $this->_prepareDownloadResponse(
34
+ 'invoice-'.Mage::getSingleton('core/date')->date('Y-m-d_H-i-s').'.pdf', $pdf->render(),
35
+ 'application/pdf'
36
+ );
37
+
38
+ }
39
+ }
40
+ }
41
+
42
+ public function preDispatch()
43
+ {
44
+ parent::preDispatch();
45
+ $action = $this->getRequest()->getActionName();
46
+ $loginUrl = Mage::helper('customer')->getLoginUrl();
47
+
48
+ if (!Mage::getSingleton('customer/session')->authenticate($this, $loginUrl)) {
49
+ $this->setFlag('', self::FLAG_NO_DISPATCH, true);
50
+ }
51
+ }
52
+
53
+ protected function _canViewOrder($order)
54
+ {
55
+ $customerId = Mage::getSingleton('customer/session')->getCustomerId();
56
+ $availableStates = Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates();
57
+ if ($order->getId() && $order->getCustomerId() && ($order->getCustomerId() == $customerId)
58
+ && in_array($order->getState(), $availableStates, $strict = true)
59
+ ) {
60
+ return true;
61
+ }
62
+ return false;
63
+ }
64
+ }
app/code/local/VasiliiB/CustomerInvoices/etc/config.xml ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <VasiliiB_CustomerInvoices>
5
+ <version>1.0.0</version>
6
+ </VasiliiB_CustomerInvoices>
7
+ </modules>
8
+
9
+ <frontend>
10
+ <routers>
11
+ <vasiliib>
12
+ <use>standard</use>
13
+ <args>
14
+ <module>VasiliiB_CustomerInvoices</module>
15
+ <frontName>vasiliib</frontName>
16
+ </args>
17
+ </vasiliib>
18
+ </routers>
19
+
20
+ <layout>
21
+ <updates>
22
+ <vasiliib>
23
+ <file>customerinvoices.xml</file>
24
+ </vasiliib>
25
+ </updates>
26
+ </layout>
27
+ </frontend>
28
+
29
+ <global>
30
+ <blocks>
31
+ <invoices>
32
+ <class>VasiliiB_CustomerInvoices_Block</class>
33
+ </invoices>
34
+ </blocks>
35
+ </global>
36
+ </config>
app/design/frontend/base/default/layout/customerinvoices.xml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+
4
+ <customer_account>
5
+ <reference name="customer_account_navigation">
6
+ <action method="addLink" translate="label">
7
+ <name>customerinvoices</name>
8
+ <path>vasiliib/customerInvoice</path>
9
+ <label>My Invoices</label>
10
+ </action>
11
+ </reference>
12
+ </customer_account>
13
+
14
+ <vasiliib_customerinvoice_index translate="label">
15
+ <label>Customer Invoices</label>
16
+ <update handle="customer_account"/>
17
+
18
+ <reference name="my.account.wrapper">
19
+ <block type="invoices/index" name="customer.invoices" template="customer/account/invoices.phtml"/>
20
+ </reference>
21
+ </vasiliib_customerinvoice_index>
22
+
23
+ </layout>
app/design/frontend/base/default/template/customer/account/invoices.phtml ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div id="customer-invoices">
2
+ <?php if( $this->getInvoices()->getSize() ): ?>
3
+
4
+ <div class="page-title">
5
+ <h1><?php echo $this->__('My Invoices'); ?></h1>
6
+ </div>
7
+
8
+ <div class="toolbar"><?php echo $this->getPagerHtml(); ?></div>
9
+ <table id="invoices-table" class="data-table">
10
+ <thead>
11
+ <tr>
12
+ <th><strong><?php echo $this->__('Invoice Number'); ?></strong></th>
13
+ <th><strong><?php echo $this->__('Invoice Date'); ?></strong></th>
14
+ <th><?php echo $this->__('Order #'); ?></th>
15
+ <th><?php echo $this->__('Order Date'); ?></th>
16
+ <th width="15%"><?php echo $this->__('Actions'); ?></th>
17
+ </tr>
18
+ </thead>
19
+ <?php
20
+ foreach( $this->getInvoices() as $invoice): ?>
21
+ <tr>
22
+ <td>
23
+ <?php echo $invoice->getIncrementId(); ?>
24
+ </td>
25
+ <td>
26
+ <?php echo $invoice->getCreatedAt(); ?>
27
+ </td>
28
+ <td>
29
+ <a href="<?php echo $this->getUrl('sales/order/view', array('order_id' => $invoice->getOrder()->getId())); ?>">
30
+ <?php echo $invoice->getOrder()->getRealOrderId(); ?>
31
+ </a>
32
+ </td>
33
+ <td>
34
+ <?php echo $invoice->getOrder()->getCreatedAt(); ?>
35
+ </td>
36
+ <td>
37
+ <a href="<?php echo $this->getUrl('best4u/customerInvoice/view',
38
+ array('order_id' => $invoice->getOrder()->getId())); ?>">
39
+ <i class="fa fa-file-pdf-o"></i>
40
+ <?php echo $this->__('Create PDF'); ?>
41
+ </a>
42
+ &nbsp; | &nbsp;
43
+ <a href="<?php echo $this->getUrl('sales/order/invoice', array('order_id' => $invoice->getOrder()->getId()))
44
+ ?>">
45
+ <i class="fa fa-eye"></i>
46
+ <?php echo $this->__('View'); ?>
47
+ </a>
48
+ </td>
49
+ </tr>
50
+ <?php endforeach;
51
+ ?>
52
+ </table>
53
+ <div class="toolbar toolbar-bottom"><?php echo $this->getPagerHtml(); ?></div>
54
+ <?php else: ?>
55
+ <p class="notice-msg"><?php echo $this->__('No invoices'); ?></p>
56
+ <?php endif; ?>
57
+ </div>
app/etc/modules/VasiliiB_CustomerInvoices.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <VasiliiB_CustomerInvoices>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </VasiliiB_CustomerInvoices>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>VasiliiB_CustomerInvoices</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>OSL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Allow customers to view list of invoices and download Invoice PDF files.</summary>
10
+ <description>Allow customers to view list of invoices and download Invoice PDF files.</description>
11
+ <notes>The first delivery of the module.</notes>
12
+ <authors><author><name>Vasilii</name><user>vasiliib</user><email>burlacu.vasilii@yandex.ru</email></author></authors>
13
+ <date>2016-06-26</date>
14
+ <time>19:04:44</time>
15
+ <contents><target name="magelocal"><dir><dir name="VasiliiB"><dir name="CustomerInvoices"><dir name="Block"><file name="Index.php" hash="d697118ce5620b715e1caa0f749bc9ae"/></dir><dir name="controllers"><file name="CustomerInvoiceController.php" hash="05f1814f4aa54728cdefbc30c49bedeb"/></dir><dir name="etc"><file name="config.xml" hash="092d7cad826bba69151a861f65fc57f1"/></dir></dir></dir></dir></target><target name="magedesign"><dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="customerinvoices.xml" hash="78c280bd13a1fe75e1b464d6f33a306f"/></dir><dir name="template"><dir name="customer"><dir name="account"><file name="invoices.phtml" hash="4146a436bc9b5cc20e67075b40d1873e"/></dir></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir><dir name="modules"><file name="VasiliiB_CustomerInvoices.xml" hash="b5334bd488fab9eb3fd69af1e774a23a"/></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.6.0</min><max>7.7.0</max></php></required></dependencies>
18
+ </package>