Post by storm-cloud » Sun Sep 22, 2013 11:37 am

Something that has bothered me for a while (since v1.5.1.3, now on v1.5.5.1) is when a shipping method is applied at the Cart stage of the Checkout, but is not pre-selected during Checkout (only applicable if multiple shipping options are available).

To clarify:
1) Customer adds an item to their cart.
2) They visit the Cart page and select "Estimate Shipping".
3) They then apply their preferred shipping method (other than the first option).
4) When proceeding through to the Checkout, on Step 4 (Delivery Method) the shipping method reverts back to the default (first) option.

Looking over the shipping_method.tpl and controller file, it does appear that there is a provision for this to work, but unfortunately it does not.

Code: Select all

<td><?php if ($quote['code'] == $code || !$code) { ?>
      <?php $code = $quote['code']; ?>
      <input type="radio" name="shipping_method" value="<?php echo $quote['code']; ?>" id="<?php echo $quote['code']; ?>" checked="checked" />
      <?php } else { ?>
      <input type="radio" name="shipping_method" value="<?php echo $quote['code']; ?>" id="<?php echo $quote['code']; ?>" />
      <?php } ?></td>
Would there be any way to correct this behaviour so it works as it should?

Active Member

Posts

Joined
Wed Feb 22, 2012 8:07 am

Post by storm-cloud » Wed Oct 09, 2013 10:04 am

Oh well... I guess this is not important enough to warrant a fix. :(

Active Member

Posts

Joined
Wed Feb 22, 2012 8:07 am

Post by MarketInSG » Wed Oct 09, 2013 4:50 pm

the variable is being unset in guest_shipping.php file

Code: Select all

unset($this->session->data['shipping_method']);


User avatar
Guru Member

Posts

Joined
Wed Nov 16, 2011 11:53 am
Location - Singapore

Post by storm-cloud » Wed Oct 09, 2013 7:19 pm

MarketInSG wrote:the variable is being unset in guest_shipping.php file
Ahhh... Thank you. I didn't think to look for this, which clearly shows I still have a lot to learn! ;)

However, now that you pointed me in the right direction I found that the variable is unset in multiple instances (cart.php, confirm.php, guest.php, guest_shipping.php, manual.php, register.php, shipping_address.php and success.php) and that modifying guest_shipping.php unfortunately did not help.

I found that modifying guest.php (for Guest Checkout) and shipping_address.php (for users that are logged in) resulted in the behaviour that I was seeking.

I am a little surprised that this isn't the default behaviour though. If a customer has already selected a shipping method at the cart stage of the checkout, there is no reason why they should be have to select this again during checkout. Also, it seems odd that there would be code in place to retain the shipping method, yet the steps prior to this unset the shipping method making this code redundant.

I now feel inspired to take this modification further. ;D If a shipping method has already been selected at the cart, then I would like to remove the step in the checkout completely.

I think this could be quite tricky though. The OpenCart system does not use any logic to obtain the checkout steps numbering and instead these are hardcoded in. I would guess that I would need to create new language entries and call upon these with php if statements. Also I am not sure how to work with ajax to ensure the continue button skips step 4 if the shipping method is already selected (Step 3 > Step 5).

Any suggestions would be greatly appreciated.

Active Member

Posts

Joined
Wed Feb 22, 2012 8:07 am

Post by MarketInSG » Thu Oct 10, 2013 11:42 am

you can use javascript for the button to be clicked if the shipping method is already set. That will do pretty much you need. so
<?php if (isset($this->session->data['shipping_method'])) { ?>
<script type="text/javascript">
$(document).ready(function() {
$('#button-shipping-method').trigger('click');
});
</script>
<?php } ?>


User avatar
Guru Member

Posts

Joined
Wed Nov 16, 2011 11:53 am
Location - Singapore

Post by pacage » Sun Jul 26, 2015 10:54 pm

storm-cloud wrote: I found that modifying guest.php (for Guest Checkout) and shipping_address.php (for users that are logged in) resulted in the behaviour that I was seeking.
Many thanks storm-cloud, this fixed this issue for me in OpenCart v2.0.3.1 also.
Strange issue to still exist, to me if I was a customer and came across this behaviour in an online store, I wouldn't be revisiting.
Great to have the OC Forums to fallback on for issues such as this.

Newbie

Posts

Joined
Thu Jul 02, 2015 3:52 am

Post by WriteOn » Wed Dec 06, 2017 12:57 pm

I've installed OpenCart for the first time, manually installing 3.0.2.0. It's doing fine in pre-opening tests, but this issue of the shipping section of checkout opening with the first option checked, instead of the shipping method that was selected and applied in the cart being checked, is one I wish I knew how to solve. Even loading with nothing checked would be better than loading with the wrong option checked when there are only two options. Suggestions, anyone?

Newbie

Posts

Joined
Sat Nov 25, 2017 11:29 pm

Post by Johnathan » Wed Dec 06, 2017 11:42 pm

This happens because shipping rates are re-requested after the shipping address step of checkout, and the rate might be different. You can try this old edit that I provided, which will stop the shipping rates in the session data from being cleared:

viewtopic.php?f=20&t=152080

That may or may not solve your issue.

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am

Who is online

Users browsing this forum: No registered users and 43 guests