verbb / postie

A Craft Commerce shipping calculator plugin.
Other
12 stars 18 forks source link

Digital Products with Free Shipping enabled are recently throwing errors #105

Closed johnj24 closed 10 months ago

johnj24 commented 1 year ago

Describe the bug

Hello. We have a digital product type where no sizing or weights are available. We have Free Shipping enabled on this product type. We were selling digital pdf's just fine a few months ago, but now each time you enter an address the next screen you see is full of errors. No site updates were made in the past two months so my only guess is USPS made changes on their end that is now effecting us. I did update Postie, Commerce, and CraftCMS today to see if that would fix our issues, but it did not.

I've pasted the errors below:

"USPS: Response error: `{"Number":"-2147221202","Source":"Common:XmlParse","Description":"The element 'RateV4Request' has incomplete content. List of possible elements expected: 'Revision, RateClientType, Package'.","HelpFile":"","HelpContext":""}`."
An Error occurred while handling another error:
yii\web\HeadersAlreadySentException: Headers already sent in /Users/.../vendor/symfony/var-dumper/Dumper/AbstractDumper.php on line 171. in /Users/.../lifebeautiful/vendor/yiisoft/yii2/web/Response.php:368
Stack trace:
#0 /Users/.../vendor/yiisoft/yii2/web/Response.php(341): yii\web\Response->sendHeaders()
#1 /Users/.../vendor/yiisoft/yii2/web/ErrorHandler.php(136): yii\web\Response->send()
#2 /Users/.../vendor/craftcms/cms/src/web/ErrorHandler.php(192): yii\web\ErrorHandler->renderException(Object(yii\web\HeadersAlreadySentException))
#3 /Users/.../vendor/yiisoft/yii2/base/ErrorHandler.php(152): craft\web\ErrorHandler->renderException(Object(yii\web\HeadersAlreadySentException))
#4 /Users/.../vendor/craftcms/cms/src/web/ErrorHandler.php(66): yii\base\ErrorHandler->handleException(Object(yii\web\HeadersAlreadySentException))
#5 [internal function]: craft\web\ErrorHandler->handleException(Object(yii\web\HeadersAlreadySentException))
#6 {main}
Previous exception:
yii\web\HeadersAlreadySentException: Headers already sent in /Users/.../vendor/symfony/var-dumper/Dumper/AbstractDumper.php on line 171. in /Users/.../vendor/yiisoft/yii2/web/Response.php:368
Stack trace:
#0 /Users/.../vendor/yiisoft/yii2/web/Response.php(341): yii\web\Response->sendHeaders()
#1 /Users/.../vendor/yiisoft/yii2/base/Application.php(390): yii\web\Response->send()
#2 /Users/.../public/index.php(21): yii\base\Application->run()
#3 {main}

Steps to reproduce

  1. Create a product type that does not allow sizing or weights
  2. Create a new product with the new product type and have Free Shipping enabled
  3. Go through the checkout process and enter a United States address.
  4. After submitting an address, these errors should appear.

Craft CMS version

4.4.15

Plugin version

3.0.3

Multi-site?

No

Additional context

No response

johnj24 commented 12 months ago

Hi, Josh. Any updates on this even if it's just to say you're aware of the issue and exploring fixes? Or do you think this is a template/settings issue on my end?

engram-design commented 11 months ago

Possibly related to https://github.com/verbb/postie/issues/104 with regards to products marked as "Free Shipping", they should be getting excluded from being sent to providers.

To get this early, run composer require verbb/postie:"dev-craft-4 as 3.0.3".

johnj24 commented 11 months ago

After updating to dev-craft-4 the Free Shipping items still show the same errors.

Our physical items with weight/size now show this error:

Error: Class "verbb\postie\services\PostieHelper" not found in /.../vendor/verbb/postie/src/services/Service.php:213
Stack trace:
#0 /.../vendor/verbb/postie/src/services/Service.php(154): verbb\postie\services\Service->applyFreeShipping(Object(craft\commerce\elements\Order))
#1 /.../vendor/verbb/postie/src/services/Service.php(181): verbb\postie\services\Service->getShippingMethodsForOrder(Object(craft\commerce\elements\Order))
#2 [internal function]: verbb\postie\services\Service->registerShippingMethods(Object(craft\commerce\events\RegisterAvailableShippingMethodsEvent))
#3 /.../vendor/yiisoft/yii2/base/Event.php(312): call_user_func(Array, Object(craft\commerce\events\RegisterAvailableShippingMethodsEvent))
#4 /.../vendor/yiisoft/yii2/base/Component.php(642): yii\base\Event::trigger('craft\\commerce\\...', 'registerAvailab...', Object(craft\commerce\events\RegisterAvailableShippingMethodsEvent))
#5 /.../vendor/craftcms/commerce/src/services/ShippingMethods.php(119): yii\base\Component->trigger('registerAvailab...', Object(craft\commerce\events\RegisterAvailableShippingMethodsEvent))
#6 /.../vendor/craftcms/commerce/src/elements/Order.php(1959): craft\commerce\services\ShippingMethods->getMatchingShippingMethods(Object(craft\commerce\elements\Order))
#7 /.../vendor/craftcms/commerce/src/elements/Order.php(1932): craft\commerce\elements\Order->getAvailableShippingMethodOptions()
#8 /.../vendor/craftcms/commerce/src/elements/Order.php(2014): craft\commerce\elements\Order->recalculate()
#9 /.../vendor/craftcms/cms/src/services/Elements.php(3166): craft\commerce\elements\Order->afterSave(false)
#10 /.../vendor/craftcms/cms/src/services/Elements.php(1063): craft\services\Elements->_saveElementInternal(Object(craft\commerce\elements\Order), false, false, true, Array, false)
#11 /.../vendor/craftcms/commerce/src/controllers/CartController.php(461): craft\services\Elements->saveElement(Object(craft\commerce\elements\Order), false, false, true)
#12 /.../vendor/craftcms/commerce/src/controllers/CartController.php(277): craft\commerce\controllers\CartController->_returnCart()
#13 [internal function]: craft\commerce\controllers\CartController->actionUpdateCart()
#14 /.../vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#15 /.../vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#16 /.../vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('update-cart', Array)
#17 /.../vendor/craftcms/cms/src/web/Application.php(304): yii\base\Module->runAction('commerce/cart/u...', Array)
#18 /.../vendor/craftcms/cms/src/web/Application.php(607): craft\web\Application->runAction('commerce/cart/u...', Array)
#19 /.../vendor/craftcms/cms/src/web/Application.php(283): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#20 /.../vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#21 /.../public/index.php(21): yii\base\Application->run()
#22 {main}
engram-design commented 11 months ago

Just pushed a fix for that error (just run composer require ... again). As for the error, that's actually expected behaviour if all you have in your cart are non-shippable products. The USPS API is essentially saying you need to have packages in your rate request, and because you don't have any shippable products to add to packages, it's an invalid call.

This shouldn't actually return an error unless you have the debugging settings set to show errors?

johnj24 commented 11 months ago

I thought I may have had debugging on, but I checked the config and it's not.

'hasCpSection' => true,
'applyFreeShipping' => true,
'displayDebug' => false,
'providers' => [
  'usps' => [
    'name' => 'USPS',
    'enabled' => true,
    'settings' => [
      'username' => 'XXXXXXXXXX',
    ],
    // Mark-Up
    'markUpRate' => '0.50',
    'markUpBase' => 'value',

     // Units
    'weightUnit' => 'lb',
    'dimensionUnit' => 'in',

    // Packing method
    'packingMethod' => 'boxPacking',
  ],
],

With displayDebug set to true I now get this error when adding just a PDF to the cart:

"USPS: Domestic rate service call"
engram-design commented 11 months ago

I just wanted to confirm your comment but now each time you enter an address the next screen you see is full of errors you shouldn’t see any errors, it should just return no available shipping methods and log this error to your postie.log file.

are you seeing something different?

johnj24 commented 11 months ago

This is the screen I see after addresses are entered:

Screenshot 2023-07-14 at 10 53 39 AM
engram-design commented 11 months ago

So that seems like a Craft::dd() call in PHP, or a {% dd %} call in Twig, which certainly isn't what I'm seeing. Is there any chance you've added that on your end for debugging? I can't tell from the stack trace exactly where it's coming from. It might show in your storage/logs/*.log files though.

johnj24 commented 11 months ago

Well, I poked around config files and ended up adding 'displayErrors' => false to postie.php and that -- at least for now -- has removed the error screen from what I can tell. I'm able to get all the way to the payment page uninterrupted now.

engram-design commented 11 months ago

So by default, that should be set to false anyway, but yes - that will show errors from providers.

johnj24 commented 11 months ago

That's what I thought too, which is why I left it out of the original config settings. I guess maybe not?

engram-design commented 11 months ago

Very strange, as the default is certainly false