nanoblocktech/shipping-calculator

PHP class to determines shipping fee based on origin latitude and lonitude of customer from business location.

1.4 2023-11-21 00:34 UTC

This package is auto-updated.

Last update: 2024-09-21 19:58:07 UTC


README

Determines the shipping fee based on the customer's longitude and latitude to the business location.

Functions

  • Calculates the distance between business and customer locations
  • Determines the shipping fee based on the provided charge per distance.
  • Determines the estimated traveling time based on distance and speed

Installation Guide via Composer:

composer require nanoblocktech/shipping-calculator

Usages

use Luminova\ExtraUtils\ShippingCalculator;

$calculator = new ShippingCalculator();

// Set business and customer locations

$calculator->setOrigin(6.47427, 7.56196); // Business location (Enugu Airport Nigeria)
$calculator->setDestination(6.51181, 7.35535); // Customer location (Udi Nigeria)
$calculator->setCharge(100); // Initial shipping cost per distance km, or ml

// Calculate distance and return new ShippingDistance instance class

$distance = $calculator->getDistance();

// Get the estimated time information

$time = $calculator->getTime();

// Get your calculated information

echo "Distance: $distance->toDistance() \n";
echo "Distance[km|ml]: $distance->toString() \n";
echo "Shipping Fee: $distance->getCurrency(2)\n";
echo "Shipping Fee: $distance->getCharges()\n";

Methods

ShippingCalculator

Setting up your calculations $calculator = new ShippingCalculator(ShippingCalculator::KM);

ShippingDistance

The method which $distance = $calculator->getDistance(); is returned

ShippingTime

The method which $time = $distance->getTime(); is returned