Author Topic: Bug/feature request and patch: Set Default Country to match Shop Location  (Read 3670 times)

thebeuving

  • Beginner
  • *
  • Posts: 30
Virtuemart 2.0.6 doesn't set the shops location to be the default country on check out. Since this was the functionality in VM1 and several people are requesting it I have created a patch to solve this problem in hopes that it could be put in the code base for the next release.

The 2 patches need to be applied to
administrator/components/com_virtuemart/models/userfields.php
and
administrator/components/com_virtuemart/controllers/user.php

Let me know if you have any questions.

Thanks,
David

[attachment cleanup by admin]
Founded in 2005, Khoza Technology, Inc. formerly SRI Hosting, Inc. is an IT services company with proven success building hosted services, applications, and websites.

https://khoza.com

thebeuving

  • Beginner
  • *
  • Posts: 30
Users can find a quick solution that doesn't require applying the patch here: http://srihosting.com/blog/2012/05/set-default-country-for-virtuemart-2/
Founded in 2005, Khoza Technology, Inc. formerly SRI Hosting, Inc. is an IT services company with proven success building hosted services, applications, and websites.

https://khoza.com

totallnet

  • Beginner
  • *
  • Posts: 3
thebeuving

Joomla 2.5.4
VM 2.0.6

In backend i set the shop location as Brazil and tried your both tips but failed.

Code: [Select]
UPDATE brsist_virtuemart_userfields SET `default`=(SELECT virtuemart_country_id FROM brsist_virtuemart_countries WHERE country_name='Brazil') WHERE name='virtuemart_country_id';
and then ... removing back the virtuemart_country_id to NULL tried uploading the 2 files..

What can i do ..

Thanks in advance

Kazuo

thebeuving

  • Beginner
  • *
  • Posts: 30
What is the result for the inner query:

Quote
SELECT virtuemart_country_id FROM brsist_virtuemart_countries WHERE country_name='Brazil';

If that is a valid number greater than 0 then it should have worked, I would suggest running the query again, my try clearing your browser cache before hitting the check out to make sure the defaults aren't being cached.

Thanks,
David
Founded in 2005, Khoza Technology, Inc. formerly SRI Hosting, Inc. is an IT services company with proven success building hosted services, applications, and websites.

https://khoza.com

serapol

  • Beginner
  • *
  • Posts: 43
There is a correct solution to this problem. In Virtuemart already incorporated this functionality but for some reason has not been used since the time of Virtuemart 1.0.

It is necessary to make two small changes
1. In the file administrator/components/com_virtuemart/views/userfields/tmpl/edit.php find the line
Code: [Select]
<?php echo $this->lists['published']; ?>

and after adding
Code: [Select]
<?php echo VmHTML::row('input','COM_VIRTUEMART_CUSTOM_DEFAULT','default',$this->userField->default,'class="inputbox"','',40); ?>

2. In the file administrator/components/com_virtuemart/tables/userfields.php find the line
Code: [Select]
$reqValues = array('select', 'multiselect', 'radio', 'multicheckbox');

and after adding
Code: [Select]
$ignoreName = array('virtuemart_country_id', 'virtuemart_state_id');

and change line
Code: [Select]
if (in_array($this->type, $reqValues) && $nrOfValues == 0) {

in the
Code: [Select]
if (in_array($this->type, $reqValues) && !in_array($this->name, $ignoreName) && $nrOfValues == 0) {

This change needs to be done because there is a check the availability of additional values ​​for the field type select, and in the fields of country and state we do not need

Since this functionality is not used for obvious reasons, the field does not default in the database, an int. It needs to be replaced with char(255), so that you can add default values ​​for each field type.
To execute the query in phpmyadmin
Code: [Select]
ALTER TABLE `PREFIX_virtuemart_userfields` CHANGE `default` `default` CHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL

Now that you appear at the bottom when editing custom fields, another option is "default", there you can write any value for any field. For fields of the country and state must be entered ID

celticwebs

  • Beginner
  • *
  • Posts: 45
There is a correct solution to this problem. In Virtuemart already incorporated this functionality but for some reason has not been used since the time of Virtuemart 1.0.

It is necessary to make two small changes
1. In the file administrator/components/com_virtuemart/views/userfields/tmpl/edit.php find the line
Code: [Select]
<?php echo $this->lists['published']; ?>

and after adding
Code: [Select]
<?php echo VmHTML::row('input','COM_VIRTUEMART_CUSTOM_DEFAULT','default',$this->userField->default,'class="inputbox"','',40); ?>

2. In the file administrator/components/com_virtuemart/tables/userfields.php find the line
Code: [Select]
$reqValues = array('select', 'multiselect', 'radio', 'multicheckbox');

and after adding
Code: [Select]
$ignoreName = array('virtuemart_country_id', 'virtuemart_state_id');

and change line
Code: [Select]
if (in_array($this->type, $reqValues) && $nrOfValues == 0) {

in the
Code: [Select]
if (in_array($this->type, $reqValues) && !in_array($this->name, $ignoreName) && $nrOfValues == 0) {

This change needs to be done because there is a check the availability of additional values ​​for the field type select, and in the fields of country and state we do not need

Since this functionality is not used for obvious reasons, the field does not default in the database, an int. It needs to be replaced with char(255), so that you can add default values ​​for each field type.
To execute the query in phpmyadmin
Code: [Select]
ALTER TABLE `PREFIX_virtuemart_userfields` CHANGE `default` `default` CHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL

Now that you appear at the bottom when editing custom fields, another option is "default", there you can write any value for any field. For fields of the country and state must be entered ID


Just so everybody knows you have to enter the country ID number I.e. US is 223 UK is 222 Aus is 13 etc  etc.  You can find these by checking them in the SQL under virtuemart_userfields

webbits

  • Beginner
  • *
  • Posts: 34
Re: Bug/feature request and patch: Set Default Country to match Shop Location
« Reply #6 on: November 10, 2012, 14:23:29 pm »
Simplest solution found here:  https://forum.virtuemart.net/index.php?topic=101294.0

Directions to set default in database, no hacks required.