first commit
This commit is contained in:
61
override/modules/zh_uspslabels/zh_uspslabels.php
Normal file
61
override/modules/zh_uspslabels/zh_uspslabels.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class Zh_UspsLabelsOverride extends Zh_UspsLabels
|
||||
{
|
||||
/**
|
||||
* Intercept the rate calculation call.
|
||||
*/
|
||||
public function getPackageShippingCost($params, $shipping_cost, $products)
|
||||
{
|
||||
// 1. Check if Bridge Module exists and is active
|
||||
/** @var Usps_Api_Bridge $bridge */
|
||||
$bridge = Module::getInstanceByName('usps_api_bridge');
|
||||
|
||||
if ($bridge && $bridge->active) {
|
||||
|
||||
// 2. Check Debug IP Logic
|
||||
// If configured, only these IPs use the new API.
|
||||
// Everyone else continues using the old logic (parent).
|
||||
if ($bridge->isIpAllowed()) {
|
||||
|
||||
// 3. Attempt to calculate rate via Bridge
|
||||
// We pass '$this' (the original module instance) to access its config settings
|
||||
$newRate = $bridge->calculateRate($params, $shipping_cost, $products, $this);
|
||||
|
||||
// If Bridge returns a valid numeric rate, use it.
|
||||
// If it returns FALSE (api error, no token, etc), fall back to old logic.
|
||||
if ($newRate !== false && $newRate !== null) {
|
||||
return $newRate;
|
||||
}
|
||||
|
||||
$bridge->log("Bridge returned false/null. Falling back to Legacy API.");
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Fallback to Legacy Logic
|
||||
return parent::getPackageShippingCost($params, $shipping_cost, $products);
|
||||
}
|
||||
|
||||
/**
|
||||
* Intercept the "Check API" button in Back Office
|
||||
*/
|
||||
public function ajaxProcessCheckApiConnection()
|
||||
{
|
||||
/** @var Usps_Api_Bridge $bridge */
|
||||
|
||||
$bridge = Module::getInstanceByName('usps_api_bridge');
|
||||
|
||||
if ($bridge && $bridge->active && $bridge->isIpAllowed()) {
|
||||
// We can implement a specific test function in the bridge later
|
||||
// For now, we just let it connect to OAuth
|
||||
// $bridge->testApiConnection();
|
||||
// return;
|
||||
}
|
||||
|
||||
parent::ajaxProcessCheckApiConnection();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user