0

一部の電子商取引サイトの国、都市、州、および郵便番号を含めたいのですが、次のようにしたいのです。特定の国を選択すると、その特定の国の都市のみがリストされます。都市が選択されると、その都市の州がドロップダウンに表示され、都市が選択されると、その都市の郵便番号がドロップダウンに表示されます。Google で検索しましたが、信頼できるリンクが見つかりません。誰でもリンクや提案を手伝ってくれます。どんな助けでも大歓迎です。私の現在のコードに感謝します:

<form class="clearboth" name="form" action="" method="post" onSubmit="return sign_up(this);">
    <input type="hidden" name="action" value="<?php echo $_GET['action']?>" />
     <h1>New User: Sign Up</h1>
               <ul class="input_field">
               <li><label>Username <span>*</span></label>
                <input name="username" class="input_textarea" id="username" size="25" req="1" valimessage="Username cannot be blank" 
                      valiclass="required" />
                        </li>   
               <li><label>First Name <span>*</span></label>
                   <input name="first_name" class="input_textarea" id="first_name" size="25" req="1" 
                      valimessage="First name cannot be blank" 
                      valiclass="required" />
                 </li>
               <li><label>Last Name <span>*</span></label>
                 <input name="last_name" class="input_textarea" id="last_name" size="25" req="1" valimessage="Last name cannot be blank" 
                      valiclass="required" />
                </li>
                   <li><label>Street address <span>*</span></label>
                    <input name="address1" class="input_textarea" id="address1" size="25" req="1" valimessage="Street Address cannot be blank" 
                      valiclass="required" />
                      </li>
                 <li><label>Street address 2</label>
                 <input name="address2" class="input_textarea" id="address2" size="25" />
                  </li>
                   <li><label>City <span>*</span></label>
                           <input name="city" class="input_textarea" id="city" size="25" req="1" valimessage="City cannot be blank" 
                      valiclass="required" />
                   </li>
                    <li><label>Country <span>*</span></label>
                          <select name="country" class="input_textarea">
                                <option 
                        value="NA">Please Select</option>
                                <option>Afghanistan</option>
                                <option>Albania</option>
                                <option>Algeria</option>
                                <option>American Samoa</option>
                                <option>Andorra</option>
                                <option>Angola</option>
                                <option>Anguilla</option>
                                <option>Antarctica</option>
                                <option>Antigua and Barbuda</option>
                                <option>Argentina</option>
                                <option>Armenia</option>
                                <option>Aruba</option>
                                <option>Australia</option>
                                <option>Austria</option>
                                <option>Azerbaijan</option>
                                <option>Bahamas</option>
                                <option>Bahrain</option>
                                <option>Bangladesh</option>
                                <option>Barbados</option>
                                <option>Belarus</option>
                                <option>Belgium</option>
                                <option>Belize</option>
                                <option>Benin</option>
                                <option>Bermuda</option>
                                <option>Bhutan</option>
                                <option>Bolivia</option>
                                <option>Bosnia and Herzegowina</option>
                                <option>Botswana</option>
                                <option>Bouvet Island</option>
                                <option>Brazil</option>
                                <option>British Indian Ocean Territory</option>
                                <option>Brunei Darussalam</option>
                                <option>Bulgaria</option>
                                <option>Burkina Faso</option>
                                <option>Burundi</option>
                                <option>Cambodia</option>
                                <option>Cameroon</option>
                                <option>Canada</option>
                                <option>Cape Verde</option>
                                <option>Cayman Islands</option>
                                <option>Central African Republic</option>
                                <option>Chad</option>
                                <option>Chile</option>
                                <option>China</option>
                                <option>Christmas Island</option>
                                <option>Cocos (Keeling)Islands</option>
                                <option>Colombia</option>
                                <option>Comoros</option>
                                <option>Congo</option>
                                <option>Cook Islands</option>
                                <option>Costa Rica</option>
                                <option>Cote D'Ivoire</option>
                                <option>Croatia</option>
                                <option>Cuba</option>
                                <option>Cyprus</option>
                                <option>Czech 
                                  Republic</option>
                                <option>Denmark</option>
                                <option>Djibouti</option>
                                <option>Dominica</option>
                                <option>Dominican 
                                  Republic</option>
                                <option>East Timor</option>
                                <option>Ecuador</option>
                                <option>Egypt</option>
                                <option>El Salvador</option>
                                <option>Equatorial 
                                  Guinea</option>
                                <option>Eritrea</option>
                                <option>Estonia</option>
                                <option>Ethiopia</option>
                                <option>Falkland 
                                  Islands (Malvinas)</option>
                                <option>Faroe 
                                  Islands</option>
                                <option>Fiji</option>
                                <option>Finland</option>
                                <option>France</option>
                                <option>France, Metropolitan</option>
                                <option>French Guiana</option>
                                <option>French 
                                  Polynesia</option>
                                <option>French Southern 
                                  Territories</option>
                                <option>Gabon</option>
                                <option>Gambia</option>
                                <option>Georgia</option>
                                <option>Germany</option>
                                <option>Ghana</option>
                                <option>Gibraltar</option>
                                <option>Greece</option>
                                <option>Greenland</option>
                                <option>Grenada</option>
                                <option>Guadeloupe</option>
                                <option>Guam</option>
                                <option>Guatemala</option>
                                <option>Guinea</option>
                                <option>Guinea-bissau</option>
                                <option>Guyana</option>
                                <option>Haiti</option>
                                <option>Heard and Mc Donald Islands</option>
                                <option>Honduras</option>
                                <option>Hong 
                                  Kong</option>
                                <option>Hungary</option>
                                <option>Iceland</option>
                                <option>India</option>
                                <option>Indonesia</option>
                                <option>Iran (Islamic 
                                  Republic of)</option>
                                <option>Iraq</option>
                                <option>Ireland</option>
                                <option>Israel</option>
                                <option>Italy</option>
                                <option>Jamaica</option>
                                <option>Japan</option>
                                <option>Jordan</option>
                                <option>Kazakhstan</option>
                                <option>Kenya</option>
                                <option>Kiribati</option>
                                <option>Korea, Democratic People's Republic 
                                  of</option>
                                <option>Korea, Republic of</option>
                                <option>Kuwait</option>
                                <option>Kyrgyzstan</option>
                                <option>Lao People's 
                                  Democratic Republic</option>
                                <option>Latvia</option>
                                <option>Lebanon</option>
                                <option>Lesotho</option>
                                <option>Liberia</option>
                                <option>Libyan Arab 
                                  Jamahiriya</option>
                                <option>Liechtenstein</option>
                                <option>Lithuania</option>
                                <option>Luxembourg</option>
                                <option>Macau</option>
                                <option>Macedonia, The 
                                  Former Yugoslav Republic of</option>
                                <option>Madagascar</option>
                                <option>Malawi</option>
                                <option>Malaysia</option>
                                <option>Maldives</option>
                                <option>Mali</option>
                                <option>Malta</option>
                                <option>Marshall 
                                  Islands</option>
                                <option>Martinique</option>
                                <option>Mauritania</option>
                                <option>Mauritius</option>
                                <option>Mayotte</option>
                                <option>Mexico</option>
                                <option>Micronesia, Federated States of</option>
                                <option>Moldova, Republic of</option>
                                <option>Monaco</option>
                                <option>Mongolia</option>
                                <option>Montserrat</option>
                                <option>Morocco</option>
                                <option>Mozambique</option>
                                <option>Myanmar</option>
                                <option>Namibia</option>
                                <option>Nauru</option>
                                <option>Nepal</option>
                                <option>Netherlands</option>
                                <option>Netherlands 
                                  Antilles</option>
                                <option>New Caledonia</option>
                                <option>New Zealand</option>
                                <option>Nicaragua</option>
                                <option>Niger</option>
                                <option>Nigeria</option>
                                <option>Niue</option>
                                <option>Norfolk 
                                  Island</option>
                                <option>Northern Mariana 
                                  Islands</option>
                                <option>Norway</option>
                                <option>Oman</option>
                                <option>Pakistan</option>
                                <option>Palau</option>
                                <option>Panama</option>
                                <option>Papua New Guinea</option>
                                <option>Paraguay</option>
                                <option>Peru</option>
                                <option>Philippines</option>
                                <option>Pitcairn</option>
                                <option>Poland</option>
                                <option>Portugal</option>
                                <option>Puerto 
                                  Rico</option>
                                <option>Qatar</option>
                                <option>Reunion</option>
                                <option>Romania</option>
                                <option>Russian 
                                  Federation</option>
                                <option>Rwanda</option>
                                <option>Saint Kitts and Nevis</option>
                                <option>Saint Lucia</option>
                                <option>Saint 
                                  Vincent and the Grenadines</option>
                                <option>Samoa</option>
                                <option>San 
                                  Marino</option>
                                <option>Sao Tome and 
                                  Principe</option>
                                <option>Saudi Arabia</option>
                                <option>Senegal</option>
                                <option>Seychelles</option>
                                <option>Sierra 
                                  Leone</option>
                                <option>Singapore</option>
                                <option>Slovakia (Slovak Republic)</option>
                                <option>Slovenia</option>
                                <option>Solomon 
                                  Islands</option>
                                <option>Somalia</option>
                                <option>South Africa</option>
                                <option>South 
                                  Georgia and the South Sandwich Islands</option>
                                <option>Spain</option>
                                <option>Sri 
                                  Lanka</option>
                                <option>St. Helena</option>
                                <option>St. Pierre and Miquelon</option>
                                <option>Sudan</option>
                                <option>Suriname</option>
                                <option>Svalbard and Jan Mayen Islands</option>
                                <option>Swaziland</option>
                                <option>Sweden</option>
                                <option>Switzerland</option>
                                <option>Syrian Arab 
                                  Republic</option>
                                <option>Taiwan, Province of 
                                  China</option>
                                <option>Tajikistan</option>
                                <option>Tanzania, United Republic of</option>
                                <option>Thailand</option>
                                <option>Togo</option>
                                <option>Tokelau</option>
                                <option>Tonga</option>
                                <option>Trinidad and Tobago</option>
                                <option>Tunisia</option>
                                <option>Turkey</option>
                                <option>Turkmenistan</option>
                                <option>Turks and 
                                  Caicos Islands</option>
                                <option>Tuvalu</option>
                                <option>Uganda</option>
                                <option>Ukraine</option>
                                <option>United Arab Emirates</option>
                                <option>United Kingdom</option>
                                <option 
                        selected="selected">United States</option>
                                <option>United 
                                  States Minor Outlying Islands</option>
                                <option>Uruguay</option>
                                <option>Uzbekistan</option>
                                <option>Vanuatu</option>
                                <option>Vatican City 
                                  State (Holy See)</option>
                                <option>Venezuela</option>
                                <option>Viet 
                                  Nam</option>
                                <option>Virgin Islands 
                                  (British)</option>
                                <option>Virgin Islands 
                                  (U.S.)</option>
                                <option>Wallis and Futuna 
                                  Islands</option>
                                <option>Western Sahara</option>
                                <option>Yemen</option>
                                <option>Yugoslavia</option>
                                <option>Zaire</option>
                                <option>Zambia</option>
                                <option>Zimbabwe</option>
                            </select>
                    </li>
                   <li><label>State <span>*</span></label>
                    <select name="us_state" class="input_textarea">
                                <option value="NA" 
                        selected="selected">Please Select</option>
                                <option>Alabama</option>
                                <option>Alaska</option>
                                <option>American Samoa</option>
                                <option>Arizona</option>
                                <option>Arkansas</option>
                                <option>Armed Forces 
                                  Africa</option>
                                <option>Armed Forces 
                                  Americas</option>
                                <option>Armed Forces 
                                  Canada</option>
                                <option>Armed Forces 
                                  Europe</option>
                                <option>Armed Forces Middle 
                                  East</option>
                                <option>Armed Forces 
                                  Pacific</option>
                                <option>California</option>
                                <option>Colorado</option>
                                <option>Connecticut</option>
                                <option>Delaware</option>
                                <option>District of 
                                  Columbia</option>
                                <option>Federated States Of 
                                  Micronesia</option>
                                <option>Florida</option>
                                <option>Georgia</option>
                                <option>Guam</option>
                                <option>Hawaii</option>
                                <option>Idaho</option>
                                <option>Illinois</option>
                                <option>Indiana</option>
                                <option>Iowa</option>
                                <option>Kansas</option>
                                <option>Kentucky</option>
                                <option>Louisiana</option>
                                <option>Maine</option>
                                <option>Marshall 
                                  Islands</option>
                                <option>Maryland</option>
                                <option>Massachusetts</option>
                                <option>Michigan</option>
                                <option>Minnesota</option>
                                <option>Mississippi</option>
                                <option>Missouri</option>
                                <option>Montana</option>
                                <option>Nebraska</option>
                                <option>Nevada</option>
                                <option>New 
                                  Hampshire</option>
                                <option>New Jersey</option>
                                <option>New Mexico</option>
                                <option>New 
                                  York</option>
                                <option>North Carolina</option>
                                <option>North Dakota</option>
                                <option>Northern 
                                  Mariana Islands</option>
                                <option>Ohio</option>
                                <option>Oklahoma</option>
                                <option>Oregon</option>
                                <option>Palau</option>
                                <option>Pennsylvania</option>
                                <option>Puerto 
                                  Rico</option>
                                <option>Rhode Island</option>
                                <option>South Carolina</option>
                                <option>South 
                                  Dakota</option>
                                <option>Tenessee</option>
                                <option>Texas</option>
                                <option>Utah</option>
                                <option>Vermont</option>
                                <option>Virgin 
                                  Islands</option>
                                <option>Virginia</option>
                                <option>Washington</option>
                                <option>West 
                                  Virginia</option>
                                <option>Wisconsin</option>
                                <option>Wyoming</option>
                            </select>
                   </li>         

                         <li><label>Zip Code <span>*</span></label>
                    <input name="zip" class="input_textarea" id="zip" size="25" req="1" 
                      valimessage="Invalid Zip code" 
                  valiclass="zip" />
                  </li>
                   <li><label>Phone</label>
                      <input name="phone" class="input_textarea" id="phone" size="25" />
                   </li>
                    <li><label>Fax</label>
                   <input name="fax" class="input_textarea" id="fax" size="25" />
                 </li>
                           <li><label>Email address<span>*</span></label>
                      <input name="email" class="input_textarea" id="email" size="25" req="1" 
                      valimessage="Invalid email address" 
                      valiclass="email" />
                 </li>
                           <li><label>Password <span>*</span></label>
                         <input name="password" type="password" class="input_textarea" id="password" size="25" req="4" 
                      valimessage="not sufficent password lenghth" 
                      valiclass="required" />
                      </li>
                           <li><label>Verify Password</label>
                           <input name="password2" type="password" class="input_textarea" id="password2" size="25" />
                        </li>
                        <li><label>&nbsp;</label>* indicates required fields.</li>

                          <li><label>&nbsp;</label>
                          <input type="submit" value="Sign up" name="btn_signup"  class="red_btn"/>
                          </li>
                          </ul>

4

1 に答える 1

0

私はあなたがMagento 1.7.0.2で言ったことをしただけですが、拡張機能としてはしていません。汚い方法のようです。

私は AU のためにそれを行います。私が行うことは次 の
とおりです。
base\default\template\persistent\checkout\onepage\billing.phtml の下部にあるこれらのコード:

    <script type="text/javascript">
jQuery(document).ready(function(){
CountryListener();
jQuery('#billing\\:country_id').change(function() {
CountryListener();
});     
});

var OriginalBillingCity = '<?php echo $this->escapeHtml($this->getAddress()->getCity()); ?>';
var OriginalBillingPostcode = '<?php echo $this->escapeHtml($this->getAddress()->getPostcode()); ?>';
function CountryListener()
{
var selectVal = jQuery('#billing\\:country_id option:selected').val();
if(selectVal == "AU"){
jQuery('#billing\\:region_id').change(function() {      ////add select change listener          
StateToCityList();
});
jQuery("#billing\\:city")
.replaceWith('<select id="billing:city" name="billing[city]" class="required-entry"><option value="">Select the State first, then you have options</option></select>');
jQuery("#billing\\:postcode")
.replaceWith('<select id="billing:postcode" name="billing[postcode]"><option value="">Please select the City first</option></select>');
}else{
jQuery("#billing\\:city")
.replaceWith('<input type="text" class="input-text required-entry absolute-advice" title="City" value="' + OriginalBillingCity + '" id="billing:city" name="billing[city]" autocomplete="off">');
jQuery("#billing\\:postcode")
.replaceWith('<input type="text" class="input-text required-entry absolute-advice" title="postcode" value="' + OriginalBillingPostcode + '" id="billing:postcode" name="billing[postcode]" autocomplete="off">');
} 
}

var state_city = [];
<?php echo $this->getCityList(); ?>
var city_postcode = [];
<?php echo $this->getPostCodeList(); ?>
//state_city.push({state:'New South Wales',city:'CHATSWORTH'});
//state_city.push({state:'New South Wales',city:'NAUGHTONS GAP',postcode:2470});
//state_city.push({state:'Queensland',city:'TERRICA',postcode:4387});

function StateToCityList(){
var StateText = jQuery('#billing\\:region_id option:selected').text();
if(StateText == "Please select region, state or province")
{   jQuery("#billing\\:city")
.replaceWith('<select id="billing:city" name="billing[city]" class="required-entry"><option value="">Select the State first, then you have options</option></select>');
} else{                             
/////////cookie////////         
/*var cookie_name = "billingstate";         
Mage.Cookies.clear(cookie_name);
Mage.Cookies.set(cookie_name, StateText);           
alert(Mage.Cookies.get(cookie_name));*/
//////////////////////////          
var CityList =  '<select id="billing:city" name="billing[city]" class="required-entry">'+
'<option>Select the City You live</option>';
for(i=0;i<state_city.length;i++)
{
if(state_city[i].state == StateText)
CityList += '<option value="'+state_city[i].city+'">'+state_city[i].city+'</option>';
}
CityList += '</select>';

jQuery("#billing\\:city")
.replaceWith(CityList);     
jQuery('#billing\\:city').change(function() {       ////add select change listener      
CityToPostcode();
});         
}
}   

function CityToPostcode(){      
var CityVal = jQuery('#billing\\:city option:selected').val();
var StateText = jQuery('#billing\\:region_id option:selected').text();
if(StateText == "Please select region, state or province" && CityVal == "Select the City You live")
{   jQuery("#billing\\:postcode")
.replaceWith('<select id="billing\\:postcode" name="billing[postcode]"><option value="">Please select the City first</option></select>');
} else{         
var PostcodeList =  '<select id="billing:postcode" name="billing[postcode]" >';
for(i=0;i<city_postcode.length;i++)
{
if(city_postcode[i].state == StateText && city_postcode[i].city == CityVal)
PostcodeList += '<option value="'+city_postcode[i].postcode+'">'+city_postcode[i].postcode+'</option>';
}
PostcodeList += '</select>';

jQuery("#billing\\:postcode")
.replaceWith(PostcodeList);     
}
}

</script>

次に、\app\code\core\Mage\Checkout\Block\Onepage\Billing.php の Billing.php を編集して、以下のように 2 つの関数を作成します。

    public function getCityList(){
require_once '/your server path/example.com/html/app/Mage.php';
Mage::app();    
$data = "";
/////////////// call SQL read////////////////
$connection_read = Mage::getSingleton('core/resource')->getConnection('core_read'); 
$sql = "SELECT * FROM state_to_city_AU";
$count = 1;
foreach ($connection_read->fetchAll($sql) as $State_City) {
$data .= 'state_city.push({state:"'.$State_City['state'].'", city:"'.$State_City['city'].'"});';    
}       
return $data;       
}

public function getPostCodeList(){
require_once '/your server path/example.com/html/app/Mage.php';
Mage::app();        
$data = "";
/////////////// call SQL read////////////////
$connection_read = Mage::getSingleton('core/resource')->getConnection('core_read');         
$sql = "SELECT * FROM city_to_postcode_AU";
$count = 1;
foreach ($connection_read->fetchAll($sql) as $city_postcode) {
$data .= 'city_postcode.push({state:"'.$city_postcode['state'].'", city:"'.$city_postcode['city'].'", postcode:"'.$city_postcode['postcode'].'"});';            
}       
return $data;       
}

最後に、2 つのデータベース テーブル state_to_city_AU (2 つの列、state と city) および city_to_postcode_AU (3 つの列、state-city-postcode) を追加する準備をする必要があります。

配送先住所コードについても同じ方法を行う必要があります。それは私のために働きます、あなたは試すことができます。

于 2013-10-28T11:14:43.577 に答える