surprisehighway / craft-avatax

Calculate and add sales tax to an order's base tax using Avalara's AvaTax service with Craft Commerce 5.
MIT License
7 stars 11 forks source link

Exception when saving user #5

Closed jmauzyk closed 5 years ago

jmauzyk commented 5 years ago

Throwing an exception when attempting to save user preferences in the Control Panel. Not saving any address info but it appears to be triggering the onBeforeSaveAddress event. Stack trace:

yii\base\Exception: Invalid address. in /Users/joel/Sites/craft3/vendor/surprisehighway/craft-avatax/src/services/SalesTaxService.php:380
Stack trace:
#0 /Users/joel/Sites/craft3/vendor/surprisehighway/craft-avatax/src/Avatax.php(176): surprisehighway\avatax\services\SalesTaxService->validateAddress(Object(craft\commerce\models\Address))
#1 /Users/joel/Sites/craft3/vendor/surprisehighway/craft-avatax/src/Avatax.php(131): surprisehighway\avatax\Avatax->onBeforeSaveAddress(Object(craft\commerce\events\AddressEvent))
#2 [internal function]: surprisehighway\avatax\Avatax->surprisehighway\avatax\{closure}(Object(craft\commerce\events\AddressEvent))
#3 /Users/joel/Sites/craft3/vendor/yiisoft/yii2/base/Event.php(312): call_user_func(Object(Closure), Object(craft\commerce\events\AddressEvent))
#4 /Users/joel/Sites/craft3/vendor/yiisoft/yii2/base/Component.php(636): yii\base\Event::trigger('craft\\commerce\\...', 'beforeSaveAddre...', Object(craft\commerce\events\AddressEvent))
#5 /Users/joel/Sites/craft3/vendor/craftcms/commerce/src/services/Addresses.php(200): yii\base\Component->trigger('beforeSaveAddre...', Object(craft\commerce\events\AddressEvent))
#6 /Users/joel/Sites/craft3/vendor/craftcms/commerce/src/elements/Order.php(927): craft\commerce\services\Addresses->saveAddress(Object(craft\commerce\models\Address), false)
#7 /Users/joel/Sites/craft3/vendor/craftcms/cms/src/services/Elements.php(515): craft\commerce\elements\Order->afterSave(false)
#8 /Users/joel/Sites/craft3/vendor/craftcms/commerce/src/services/Customers.php(426): craft\services\Elements->saveElement(Object(craft\commerce\elements\Order))
#9 [internal function]: craft\commerce\services\Customers->saveUserHandler(Object(craft\events\ModelEvent))
#10 /Users/joel/Sites/craft3/vendor/yiisoft/yii2/base/Event.php(312): call_user_func(Array, Object(craft\events\ModelEvent))
#11 /Users/joel/Sites/craft3/vendor/yiisoft/yii2/base/Component.php(636): yii\base\Event::trigger('craft\\elements\\...', 'afterSave', Object(craft\events\ModelEvent))
#12 /Users/joel/Sites/craft3/vendor/craftcms/cms/src/base/Element.php(1889): yii\base\Component->trigger('afterSave', Object(craft\events\ModelEvent))
#13 /Users/joel/Sites/craft3/vendor/craftcms/cms/src/elements/User.php(1322): craft\base\Element->afterSave(false)
#14 /Users/joel/Sites/craft3/vendor/craftcms/cms/src/services/Elements.php(515): craft\elements\User->afterSave(false)
#15 /Users/joel/Sites/craft3/vendor/craftcms/cms/src/controllers/UsersController.php(1088): craft\services\Elements->saveElement(Object(craft\elements\User), false)
#16 [internal function]: craft\controllers\UsersController->actionSaveUser()
#17 /Users/joel/Sites/craft3/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#18 /Users/joel/Sites/craft3/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#19 /Users/joel/Sites/craft3/vendor/craftcms/cms/src/web/Controller.php(109): yii\base\Controller->runAction('save-user', Array)
#20 /Users/joel/Sites/craft3/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('save-user', Array)
#21 /Users/joel/Sites/craft3/vendor/craftcms/cms/src/web/Application.php(297): yii\base\Module->runAction('users/save-user', Array)
#22 /Users/joel/Sites/craft3/vendor/craftcms/cms/src/web/Application.php(561): craft\web\Application->runAction('users/save-user', Array)
#23 /Users/joel/Sites/craft3/vendor/craftcms/cms/src/web/Application.php(281): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#24 /Users/joel/Sites/craft3/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#25 /Users/joel/Sites/craft3/web/index.php(21): yii\base\Application->run()
#26 {main}
jmauzyk commented 5 years ago

To clarify, this exception happens in the Control Panel when saving updates to an existing user who already has addresses associated with their account. Does not happen when saving new users.

imagehat commented 5 years ago

Thanks @jmauzyk - to get around this for now you should be able to disable address validation in the Avatax plugin settings. But yeah that address check should probably only happen during the front-end checkout flow so I'll see what we need to change.

imagehat commented 5 years ago

This was fixed with v2.0.3.