News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

How to create a new view in Virtuemart 3

Started by its4yougr, March 01, 2017, 09:00:17 AM

Previous topic - Next topic

its4yougr

Hi
I would like to create two new views called invoice and receipt where there will be an invoice like form which will display different data concerning the chosen order. I have defined a user field (selectable) for either invoice or receipt. So when a user during checkout process selects either invoice or a receipt he will be able to get/print his invoice or receipt by going to the list of his orders. Now at the file /components/com_virtuemart/views/orders/tmpl/list.php, where there is the list of all orders, I have made some changes and next to every order there is a button which, depending on the user's choice (invoice or receipt), has either the value of invoice or receipt and of course could point to a different url with a different view.

I tried creating a new view following the instructions here http://network.convergenceservices.in/forum/46-virtue-mart/1630-creating-a-new-view-in-virtuemart-20-or-greater.html w/o any success.... I have also searched the forum for some detailed instructions w/o any luck. The instructions here https://forum.virtuemart.net/index.php?topic=118974.0 don't work either. I get error 500 on both cases.....

The way I call the new view is  http://domain_name/index.php?option=com_virtuemart&view=invoices&layout=details&order_number=5 where invoices is the new view.

My Joomla 3.6.5 and my VM 3.0.18.

Is there some detailed instructions on how to create a new view?

I think that I could do my job using two different layouts. Is there some detailed instructions on how to create two different layouts?

Could you please help? I am stuck...
Thank you in advance.
Κατασκευή Ιστοσελίδων Θεσσαλονίκη - http://www.its4you.gr/
WebDesign Internet Marketing - http://www.webdesign-internetmarketing.com/

Studio 42

You can use vmextend plugin, to create completly new views and
function onVmSiteController() in your plugin to full manage all without trouble.
Do not use an existing Vm view for the plugin name eg. invoice cannot be used.
But "receipt" or "invoices"

For eg this is my "push" plugin minimal code to do it work, i have developed.
<?php
defined
('_JEXEC') or  die( '' ) ;
class 
plgVmextendedPush extends JPlugin

function onVmSiteController($controller){
if($controller !== 'push') {
return;
}
// here your own code

}
}


the file have to be JOOMLAROOT\plugins\vmextended\push\push.php
and of course push.xml need
<extension version="3.1" type="plugin" group="vmextended" method="upgrade">
the other parts are same as any Joomla plugin


its4yougr

Hi Studio 42 and thank you very much for your reply ! !
What I have done so far is :
1. Created a file invoices.php inside /plugins/vmextended/invoices/ with the following code:

<?php
defined
('_JEXEC') or  die( '' ) ;
class 
plgVmextendedInvoices extends JPlugin

function onVmSiteController($controller){
if($controller !== 'invoices') {
return;
}
// here your own code

}
}


2. Created a file invoices.xml inside /plugins/vmextended/invoices/ with the following code:

<?xml version="1.0" encoding="UTF-8" ?>
<extension version="3.1" type="plugin" group="vmextended" method="upgrade">
    <name>Invoices</name>
    <creationDate>March 05 2017</creationDate>
    <author>Internet Technology Solutions</author>
    <authorUrl>http://www.its4you.gr</authorUrl>
    <copyright>Copyright (C) 2017 Internet Technology Solutions. All rights reserved.</copyright>
    <license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
    <version>1.0</version>
    <description>Invoices Plugin for Virtuemart</description>
    <files>
        <filename plugin="invoices">invoices.php</filename>
        <folder>invoices</folder>
    </files>
    <params addpath="/plugins/vmextended/invoices"/>
</extension>


3. I created a directory tmpl under /plugins/vmextended/invoices/ and inside there I created a file named default.php with the following code:

<?php
defined
('_JEXEC') or die('Restricted access');
$user JFactory::getUser();

if(
$user->id !=$this->item->company->userId){
$app JFactory::getApplication();
$app->redirect(JURI::root());
}
$newDate date("d-m-Y"strtotime($this->item->created));
$newTime date("H:i"strtotime($this->item->created));
?>


<h4 style="text-align:center"><?php echo JText::_("LNG_ORDER_INVOICE_DETAILS")?></h4>
<table style="width: 100%; margin-left: auto; margin-right: auto;">
<tbody>
<tr>
<td><img src="images/-site/logo-plain.jpg" alt="" /></td>
<td style="text-align:left;">
<p><strong>ΣΕΙΡΑ A</strong><br />
<b><?php echo JText::_('LNG_NUMBER'); ?>: </b> <?php echo $this->item->id ?><br />
<b><?php echo JText::_('LNG_DATE'); ?>: </b><?php echo $newDate ?><br /><b><?php echo JText::_('LNG_TIME'); ?>: </b><?php echo $newTime ?></p>
</td>
</tr>
</tbody>
</table>
<div>
<div style="font-size:16px; font-weight:bold;">
<p>&nbsp;</p>
<p>Παπαδόπουλος Παντελής<br/>
Υπηρεσίες Εκπαίδευσης<br/>
Αλμπάνη 128<br/>
Κιφισιά<br/>
ΑΦΜ : 5558970251<br/>
ΔΟΥ : Α' Αθηνών<br/>
ΤΗΛ : 2310 235984<br/>
</span></p>
<br /><br />
</div>

</div>

Please note the code is not checked if it works OK..... I took this code from another part of the website. This is something that I did in order to check how the plugin works so that it displays some info....

4. I went into the backend and using Discover from Extensions > Manage > Discover it found the new plugin and from there I 've installed it.

Now what..... How do I test the new view? How does this will work?

When I  try the url:  http://domain_name/index.php?option=com_virtuemart&view=invoices I get the message "View not found [name, type, prefix]: invoices, html, virtuemartView"

I am sure I am doing something wrong so please enlighten me. How can I go from here so that I will be able to get the url to the code of the default.php file under /plugins/vmextended/invoices/tmpl/default.php?

Thank you in advance
Κατασκευή Ιστοσελίδων Θεσσαλονίκη - http://www.its4you.gr/
WebDesign Internet Marketing - http://www.webdesign-internetmarketing.com/

Studio 42

You need to add all the logic if you want use MVC, inside the function onVmSiteController($controller){
eg you can include a controller loading a model and a view.
Or you can extend vmExtendedPlugin to have Virtuemart core possibility to use tmpl/default.php
if (!class_exists('vmExtendedPlugin ')) require(JPATH_VM_PLUGINS . DS . 'vmextendedplugin.php');
class plgVmextendedInvoices extends vmExtendedPlugin


its4yougr

Thanks again for your prompt reply ! !
   As you might already understood I am not a programmer and I don't really understand what you are saying. So please bear with me.....
Where do I put the code you just posted?

What I would like to achieve is:
1. The user during checkout process makes a selection Receipt or Invoice at a defined user field tax_document. So on the db table jos_virtuemart_order_userinfos I have the type of document he chose for every of his orders.
2. When this user goes to the List Orders of Virtuemart (http://domain_name/index.php?option=com_virtuemart&view=orders) have a button same as the button "Print Order" (http://domain_name/index.php?option=com_virtuemart&view=orders&layout=details&order_number=) which will have two different views one for Invoice and one for Receipt.
3. Checking on the field tax_document on the db table jos_virtuemart_order_userinfos I have the info and using a condition I can display different text and have different link behind the button next to the order on the list view of orders. I already have done that.

How do I create these two different views (Invoice & Receipt) and what will be the two urls that I conditionally set into the Invoice or Receipt button next to each order?

If the above procedure is feasible using your method with the vmExtendedPlugin how to I go from here?

Please note that I can give you access to the website and you can just do a start for me. I can populate the two different form with the output of the db fields that I need. Of course you will get paid for that. Please give me a price quote for just doing a start for me.

Thank you in advance
Κατασκευή Ιστοσελίδων Θεσσαλονίκη - http://www.its4you.gr/
WebDesign Internet Marketing - http://www.webdesign-internetmarketing.com/

Studio 42

It's not so easy, because you need to populate the view with some values depending your needs, i have do a private message.