Ship In Cart

Error when country is not listed. - Ship In Cart

Error when country is not listed.

by mhsuffolk » Wed Apr 07, 2021 2:32 pm

1.0.8.0 PHP 7.4 Ship in cart 5.6

Works perfectly until customer selects a country that I do not have listed in Zones based rates. I get on shopping_cart.php The core code correctly shows the "We do not ship...etc"

Notice: Trying to access array offset on value of type bool in D:\Phoenix_1_0_8_0\htdocs\includes\modules\content\shopping_cart\cm_sc_shipping.php on line 227

Notice: Trying to access array offset on value of type bool in D:\Phoenix_1_0_8_0\htdocs\includes\modules\content\shopping_cart\cm_sc_shipping.php on line 228

Notice: Trying to access array offset on value of type bool in D:\Phoenix_1_0_8_0\htdocs\includes\modules\content\shopping_cart\cm_sc_shipping.php on line 229

Notice: Trying to access array offset on value of type bool in D:\Phoenix_1_0_8_0\htdocs\includes\modules\order_total\ot_shipping.php on line 48

Notice: Trying to access array offset on value of type bool in D:\Phoenix_1_0_8_0\htdocs\includes\modules\order_total\ot_shipping.php on line 48

Notice: Trying to access array offset on value of type bool in D:\Phoenix_1_0_8_0\htdocs\includes\modules\content\shopping_cart\templates\tpl_cm_sc_shipping.php on line 8
User avatar
mhsuffolk
Contributor
Posts: 199
Joined: Sat Oct 26, 2019 9:13 am
Phoenix Version: v1.1.0.6
Contact:

Re: Error when country is not listed.

by raiwa » Wed Apr 07, 2021 4:04 pm

Thanks, I‘ll check it.
Public Phoenix Change Log Cheat Set on Google Sheets
https://docs.google.com/spreadsheets/d/ ... sp=sharing

Need Help?viewtopic.php?f=10&t=27
raiwa
Certified Developer
Posts: 1640
Joined: Sat Dec 21, 2019 8:08 am
Phoenix Version: 1.1.0.6
Contact:

Re: Error when country is not listed.

by raiwa » Wed Apr 07, 2021 4:28 pm

Hi @mhsuffolk,

It seems you are using one of the multi zone modules. The core zone module works correct.
Can you please post the complete package you are using, I'll then research.

Anyway the error is strange, $selected_shipping is correct defined as an array.
Public Phoenix Change Log Cheat Set on Google Sheets
https://docs.google.com/spreadsheets/d/ ... sp=sharing

Need Help?viewtopic.php?f=10&t=27
raiwa
Certified Developer
Posts: 1640
Joined: Sat Dec 21, 2019 8:08 am
Phoenix Version: 1.1.0.6
Contact:

Re: Error when country is not listed.

by raiwa » Wed Apr 07, 2021 5:16 pm

Just checked this multi zone module and it works error free:
https://apps.oscommerce.com/osvz6&multi ... ipping&p=2
Public Phoenix Change Log Cheat Set on Google Sheets
https://docs.google.com/spreadsheets/d/ ... sp=sharing

Need Help?viewtopic.php?f=10&t=27
raiwa
Certified Developer
Posts: 1640
Joined: Sat Dec 21, 2019 8:08 am
Phoenix Version: 1.1.0.6
Contact:

Re: Error when country is not listed.

by mhsuffolk » Wed Apr 07, 2021 6:26 pm

Strange, I am not using any addon for zones, just the core one.
Is it because the country that I have not listed in the zones module is still in the countries table, that is I have not deleted them?
I have Tax Class set to none and am using 4 zones. The same set up works OK in my live store on 1.0.5.0 PHP 7.3
User avatar
mhsuffolk
Contributor
Posts: 199
Joined: Sat Oct 26, 2019 9:13 am
Phoenix Version: v1.1.0.6
Contact:

Re: Error when country is not listed.

by raiwa » Wed Apr 07, 2021 6:51 pm

O.K. I could recreate it now knowing that it shows when no shipping is available at all.

Even it shows in the shipping estimator, the root of the problem is in the shipping class which returns null instead of an empty array for "$shipping_modules->cheapest()" when no shipping is available.

In the shipping estimator cm_sc_shipping.php it could be catched in line 227-229 like this:

Code: Select all

            $order->info['shipping_method'] = $selected_shipping['title'] ?? '';
            $order->info['shipping_cost'] = $selected_shipping['cost'] ?? '0';
            $order->info['total']+= $selected_shipping['cost'] ?? '0';
and in the template tpl_cm_sc_shipping.php line 8 like this:

Code: Select all

      <?= tep_draw_form('estimator', tep_href_link('shopping_cart.php', '', 'NONSSL'), 'post') . tep_draw_hidden_field('sid', $selected_shipping['id'] ?? '') ?>
But then there would still show errors in the ot_shipping.php module. This is not covered in core because in checkout_confirmation.php, where the order total modules show in the c ore prcheckout process, it's supposed a valid shipping module is always selected.
So this would need to be fixed in core files.

However, as you say, another aproach would be to leave in the countries table only countries for which shipping is available.

And: These are "only" notice errors.
Public Phoenix Change Log Cheat Set on Google Sheets
https://docs.google.com/spreadsheets/d/ ... sp=sharing

Need Help?viewtopic.php?f=10&t=27
raiwa
Certified Developer
Posts: 1640
Joined: Sat Dec 21, 2019 8:08 am
Phoenix Version: 1.1.0.6
Contact:

Re: Error when country is not listed.

by mhsuffolk » Thu Apr 08, 2021 3:15 pm

Thank you @raiwa.
I have tried your changes in my 1.0.8.0 test shop and all those error messages have gone, the message in your addon saying we do not ship there is present and correct, however we now have a new error message.

Notice: Trying to access array offset on value of type bool in D:\Phoenix_1_0_8_0\htdocs\includes\modules\order_total\ot_shipping.php on line 48

Notice: Trying to access array offset on value of type bool in D:\Phoenix_1_0_8_0\htdocs\includes\modules\order_total\ot_shipping.php on line 48

Regarding your earlier comments do you think that core should be changed to cope with this scenario?
User avatar
mhsuffolk
Contributor
Posts: 199
Joined: Sat Oct 26, 2019 9:13 am
Phoenix Version: v1.1.0.6
Contact:

Re: Error when country is not listed.

by raiwa » Thu Apr 08, 2021 3:41 pm

Regarding your earlier comments do you think that core should be changed to cope with this scenario?
That's a question for the lead developers: @ecartz, @burt ?

In a clean core scenario the error situation will not be given. However a fix is only possible (as far as I can see) in core files.

As mentioned, the other approach is to leave in the database only countries for which shipping is available. This would also be good for the create account form. It doesn't make sense to allow creating accounts with countries to which you do not ship.
Public Phoenix Change Log Cheat Set on Google Sheets
https://docs.google.com/spreadsheets/d/ ... sp=sharing

Need Help?viewtopic.php?f=10&t=27
raiwa
Certified Developer
Posts: 1640
Joined: Sat Dec 21, 2019 8:08 am
Phoenix Version: 1.1.0.6
Contact:

Re: Error when country is not listed.

by mhsuffolk » Thu Apr 08, 2021 3:45 pm

raiwa wrote:
It doesn't make sense to allow creating accounts with countries to which you do not ship.
Very good point, I will start deleting countries.
User avatar
mhsuffolk
Contributor
Posts: 199
Joined: Sat Oct 26, 2019 9:13 am
Phoenix Version: v1.1.0.6
Contact: