As the title says, I have a problem with the dropdown that I made. It contains a list of countries to which the store can send. He can create a delivery region, give him a name, and then select all the countries that fall under that region. then add a price to it.
During the check, I want to get the list of countries provided by the web store and use it so that the customer can choose where he lives. Options for the country are those in which the store also ships its products. However, I ran into some problems.
The main problem is that the way it was designed is that you select a region that will reload the page with an additional parameter in the URL that will add the delivery region to the order that will be created. This is causing me a problem. Since he will always choose the bottom option of the drop-down list, and not the one that I just selected, this means that I can’t establish the country in which the person lives properly.
therefore if the dropdown menu
USA Singles China
and I will choose the USA, the page will reload, and China will depend
My code is:
Html dropdown
{% for shippingRegion in store.getShippingRegions %}
<a style="display: none" id="addShippingRegion{{shippingRegion.id}}" href="{{ path('checkout', {'store_id': store.id, 'shippingRegion': shippingRegion.id}) }}"></a>
{% endfor %}
<div class="collection">
<select onchange="shippingRegionSelectCheck(this)" class="browser-default" id="shippingRegion" name="ShippingRegion">
<option selected disabled>Select a shipping region</option>
{% for key,country in regionCountries %}
{% for c in country %} =
<option id="countrySelect" data-id="{{key}}" selected value="{{c}}" >{{c}}</option>
{% endfor %}
{% endfor %}
</select>
</div>
Javascript function reloading page
function shippingRegionSelectCheck(regionSelect){
if(regionSelect){
var selected = $('#shippingRegion').find('option:selected');
var extra = selected.data('id');
var country = $('#shippingRegion').val('value');
var href = $('#addShippingRegion' + extra).attr('href');
window.location.href = href;
}
}
Entity
class ShippingRegion{
public function __construct() {
$this->shipping_weight_prices = new ArrayCollection();
$this->shipping_amount_prices = new ArrayCollection();
}
protected $id;
protected $name;
protected $regionType;
protected $regionCountry;
source
share