FosterCommerce / shipstation-connect

A plugin for Craft Commerce 2 that integrates with ShipStation.
https://plugins.craftcms.com/shipstationconnect
Other
7 stars 10 forks source link

Orders without associated Customer causes error when syncing from ShipStation #18

Closed Adamascroft closed 3 years ago

Adamascroft commented 4 years ago

An error occurred attempting to update orders: The remote server returned an error: (500) Internal Server Error.

The test connection goes through as if it's connected and working.

Craft Pro | 3.4.20 Craft Commerce | 3.1.4 ShipStation | 1.3.2

Adamascroft commented 4 years ago
2020-05-22 12:28:19 - error - TypeError
TypeError: Argument 2 passed to fostercommerce\shipstationconnect\services\Xml::customer() must be an instance of craft\commerce\models\Customer, null given, called in /home/gb57zl99okgb/vendor/fostercommerce/shipstationconnect/src/services/Xml.php on line 122 and defined in /home/gb57zl99okgb/vendor/fostercommerce/shipstationconnect/src/services/Xml.php:331
Stack trace:
#0 /home/gb57zl99okgb/vendor/fostercommerce/shipstationconnect/src/services/Xml.php(122): fostercommerce\shipstationconnect\services\Xml->customer(Object(SimpleXMLElement), NULL)
#1 /home/gb57zl99okgb/vendor/fostercommerce/shipstationconnect/src/services/Xml.php(39): fostercommerce\shipstationconnect\services\Xml->order(Object(SimpleXMLElement), Object(craft\commerce\elements\Order))
#2 /home/gb57zl99okgb/vendor/fostercommerce/shipstationconnect/src/controllers/OrdersController.php(128): fostercommerce\shipstationconnect\services\Xml->orders(Object(SimpleXMLElement), Array)
#3 /home/gb57zl99okgb/vendor/fostercommerce/shipstationconnect/src/controllers/OrdersController.php(45): fostercommerce\shipstationconnect\controllers\OrdersController->getOrders(NULL)
#4 [internal function]: fostercommerce\shipstationconnect\controllers\OrdersController->actionProcess(NULL, 'export')
#5 /home/gb57zl99okgb/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#6 /home/gb57zl99okgb/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#7 /home/gb57zl99okgb/vendor/craftcms/cms/src/web/Controller.php(178): yii\base\Controller->runAction('process', Array)
#8 /home/gb57zl99okgb/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('process', Array)
#9 /home/gb57zl99okgb/vendor/craftcms/cms/src/web/Application.php(291): yii\base\Module->runAction('shipstationconn...', Array)
#10 /home/gb57zl99okgb/vendor/craftcms/cms/src/web/Application.php(559): craft\web\Application->runAction('shipstationconn...', Array)
#11 /home/gb57zl99okgb/vendor/craftcms/cms/src/web/Application.php(270): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#12 /home/gb57zl99okgb/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#13 /home/gb57zl99okgb/public_html/index.php(21): yii\base\Application->run()
#14 {main}
Adamascroft commented 4 years ago

With this I was wondering if the order has all the info it needs (name, address, product, etc...) can it sync anyway? Or skip the ones that don't meet the requirements rather than stop all orders being synced.

johnnynotsolucky commented 4 years ago

@Adamascroft We're already checking for shipping and billing addresses here: https://github.com/FosterCommerce/shipstation-connect/blob/master/src/services/Xml.php#L19-L24

    public function shouldInclude($order)
    {
        $settings = Plugin::getInstance()->settings;
        $billingSameAsShipping = $settings->billingSameAsShipping;
        return $order->getShippingAddress() && ($billingSameAsShipping || $order->getBillingAddress());
    }

We can add a condition to require a customer on an order. I think it's fine to exclude orders without customers as ShipStation requires the CustomerCode field be set.