Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with cart page shipping estimator when multiple shipping options within 1 shipping method #11401

Closed
ClearThinking opened this issue Jun 29, 2022 · 3 comments

Comments

@ClearThinking
Copy link

The cart page estimator does not work properly when there is more than 1 shipping rate within a shipping method. To reproduce, you can set up multiple rates for the same geo zone in Weight Based Shipping, add a product to your cart, then use the cart page shipping estimator. You will see that only the first option can be selected.

I believe this is because all of the options share the same "id" attribute in their label. This fix seems like it works:

IN:
/extension/opencart/catalog/view/template/total/shipping.twig

REPLACE (LINE 99):
if (json['shipping_method'][i]['quote'][j]['code'] == '{{ shipping_method }}') {
  html += '<input type="radio" name="shipping_method" value="' + json['shipping_method'][i]['quote'][j]['code'] + '" id="input-shipping-method-' + i + '" checked/>';
} else {
  html += '<input type="radio" name="shipping_method" value="' + json['shipping_method'][i]['quote'][j]['code'] + '" id="input-shipping-method-' + i + '"/>';
}

html += '  <label for="input-shipping-method-' + i + '">' + json['shipping_method'][i]['quote'][j]['title'] + ' - ' + json['shipping_method'][i]['quote'][j]['text'] + '</label>';

WITH:
if (json['shipping_method'][i]['quote'][j]['code'] == '{{ shipping_method }}') {
  html += '<input type="radio" name="shipping_method" value="' + json['shipping_method'][i]['quote'][j]['code'] + '" id="input-shipping-method-' + json['shipping_method'][i]['quote'][j]['code'] + '" checked/>';
} else {
  html += '<input type="radio" name="shipping_method" value="' + json['shipping_method'][i]['quote'][j]['code'] + '" id="input-shipping-method-' + json['shipping_method'][i]['quote'][j]['code'] + '"/>';
}

html += '  <label for="input-shipping-method-' + json['shipping_method'][i]['quote'][j]['code'] + '">' + json['shipping_method'][i]['quote'][j]['title'] + ' - ' + json['shipping_method'][i]['quote'][j]['text'] + '</label>';

@eturerer
Copy link

eturerer commented Jul 3, 2022

namespace Opencart\Catalog\Model\Localisation;

class Common extends \Opencart\System\Engine\Model
{
public function getAddress(): array
{
$country_id = $this->config->get('config_country_id');
$zone_id = $this->config->get('config_zone_id');
$postcode = $this->config->get('config_postcode');

	$this->load->model('localisation/country');

	$country_info = $this->model_localisation_country->getCountry((int)$country_id);


	$country = $country_info['name'];
	$iso_code_2 = $country_info['iso_code_2'];
	$iso_code_3 = $country_info['iso_code_3'];
	$address_format = $country_info['address_format'];

	$this->load->model('localisation/zone');

	$zone_info = $this->model_localisation_zone->getZone((int)$zone_id);

	$zone = $zone_info['name'];
	$zone_code = $zone_info['code'];

	$address = [
		'firstname'      => '',
		'lastname'       => '',
		'company'        => '',
		'address_1'      => '',
		'address_2'      => '',
		'postcode'       => $postcode,
		'city'           => '',
		'zone_id'        => $zone_id,
		'zone'           => $zone,
		'zone_code'      => $zone_code,
		'country_id'     => $country_id,
		'country'        => $country,
		'iso_code_2'     => $iso_code_2,
		'iso_code_3'     => $iso_code_3,
		'address_format' => $address_format,
		'custom_field'   => []
	];

	return $address;
}

}

namespace Opencart\Catalog\Controller\Startup;

class Cart extends \Opencart\System\Engine\Controller {
public function index(): void {
if (!isset($this->session->data['shipping_address']['address_id'])) {
$this->load->model('localisation/common');
$this->session->data['shipping_address'] = $this->model_localisation_common->getAddress();
}

    if (!isset($this->session->data['payment_address']['address_id'])) {
        $this->load->model('localisation/common');
        $this->session->data['payment_address'] = $this->model_localisation_common->getAddress();
    }

    if (!isset($this->session->data['shipping_methods'])) {
        // Shipping methods
        $this->load->model('checkout/shipping_method');
        $data['shipping_methods'] = $this->model_checkout_shipping_method->getMethods($this->session->data['shipping_address']);

        // Store shipping methods in session
        $this->session->data['shipping_methods'] = $data['shipping_methods'];

        if (!isset($this->session->data['shipping_method'])) {
            //  if (count($this->session->data['shipping_methods']) == 1) {
            $this->session->data['shipping_method'] = current(current($this->session->data['shipping_methods'])['quote'])['code'];
            //  }
        }
    }
}

}

////
config

// Actions
$_['action_pre_action'] = [
'startup/setting',
'startup/session',
'startup/language',
'startup/seo_url',
'startup/customer',
'startup/language',
'startup/currency',
'startup/tax',
'startup/application',
'startup/extension',
'startup/startup',
'startup/marketing',
'startup/error',
'startup/event',
'startup/cart',
//'startup/sass',
'startup/maintenance',
];

@danielkerr
Copy link
Member

seems working for me

image

@danielkerr
Copy link
Member

ok i see what u mean

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants