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

Processing Short Numbers Only? #59

Closed smockensturm closed 4 months ago

smockensturm commented 4 months ago

Hey there, we have a situation with order numbers.

82fceda3cf3b9a66d2e2d61fea858c19
82fcedad331f3468434f819d9786457d

ShipStation Connect (I think) sees these as the same number and won't process the second one. How can we get ShipStation to process these seemingly duplicate numbers.

Weird, huh?

johnnynotsolucky commented 4 months ago

Hi @smockensturm, I'll take a look at this on Monday first thing.

johnnynotsolucky commented 4 months ago

@smockensturm, by default the order export uses the order reference number which is a user-defined field. Commerce sets it to {{number[:7]}} by default. Shortening the order number drastically increases the chance of a collision with higher order counts.

There are 2 possibilities to resolve this.

The first is to update the reference field in your store config so that you can guarantee its uniqueness.

Alternatively, if you have a site module on that site, you can add an event listener to override the value with the full order number:

use yii\base\Event;
use fostercommerce\shipstationconnect\services\Xml;
use fostercommerce\shipstationconnect\events\OrderFieldEvent;

Event::on(
    Xml::class,
    Xml::ORDER_FIELD_EVENT,
    function (OrderFieldEvent $e) {
        if ($e->fieldName === OrderFieldEvent::FIELD_ORDER_NUMBER) {
            $e->value = $e->order->number;
        }
    }
);