Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: SpeeDee Delivery Integration #97

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
3 changes: 1 addition & 2 deletions common/config/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
'baseUrl' => $params['coldco']['baseUrl'],
'clientId' => $params['coldco']['clientId'],
'secret' => $params['coldco']['secret'],
]

],
],
];
4 changes: 4 additions & 0 deletions common/config/params.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,8 @@
'csvBoxS3Secret' => '',
'csvBoxS3Region' => '',
'csvBoxS3Bucket' => '',

'speedeeFtpHost' => '',
'speedeeFtpUser' => 123,
'speedeeFtpPass' => '',
];
166 changes: 166 additions & 0 deletions common/models/SpeedeeManifest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
<?php

namespace common\models;

use Yii;
use yii\behaviors\TimestampBehavior;

/**
* This is the model class for table "speedee_manifests".
*
* @property int $id
* @property int $order_id
* @property int $customer_id
* @property string $ship_from_shipper_number
* @property string $ship_from_name
* @property string $ship_from_attention
* @property string $ship_from_address_1
* @property string $ship_from_address_2
* @property string $ship_from_city
* @property int $ship_from_zip
* @property string $ship_from_country
* @property string $ship_from_email
* @property string $ship_from_phone
* @property string $ship_to_import_field
* @property string $ship_to_shipper_number
* @property string $ship_to_name
* @property string $ship_to_attention
* @property string $ship_to_address_1
* @property string $ship_to_address_2
* @property string $ship_to_city
* @property string $ship_to_country
* @property string $ship_to_email
* @property string $ship_to_phone
* @property string $reference_1
* @property string $reference_2
* @property string $reference_3
* @property string $reference_4
* @property int $weight
* @property int $length
* @property int $width
* @property int $height
* @property string $barcode
* @property int $oversized
* @property int $pickup_tag
* @property int $aod
* @property int $aod_option
* @property int $cod
* @property int $cod_value
* @property int $declared_value
* @property int $package_handling
* @property int $apply_package_handling
* @property string $ship_date
* @property string $bill_to_shipper_number
* @property int $unboxed
* @property string $manifest_filename
* @property boolean $is_manifest_sent
* @property int $created_at
* @property int $updated_at
*
* @property Customer $customer
* @property Order $order
*/
class SpeedeeManifest extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'speedee_manifests';
}

public function behaviors()
{
return [
TimestampBehavior::class,
];
}

/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['order_id', 'customer_id', 'ship_from_zip', 'weight', 'length', 'width', 'height', 'oversized', 'pickup_tag', 'aod', 'aod_option', 'cod', 'cod_value', 'declared_value', 'package_handling', 'apply_package_handling', 'unboxed'], 'integer'],
[['ship_date'], 'safe'],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we ensure a data format?

[['ship_from_shipper_number', 'ship_to_shipper_number', 'bill_to_shipper_number'], 'string', 'max' => 6],
[['ship_from_name', 'ship_from_attention', 'ship_from_address_1', 'ship_from_address_2', 'ship_from_city', 'ship_from_country', 'ship_from_email', 'ship_from_phone', 'ship_to_import_field', 'ship_to_name', 'ship_to_attention', 'ship_to_address_1', 'ship_to_address_2', 'ship_to_city', 'ship_to_country', 'ship_to_email', 'ship_to_phone', 'reference_1', 'reference_2', 'reference_3', 'reference_4', 'barcode'], 'string', 'max' => 255],
[['customer_id'], 'exist', 'skipOnError' => true, 'targetClass' => Customer::class, 'targetAttribute' => ['customer_id' => 'id']],
[['order_id'], 'exist', 'skipOnError' => true, 'targetClass' => Order::class, 'targetAttribute' => ['order_id' => 'id']],
];
}

/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'order_id' => 'Order ID',
'customer_id' => 'Customer ID',
'ship_from_shipper_number' => 'Ship From Shipper Number',
'ship_from_name' => 'Ship From Name',
'ship_from_attention' => 'Ship From Attention',
'ship_from_address_1' => 'Ship From Address 1',
'ship_from_address_2' => 'Ship From Address 2',
'ship_from_city' => 'Ship From City',
'ship_from_zip' => 'Ship From Zip',
'ship_from_country' => 'Ship From Country',
'ship_from_email' => 'Ship From Email',
'ship_from_phone' => 'Ship From Phone',
'ship_to_import_field' => 'Ship To Import Field',
'ship_to_shipper_number' => 'Ship To Shipper Number',
'ship_to_name' => 'Ship To Name',
'ship_to_attention' => 'Ship To Attention',
'ship_to_address_1' => 'Ship To Address 1',
'ship_to_address_2' => 'Ship To Address 2',
'ship_to_city' => 'Ship To City',
'ship_to_country' => 'Ship To Country',
'ship_to_email' => 'Ship To Email',
'ship_to_phone' => 'Ship To Phone',
'reference_1' => 'Reference 1',
'reference_2' => 'Reference 2',
'reference_3' => 'Reference 3',
'reference_4' => 'Reference 4',
'weight' => 'Weight',
'length' => 'Length',
'width' => 'Width',
'height' => 'Height',
'barcode' => 'Barcode',
'oversized' => 'Oversized',
'pickup_tag' => 'Pickup Tag',
'aod' => 'Aod',
'aod_option' => 'Aod Option',
'cod' => 'Cod',
'cod_value' => 'Cod Value',
'declared_value' => 'Declared Value',
'package_handling' => 'Package Handling',
'apply_package_handling' => 'Apply Package Handling',
'ship_date' => 'Ship Date',
'bill_to_shipper_number' => 'Bill To Shipper Number',
'unboxed' => 'Unboxed',
'manifest_filename' => 'Manifest Filename',
'is_manifest_sent' => 'Manifest is Sent',
'checksum' => 'Checksum',
];
}

/**
* @return \yii\db\ActiveQuery
*/
public function getCustomer()
{
return $this->hasOne('common\models\Customer', ['id' => 'customer_id']);
}

/**
* @return \yii\db\ActiveQuery
*/
public function getOrder()
{
return $this->hasOne('common\models\Order', ['id' => 'order_id']);
}
}
3 changes: 3 additions & 0 deletions common/models/shipping/Carrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Carrier extends BaseCarrier
const DHL = 4;
const AMAZON_UPS = 5;
const AMAZON_FEDEX = 6;
const SPEEDEE = 9;
const AMAZON_USPS = 11;

/** @var array */
Expand All @@ -31,6 +32,7 @@ class Carrier extends BaseCarrier
self::AMAZON_UPS => 'AMAZON_UPS',
self::AMAZON_FEDEX => 'AMAZON_FEDEX',
self::AMAZON_USPS => 'AMAZON_USPS',
self::SPEEDEE => 'SPEEDEE',
];

const REPRINT_BEHAVIOUR_CREATE_NEW = 1;
Expand All @@ -49,6 +51,7 @@ class Carrier extends BaseCarrier
self::AMAZON_UPS,
self::AMAZON_FEDEX,
self::AMAZON_USPS,
self::SPEEDEE,
];

/**
Expand Down
124 changes: 124 additions & 0 deletions common/models/shipping/extension/wsdl/SpeeDeePlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

namespace common\models\shipping\extension;

use Cassandra\Date;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used?

use common\models\CustomerMeta;
use common\models\shipping\ShipmentPlugin;
use common\models\SpeedeeManifest;
use console\jobs\speedee\SpeeDeeShipJob;
use Yii;

class SpeeDeePlugin extends ShipmentPlugin
{
/**
* Plugin Name
*
* @var string Constant
*/
const PLUGIN_NAME = "SpeeDee";

private SpeedeeManifest $currentManifest;
private string $customerNumber;


public function autoload($customerId = null)
{
$customerMeta = CustomerMeta::find()
->where(['customer_id' => $customerId])
->andWhere(['key' => 'speedee_customer_number'])
->one();

$this->customerNumber = $customerMeta->value;
}

public function getPluginName()
{
return self::PLUGIN_NAME;
}

/**
*
* @return mixed|void
*/
protected function ratePrepare()
{
return $this;
}

protected function rateExecute()
{
return $this;
}

protected function rateProcess()
{
return $this;
}

protected function shipmentPrepare()
{
$manifest = new SpeedeeManifest();
// Shipper Information
$manifest->ship_from_shipper_number = $this->customerNumber;
$manifest->ship_from_name = $this->shipment->sender_company;
$manifest->ship_from_address_1 = $this->shipment->sender_address1;
$manifest->ship_from_address_2 = $this->shipment->sender_address2;
$manifest->ship_from_city = $this->shipment->sender_city;
$manifest->ship_from_zip = $this->shipment->sender_postal_code;
$manifest->ship_from_country = $this->shipment->sender_country;
$manifest->ship_from_email = $this->shipment->sender_email;
$manifest->ship_from_phone = $this->shipment->sender_phone;

// Recipient Information
$manifest->ship_to_import_field = ''; // Would be the speedee internal recipient ID if we had it.
$manifest->ship_to_shipper_number = ''; // Probably wouldn't have this.
$manifest->ship_to_name = $this->shipment->recipient_company ?? $this->shipment->recipient_contact;
$manifest->ship_to_attention = ! $this->shipment->recipient_is_residential ? substr($this->shipment->recipient_contact, 0, 35) : '';
$manifest->ship_to_address_1 = $this->shipment->recipient_address1;
$manifest->ship_to_address_2 = $this->shipment->recipient_address2;
$manifest->ship_to_city = $this->shipment->recipient_city;
$manifest->ship_to_country = $this->shipment->recipient_country;
$manifest->ship_to_email = $this->shipment->recipient_email;
$manifest->ship_to_phone = $this->shipment->recipient_phone;
$manifest->reference_1 = $this->shipment->order->customer_reference; // Additional Reference Field (Usually Invoice Number). 2, 3, 4 are also available for use.
$manifest->weight = $this->shipment->getTotalWeight();

$package = $this->shipment->getPackages()[0];
$manifest->height = $package->height;
$manifest->length = $package->length;
$manifest->width = $package->width;

$manifest->oversized = false; // All package sizes are valid
$manifest->pickup_tag = ''; // TODO: find this?
$manifest->aod = false; // TODO: Find signature required
$manifest->aod_option = 0; // TODO: Map int values to option
$manifest->cod = false; // TODO: Find COD options
$manifest->cod_value = 0;
$manifest->package_handling = 0; // TODO: Package handling rate calc?
$manifest->apply_package_handling = false;
$manifest->ship_date = date("Y-m-d H:i:s");
$manifest->bill_to_shipper_number = $this->customerNumber;
$manifest->unboxed = false; // If our cartonization forgets to send a box, re-evaluate our lives

$manifest->save();

$this->currentManifest = $manifest;

return $this;
}

protected function shipmentExecute()
{
// Currently queing this up manually for bulk process
// Yii::$app->queue->push(new \SpeeDeeShipJob([
// 'manifest' => $this->currentManifest,
// ]));
return $this;
}

protected function shipmentProcess()
{
return $this;
}
}
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
"2amigos/2fa-library": "^2.0",
"2amigos/qrcode-library": "^2.0",
"frostealth/yii2-aws-s3": "~2.0",
"league/csv": "^9.8"
"league/csv": "^9.8",
"league/flysystem-ftp": "^3.0",
"nesbot/carbon": "^2.64"
},
"require-dev": {
"yiisoft/yii2-debug": "~2.1.0",
Expand Down
Loading