Author Topic: [OUTDATED] Setting up VirtueMart 1.1.2 for Australian stores  (Read 18514 times)

Das123

  • Beginner
  • *
  • Posts: 21
    • Design Solutions - Creative Consultancy & Studio
[OUTDATED] Setting up VirtueMart 1.1.2 for Australian stores
« on: August 14, 2008, 03:20:10 am »
EDIT:
This has been updated here...
http://forum.virtuemart.net/index.php?topic=54517.0


VirtueMart is a great shopping cart but it doesn't really cater for Australian businesses. I've set up a number of stores in Australia and most of the time it is a matter of patching information into templates etc here and there. Not a very good way to operate. I wrote a guide for VirtueMart 1.0.? but some of the information doesn't work well on 1.1.?.

With this in mind I thought I would try to make small changes to the code to get a simplified structure that can be changed from the admin panel. In the end it was quite complicated but it gets the job done.

Overview:

First of all, we need to cater for ABNs as legally this should be on any tax invoice. Other samples have created ABN entries in the language files, but I would prefer this to be in the database with the rest of the vendor information.
Similarly, I want to simply select 'Australian GST' from the admin panel rather than just patch templates and code here and there all the time (the patching still needs to be done, but the selection in the admin panel feels better).
Finally, tax and shipping should be simple.

I'm going to write this in two sections. Initially I'll go through the minimum steps you need to take to get the job done. Before we start, if you don't know how to FTP files or how to run SQL commands in your database, turn back now. This will be too difficult for you. Otherwise, read on. :)

In the second part of this guide I'll go through the specific changes I have made to the code so that future versions of VirtueMart can be easily patched as well (this was made for version 1.1.2).

I've tested it and it works for me, but I can't make any promises. Back everything up before you start - just in case.

So, into the fray!


10 Steps to Australian Compliance

1. Install VirtueMart on your website.

2. Download the zip file attached to this post.

3. Extract and replace the corresponding files in the VirtueMart component backend (path in zip file is from the /administrator/components/ directory).

4. Run the following SQL command into your Joomla database to put a field for the ABN:
ALTER TABLE `jos_vm_vendor` ADD `vendor_abn` VARCHAR( 32 ) NULL AFTER `vendor_store_name` ;

5. Log in to the VirtueMart Admin.

6. In Store -> Edit Store
  a. Fill in the details for the vendor. Make sure default currencies etc are correct. Make sure country is correct (for tax defaults).
  b. Put ABN in address format:
{storename}
ABN: {abn}
etc etc

  c. Fill in other details as you like.

7. In Admin -> Configuration
  Under Price Configuration
  a. Tick Show "(including XX% tax)" when applicable?
  b. Select Tax Mode: Australian GST mode
  c. Select other settings as you like.

8. In Tax -> List Tax Rates
  a. Remove default tax rate that comes with VirtuMart.
  b. Add tax rate -> Australia, No state, .10.

9. In Store -> Shipping Module List
  Configure the AusPost module. Make sure the tax rate is the 10% rate you just made.

10. Put in your categories and products etc.

Job done! Not too difficult once you're past step 4. ;D

[attachment cleanup by admin]

Das123

  • Beginner
  • *
  • Posts: 21
    • Design Solutions - Creative Consultancy & Studio
Re: Setting up VirtueMart 1.1.2 for Australian stores
« Reply #1 on: August 14, 2008, 03:20:53 am »

Now, whats gone on under the hood? Only read on if you want to tweak code. :o All these files are found in the VirtueMart component in the backend (/administrator/components/com_virtuemart), not in the frontend component.
Remember, line numbers are for version 1.1.2 so most likely will change in the future.

global.php

This file sets up global variables for VirtueMart and we need to have our ABN included in the list.

$vendor_abn = $db->f("vendor_abn");
is inserted into line 171:

Code: [Select]
$_SESSION['minimum_pov'] = $db->f("vendor_min_pov");
$vendor_name = $db->f("vendor_name");
$vendor_store_name = $db->f("vendor_store_name");
$vendor_abn = $db->f("vendor_abn");
$vendor_mail = $db->f("contact_email");
$vendor_url = $db->f("vendor_url");

classes/htmlTools.Class.php

This file is a general formatting class with many different roles. We want to make sure the ABN can be formatted with the address.

$store_address = str_replace( '{abn}', @$address_details['abn'], $store_address );
is inserted into line 1436:

Code: [Select]
function vmFormatAddress( $address_details, $use_html=false ) {
global $vendor_address_format;

$store_address = str_replace( '{storename}', @$address_details['name'], $vendor_address_format );
$store_address = str_replace( '{abn}', @$address_details['abn'], $store_address );
$store_address = str_replace( '{address_1}', @$address_details['address_1'], $store_address );
$store_address = str_replace( '{address_2}', @$address_details['address_2'], $store_address );

classes/ps_vendor.php

This class controls the vendor information. We need to add our ABN details in multiple places.

'vendor_abn' => $d["vendor_abn"],
is inserted into the database INSERT array in line 186

Code: [Select]
$fields = array( 'vendor_name' => $d["vendor_name"],
...
'vendor_store_name' => $d["vendor_store_name"],
'vendor_abn' => $d["vendor_abn"],
'vendor_store_desc' => $d["vendor_store_desc"],
'vendor_category_id' => $d["vendor_category_id"],

and again...
'vendor_abn' => $d["vendor_abn"],
is inserted into the database UPDATE array in line 271

Code: [Select]
$fields = array( 'vendor_name' => $d["vendor_name"],
...
'vendor_store_name' => $d["vendor_store_name"],
'vendor_abn' => $d["vendor_abn"],
'vendor_store_desc' => $d["vendor_store_desc"],
'vendor_thumb_image' => $d["vendor_thumb_image"],

vendor_abn field needs to be part of the SELECT statement on line 441

Code: [Select]
function get_vendor_details($vendor_id) {
$db = new ps_DB();
$q = "SELECT vendor_id, vendor_min_pov, vendor_name, vendor_store_name, vendor_abn, contact_email,vendor_full_image, vendor_freeshipping,
vendor_address_1,vendor_address_2, vendor_url, vendor_city, vendor_state, vendor_country, country_2_code, country_3_code,
vendor_zip, vendor_phone, vendor_store_desc, vendor_currency, vendor_currency_display_style,

$vendor_abn needs to be declared a global on line 608

$address_details['abn'] = $vendor_abn;
is inserted in line 612

Code: [Select]
function formatted_store_address( $use_html=false ) {
global $vendor_store_name, $vendor_abn, $vendor_address, $vendor_address_2, $vendor_city, $vendor_state_name,
$vendor_state, $vendor_zip, $vendor_phone, $vendor_fax, $vendor_mail, $vendor_country, $vendor_url;

$address_details['name'] = $vendor_store_name;
$address_details['abn'] = $vendor_abn;
$address_details['address_1'] = $vendor_address;
$address_details['address_2'] = $vendor_address_2;

classes/ps_checkout.php

This class controls the checkout process. We want to include rules for Australian GST in the mix.

Code: [Select]
case '13':
if (! array_key_exists ('country', $auth)) {
$vmLogger->debug ('shopper\'s country is not known; defaulting to vendor-based tax');
return true;
}

$vmLogger->debug ('shopper is in ' . $auth['country']);
return ps_checkout::country_in_aust_gst_zone ($auth['country']);

is inserted in the _tax_based_on_vendor_address function at line 2291. I used '13' because this the AUS number from the databse. It could have been anything. This basically says that if the shopper has a country, use it, if not use the vendor's country (Australia) for displaying tax etc. Much cleaner than specifying either Vendor or Shipping addresses as the trigger.

Code: [Select]
function country_in_aust_gst_zone ($country) {
$eu_countries = array ('AUS');
return in_array ($country, $eu_countries);
}

is inserted at line 2315. This is the function that checks if vendor is Australian (make sure you have set up the vendor information correctly in the admin backend).

So the full functions in context:

Code: [Select]
function _tax_based_on_vendor_address () {
global $auth;
global $vmLogger;

switch (TAX_MODE) {
case '0':
return false;

case '1':
return true;

case '13':
if (! array_key_exists ('country', $auth)) {
$vmLogger->debug ('shopper\'s country is not known; defaulting to vendor-based tax');
return true;
}

$vmLogger->debug ('shopper is in ' . $auth['country']);
return ps_checkout::country_in_aust_gst_zone ($auth['country']);

case '17749':
if (! array_key_exists ('country', $auth)) {
$vmLogger->debug ('shopper\'s country is not known; defaulting to vendor-based tax');
return true;
}

$vmLogger->debug ('shopper is in ' . $auth['country']);
return ps_checkout::country_in_eu_common_vat_zone ($auth['country']);

default:
$vmLogger->warning ('unknown TAX_MODE "' . TAX_MODE . '"');
return true;
}
}

function country_in_aust_gst_zone ($country) {
$eu_countries = array ('AUS');
return in_array ($country, $eu_countries);
}

html/store.store_form.php

This is the html format for the Store information in the backend. We need to include the ABN in the form.

Code: [Select]
    <tr>
      <td class="labelcell"><?php echo $VM_LANG->_('PHPSHOP_STORE_FORM_COMPANY_ABN'?>:</td>
      <td width="78%" >
        <input type="text" class="inputbox" name="vendor_abn" value="<?php $db->sp("vendor_abn"?>" size="32" />
      </td>
    </tr>

is inserted at line 61, between the PHPSHOP_STORE_FORM_COMPANY_NAME and PHPSHOP_PRODUCT_FORM_URL input dialogs.

<strong>{abn}</strong>: '.$VM_LANG->_('PHPSHOP_STORE_FORM_COMPANY_ABN').'<br />
is inserted into the tooltip in line 122

Code: [Select]
echo vmToolTip($VM_LANG->_('PHPSHOP_STORE_ADDRESS_FORMAT_TIP') . ':<br />
        <strong>{storename}</strong>: '.$VM_LANG->_('PHPSHOP_STORE_FORM_STORE_NAME').'<br />
        <strong>{abn}</strong>: '.$VM_LANG->_('PHPSHOP_STORE_FORM_COMPANY_ABN').'<br />
        <strong>{address_1}</strong>: '.$VM_LANG->_('PHPSHOP_STORE_FORM_ADDRESS_1').'<br />
        <strong>{address_2}</strong>: '.$VM_LANG->_('PHPSHOP_STORE_FORM_ADDRESS_2').'<br />

html/admin.show_cfg.php

This is the format for the Store Configuration in the backend. We want to put Australian GST into the tax made drop-down list.

<option value="13" <?php if (TAX_MODE == 13) echo 'selected="selected"'; ?>>
<?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_TAX_MODE_GST') ?>
</option>

is inserted in line 253.

Code: [Select]
<select name="conf_TAX_MODE" class="inputbox">
<option value="0" <?php if (TAX_MODE == 0) echo 'selected="selected"'?>>
<?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_TAX_MODE_SHIP'?>
</option>
<option value="1" <?php if (TAX_MODE == 1) echo 'selected="selected"'?>>
<?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_TAX_MODE_VENDOR'?>
</option>
<option value="13" <?php if (TAX_MODE == 13) echo 'selected="selected"'?>>
<?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_TAX_MODE_GST'?>
</option>
<option value="17749" <?php if (TAX_MODE == 17749) echo 'selected="selected"'?>>
<?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_TAX_MODE_EU'?>
</option>
</select>

languages/store/english.php

The language files provide language reference throughout the cart.

'PHPSHOP_STORE_FORM_COMPANY_ABN' => 'Store A.B.N.',
is inserted at line 41

languages/admin/english.php

'PHPSHOP_ADMIN_CFG_TAX_MODE_GST' => 'Australian GST mode',
is inserted at line 246

languages/common/english.php

Various changes throughout file to update the terms to GST and to show 'Tax Invoice'. No additional references added to the file.

classes/shipping/auspost[.ini|.php|.cfg.php]

No change from Virtuit version 1.05. See post http://forum.virtuemart.net/index.php?topic=39653.0 for link and details.

I hope nothing is missing. And I hope this helps others who are struggling with this cart trying to get GST compliance for Australian stores.  :)

Ozpoker

  • Beginner
  • *
  • Posts: 22
Re: Setting up VirtueMart 1.1.2 for Australian stores
« Reply #2 on: August 14, 2008, 04:50:49 am »
You've no idea how timely this was

Awesome - thanks so much

emp

  • Beginner
  • *
  • Posts: 4
Re: Setting up VirtueMart 1.1.2 for Australian stores
« Reply #3 on: August 19, 2008, 01:15:49 am »
Thank you, very timely and very helpful :)

One question you might be able to help we with, where do I change the words '(including 10 % tax)' that appear on the product details page to: (including 10% GST).

Cheers
Emily
 

Das123

  • Beginner
  • *
  • Posts: 21
    • Design Solutions - Creative Consultancy & Studio
Re: Setting up VirtueMart 1.1.2 for Australian stores
« Reply #4 on: August 19, 2008, 01:33:17 am »
That's funny. I thought I had changed that in the files. It should be inside the languages/common/english.php file. :)

emp

  • Beginner
  • *
  • Posts: 4
Re: Setting up VirtueMart 1.1.2 for Australian stores
« Reply #5 on: August 19, 2008, 02:10:59 am »
Thanks, have fixed it now, it was the line:
'PHPSHOP_INCLUDING_TAX' => '(including $tax % tax)', that needed changing.

Thanks so much
Emily

mirarm

  • Beginner
  • *
  • Posts: 1
Re: Setting up VirtueMart 1.1.2 for Australian stores
« Reply #6 on: August 24, 2008, 19:52:07 pm »
This is great but appears for Joomla 1.0 any clues for 1.5??
Cheers
Ian

Das123

  • Beginner
  • *
  • Posts: 21
    • Design Solutions - Creative Consultancy & Studio
Re: Setting up VirtueMart 1.1.2 for Australian stores
« Reply #7 on: August 25, 2008, 02:48:14 am »
I haven't put VirtueMart into a Joomla 1.5 site yet. I'm not sure of the code differences.

aldochiu

  • Beginner
  • *
  • Posts: 11
Re: Setting up VirtueMart 1.1.2 for Australian stores
« Reply #8 on: August 29, 2008, 16:47:40 pm »
Thanks Das123! This is so good! I have been looking around about this for long.

I am very new to Joomla as well as VM. hope I can learn them fast in there!

Of cox, if you have tested your codes/tweaks with joomla 1.56, please let us know if that works, too!

Thanks again!

Ozpoker

  • Beginner
  • *
  • Posts: 22
Re: Setting up VirtueMart 1.1.2 for Australian stores
« Reply #9 on: September 02, 2008, 02:38:53 am »
Okay - I've stuffed something up soemehwere here - it stalls at the shipper section of the checkout

http://www.afflicted.com.au/joomshop/index.php

Anyone care to help ?

Ozpoker

  • Beginner
  • *
  • Posts: 22
Re: Setting up VirtueMart 1.1.2 for Australian stores
« Reply #10 on: September 02, 2008, 05:42:54 am »
Also the price is not adding 10% to it.

It says GST included but regardless of whether I set VAT id to 10% or not the ordinary net original price is still displayed.

Virtual Tax : On
Tax Mode : Australian GST Mode

Is this the way it is supposed to work - Am I supposed to enter all prices GST inclusive ?

Das123

  • Beginner
  • *
  • Posts: 21
    • Design Solutions - Creative Consultancy & Studio
Re: Setting up VirtueMart 1.1.2 for Australian stores
« Reply #11 on: September 02, 2008, 21:36:03 pm »
Try the process with debug mode turned on. It can give clues as to what is happening.

Also, make sure you have fully setup the shop details in the configuration. If the shipping module and GST don't know your location they won't work.

Ozpoker

  • Beginner
  • *
  • Posts: 22
Re: Setting up VirtueMart 1.1.2 for Australian stores
« Reply #12 on: September 03, 2008, 02:17:02 am »
What am I looking for ?

This product is $35 - VAT id is 4 (which is 10%) Gross price shows $38.50 in this product page - But displays on site as $35 (GST Inclusive) ?



[attachment cleanup by admin]

Ozpoker

  • Beginner
  • *
  • Posts: 22
Re: Setting up VirtueMart 1.1.2 for Australian stores
« Reply #13 on: September 03, 2008, 02:46:14 am »
ahhh- it's okay - it was an issue with the defauclt test user that is installed with the sample files

peebee

  • Beginner
  • *
  • Posts: 11
Re: Setting up VirtueMart 1.1.2 for Australian stores
« Reply #14 on: October 20, 2008, 08:18:52 am »
I just signed up to the forum for no other reason than wanting to say thanks to Das123.  Followed your instruction and the process worked seemlessly.  I started the changes myself and then stumbled across your post.  You have saved me hours of work that I really wasn't looking forward to.  Highly recommended for anyone trying to install an Australian ATO/GST compliant Virtuemart store.  Thanks again.