-
Notifications
You must be signed in to change notification settings - Fork 0
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
cdwieber
wants to merge
15
commits into
master
Choose a base branch
from
feature/speedee-integration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7814d02
Migration and model for SpeeDee manifests
ca30024
Merge branch 'master' into feature/speedee-integration
cdwieber e4cdd3e
Defeat Bane and restore order to Gotham City
0754635
Merge remote-tracking branch 'origin/feature/speedee-integration' int…
26722cd
Scaffold out bulk of FTP transfer and shipping logic
1daf7b6
Add timestamps to SpeedeeManifest model
0d6589b
Use caching to determine customer file index.
586bbbd
"handle" exceptions the same way I handle all my problems
43573e8
Add menu item
5f71388
Add menu item
fdb4eab
AJAX tables
7265b28
WIP; can't get ftp to write
cca24f5
Improve exception handling
d7463a4
remove wip
948f7d2
Update Carrier model for speedee
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'], | ||
[['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']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
common/models/shipping/extension/wsdl/SpeeDeePlugin.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<?php | ||
|
||
namespace common\models\shipping\extension; | ||
|
||
use Cassandra\Date; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?