PHP code example of fostercommerce / shipstationconnect

1. Go to this page and download the library: Download fostercommerce/shipstationconnect library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fostercommerce / shipstationconnect example snippets


use craft\base\Event;
use fostercommerce\shipstationconnect\models\Order;
use fostercommerce\shipstationconnect\events\OrderEvent;
use fostercommerce\shipstationconnect\services\Xml;

Event::on(
	Xml::class,
	Xml::ORDER_EVENT,
	static function (OrderEvent $e) {
	  // The transformed order - This is the data that will be sent to ShipStation.
		$order = $e->order;
		
		// The source Commerce Order that was used to create the transformed order.
		$commerceOrder = $order->getParent();

		// Use full order number for OrderNumber
		$order->setOrderNumber($commerceOrder->number);

		// Set a custom field value
		$order->setCustomField1(Currency::formatAsCurrency($commerceOrder->getAdjustmentsTotal(), 'USD'));

		// Set internal notes
		$order->setInternalNotes('Custom Field 1: Adjustments Total');
	}
);

use craft\base\Event;
use craft\commerce\elements\Order as CommerceOrder;
use fostercommerce\shipstationconnect\controllers\OrdersController;
use fostercommerce\shipstationconnect\events\FindOrderEvent;

Event::on(
    OrdersController::class,
    OrdersController::FIND_ORDER_EVENT,
    function (FindOrderEvent $e) {
        // Set the order so that ShipStation Connect can update it's shipping details.
        $this->order = CommerceOrder::find()->number($e->orderNumber)->one();
    }
);