Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2009
    Posts
    37
    Plugin Contributions
    0

    Default Simple PHP script to convert spreadsheet sheet into text formatted for Zone Shipping

    Takes an input CSV spreadsheet file of shipping prices and outputs the format needed for Zen Cart's zone shipping page.

    If you have a shipping table with many different columns of prices for various shipping weights to many different countries that you need to import into a Zen Cart Zone Shipping module, this is the script for you. However, it will make life easier for anyone using Zone Shipping, even if you only have a few zones, as it will automatically convert a properly formatted spreadsheet page into text you can easily copy and paste into the fields in Admin Panel -> Modules -> Shipping -> [select 'zones' module] -> edit.

    You can copy and paste the contents of this pastebin into makeZCZones.php: https://pastebin.com/PdLBPwb0




    usage:
    php7.2 makeZCZones.php [input.csv]

    for instance: (assuming you have a shell such as linux/OSX/'Windows Subsystem for Linux'):
    * If you are on Windows and don't want to mess with WSL, but have SSH/Telnet access to your web server, you can FTP the CSV to your server and then run the command via SSH.


    php makeZCZones.php thisIsMyFile.csv | less

    or:

    php makeZCZones.php thisIsMyFile.csv > outputForZCZones.txt
    *
    requires php installed on computer.

    Format of CSV:

    [ Blank Cell ] [ Zones/Countries 2 letter ISO Codes -------->
    [ Weight ] [Start of shipping table --->
    |
    |
    \/



    2 letter ISO codes:
    https://www.nationsonline.org/onewor..._code_list.htm

    Example .csv file:
    https://docs.google.com/spreadsheets...it?usp=sharing

    Google Docs: File -> Download As -> Comma Seperated Values (.csv, current sheet)
    Excel: File -> Save As -> CSV
    Gnumeric: Data -> Export Data -> Export as CSV File...
    LibreOffice: File -> Save As -> Text CSV



    Example output:


    Zone Name: AU

    Shipping String:

    0.5:18500, 1:21000, 1.5:24500, 2:28500, 2.5:32500, 3:36500, 3.5:40000, 4:44000, 4.5:48000, 5:52000, 5.5:56000, 6:60000, 6.5:64000, 7:68000, 7.5:72000, 8:75500, 8.5:79500, 9:83500, 9.5:87500, 10:91500, 10.5:95500, 11:99500, 11.5:103000, 12:107000, 12.5:111000, 13:115000, 13.5:119000, 14:123000, 14.5:127000, 15:130500, 15.5:134500, 16:138500, 16.5:142500, 17:146500, 17.5:150500, 18:154500, 18.5:158500, 19:162000, 19.5:166000, 20:170000




    Zone Name: BR

    Shipping String:

    0.5:28000, 1:32000, 1.5:36000, 2:40000, 2.5:43000, 3:49500, 3.5:55500, 4:62000, 4.5:68000, 5:74500, 5.5:80500, 6:86500, 6.5:93000, 7:99000, 7.5:105000, 8:111500, 8.5:117500, 9:124000, 9.5:130000, 10:136000, 10.5:142500, 11:148500, 11.5:155000, 12:161000, 12.5:167000, 13:173500, 13.5:179500, 14:186000, 14.5:192000, 15:198500, 15.5:204500, 16:210500, 16.5:217000, 17:223000, 17.5:229500, 18:235500, 18.5:241500, 19:248000, 19.5:254000, 20:260500





    <?php



    class makeZCZones {

    private $zonesCount;
    private $zonesArray;

    private $weightsCount;
    private $weightsArray;

    private $shippingTable;

    private function readAndParseCSV() {

    global $argv;

    if(!isset($argv[1])) { die('No Input File!'); }


    $file = fopen($argv[1],"r");

    $countriesRow = fgetcsv($file);

    unset($countriesRow[0]); //the first element should be empty so drop it

    $this -> zonesArray = $countriesRow;
    $this -> zonesCount = count($countriesRow);

    $rowCounter = 0;

    while(!feof($file))
    {
    $row = fgetcsv($file);

    if( gettype($row) == 'array' && count($row) > 0) {

    $this -> weightsArray[$rowCounter] = $row[0];

    $this -> shippingTable[$rowCounter] = $row;

    $rowCounter++;
    }
    }

    fclose($file);

    }

    private function createZCStrings() {
    $fullOutputString = "";
    foreach($this->zonesArray as $key => $zoneName) {

    $fullOutputString .= "\r\n\r\n\r\nZone Name: ".$zoneName."\r\n\r\nShipping String:\r\n\r\n";
    $shippingString = "";

    foreach($this->shippingTable as $row) {

    $shippingString .= $row[0] . ":" . $row[$key];
    $shippingString .= ", ";
    }

    $shippingString = substr($shippingString, 0, -2);

    $fullOutputString .= $shippingString."\r\n\r\n";

    }

    echo $fullOutputString;

    }



    public function __construct() {
    $this->readAndParseCSV();
    $this->createZCStrings();
    }



    }

    $makeZCZ = new makeZCZones();

    ?>

  2. #2
    Join Date
    Mar 2009
    Posts
    37
    Plugin Contributions
    0

    Default Re: Simple PHP script to convert spreadsheet sheet into text formatted for Zone Shipp

    For instance, if you can find a table like this from your shipping company's website, you should be able to just copy and paste it into a spreadsheet, convert all individual column headers from the country name to the 2 digit ISO code ZC uses, export it to CSV, run this script on it, and copy and paste the output text into each zone. Done :)

    https://ems.epost.go.kr/front.EmsDel...ivery02.postal
    Last edited by buddhaflow; 20 Feb 2019 at 01:50 AM.

 

 

Similar Threads

  1. v154 application/x-httpd-php html_header.php PHP script text
    By Parafanaylya in forum General Questions
    Replies: 3
    Last Post: 29 Aug 2015, 03:06 PM
  2. insert php script into item descritption for domain name registration ???
    By modchipfitters.co.uk in forum Setting Up Categories, Products, Attributes
    Replies: 14
    Last Post: 24 Aug 2008, 06:28 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR