VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: thebeuving on May 16, 2012, 23:18:18 PM

Title: Bug/feature request and patch: Set Default Country to match Shop Location
Post by: thebeuving on May 16, 2012, 23:18:18 PM
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]
Title: Re: Bug/feature request and patch: Set Default Country to match Shop Location
Post by: thebeuving on May 16, 2012, 23:19:31 PM
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/
Title: Re: Bug/feature request and patch: Set Default Country to match Shop Location
Post by: totallnet on May 20, 2012, 06:19:07 AM
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.

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
Title: Re: Bug/feature request and patch: Set Default Country to match Shop Location
Post by: thebeuving on May 21, 2012, 16:54:28 PM
What is the result for the inner query:

QuoteSELECT 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
Title: Re: Bug/feature request and patch: Set Default Country to match Shop Location
Post by: serapol on May 21, 2012, 20:16:49 PM
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

<?php echo $this->lists['published']; ?>


and after adding

<?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

$reqValues = array('select', 'multiselect', 'radio', 'multicheckbox');


and after adding

$ignoreName = array('virtuemart_country_id', 'virtuemart_state_id');


and change line

if (in_array($this->type, $reqValues) && $nrOfValues == 0) {


in the

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

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
Title: Re: Bug/feature request and patch: Set Default Country to match Shop Location
Post by: celticwebs on May 26, 2012, 14:20:00 PM
Quote from: serapol on May 21, 2012, 20:16:49 PM
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

<?php echo $this->lists['published']; ?>


and after adding

<?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

$reqValues = array('select', 'multiselect', 'radio', 'multicheckbox');


and after adding

$ignoreName = array('virtuemart_country_id', 'virtuemart_state_id');


and change line

if (in_array($this->type, $reqValues) && $nrOfValues == 0) {


in the

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

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
Title: Re: Bug/feature request and patch: Set Default Country to match Shop Location
Post by: webbits 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.