Zen Cart Logo
Forums / Addon Shipping Modules / How to get custom shipping module costs through to checkout?

How to get custom shipping module costs through to checkout?

Views: 7,863

Results 21 to 34 of 34
30 Oct 2015, 9:41 PM
#21
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

How to get custom shipping module costs through to checkout?

Point was primarily too indicate the actions or requirements perceived to be needed by the shipping portion of ZC (or what may be necessary/desired of any eCommerce) in order to openly discuss shipping modules. Particularly because of the statement/description of how modules could handle the process better. Difficult to discuss a proposal without having the expected requirements (end state) formalized... More so when proposing changes. Ideally, more than a snippet will be addressed, though if that really is all that is/would be necessary then great. But the statement was made that it could be simplified. I'm all for simplification and seems like you have ideas, so figured would lay out the above to see what could be modified...

Wouldn't doubt that perhaps others might learn something from it and who knows improvement might be had. :)

I tried to go looking for the module "divider" but didn't readily come across it. Maybe I did and didn't realize it, anyways the point being that perhaps your three modules could be one, though I haven't a clue how you're implementing your three modules...

As to offering the lowest of all modules to be 0 and the others to be based off that, how do you plan to address in-store-pickup?

30 Oct 2015, 9:56 PM
#22
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Re: How to get custom shipping module costs through to checkout?

I would't.

The 3 separate modules is only necessary to achieve the visual representation of the data that I'm going for. I could do it with a single module, but then either I have to put gobs of programming into the template (templates SHOULD be for html, not php) or else I have to modify core files, which I'm trying to avoid. The 3-module concept is optional if someone else were using it. I was just expressing that it complicated things because I want the "cheapest is free" to carry through to all 3 modules. NOT to other 3rd party modules as well, of which I do not use. Frankly, I can't see any scenario where they would apply in this case. As I said, the module is specific to a particular distribution service. So store pickup wouldn't be offered since the goods aren't at the "store" and it is highly unlikely that any distribution service would welcome client customers coming in (in fact, part of the documents I sign is an agreement that I won't reveal their address to anyone). Similarly, things like "UPS" or "USPS" or whatever are rendered moot as they are incorporated into this module, at least as offered by the service. If the service doesn't offer it, there's no point giving the option to a customer.

When I briefly went away from ZC and tried Prestashop there was one feature they did really well... multiple warehouses. I can define "my basement" as one and "Chinese warehouse" as another and "Amazon" as another... keep track of inventory at all and offer shipping from any one, each with its own shipping calculations as necessary. Now THAT is "complicated".

31 Oct 2015, 8:01 AM
#23
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Re: How to get custom shipping module costs through to checkout?

This is getting fun again :)

I decided to get a little more detailed with the "estimated delivery date" data. The service's IPN outputs a standard number of days for each service (eg: 8-20). I didn't think that was very useful, so I've now got it so my module takes each end of that range and adjusts it for weekends as well as holidays at both the source and destination country. Of course its not perfect since there's a lot more that can impact delivery dates and, for example, accounting for a source holiday after the package has already left the source country is nonsense (but its "err on the side of caution" nonsense at least)... but in the end I now have a semi-meaningful "should arrive between Nov 12th and Nov 19th" output.

Maybe there's already something out there like that, but I hadn't seen it.

24 Jan 2017, 8:26 PM
#24
bkowal avatar

bkowal

New Zenner

Join Date:
Dec 2016
Location:
Oakville, Ontario, Canada
Posts:
5
Plugin Contributions:
0

Re: How to get custom shipping module costs through to checkout?

OK, I have exactly the same problem with the Cost and Description being wrong. The problem described as being solved, but there really was no clear description of how it was solved. I need to get this fixed ASAP for a client.

Thanks,
Bryan Kowalchuk

24 Jan 2017, 8:41 PM
#25
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Re: How to get custom shipping module costs through to checkout?

It is very unlikely that you have "exactly the same problem" that I was having. What, exactly, are you trying to do? Post your code. It has been well over a year since I looked at any of this. Yes, I resolved my issue... no, I don't remember how (or frankly, what the issue was).

24 Jan 2017, 9:48 PM
#26
bkowal avatar

bkowal

New Zenner

Join Date:
Dec 2016
Location:
Oakville, Ontario, Canada
Posts:
5
Plugin Contributions:
0

Re: How to get custom shipping module costs through to checkout?

s_mack:

It is very unlikely that you have "exactly the same problem" that I was having. What, exactly, are you trying to do? Post your code. It has been well over a year since I looked at any of this. Yes, I resolved my issue... no, I don't remember how (or frankly, what the issue was).

Thanks for the quick reply!

I wrote a shipping module that returns several quotes. It all works well. When moving off to the next page, the session variables for ($_SESSION['shipping']) contains the correct user selected shipping method ID, but the Cost and Description are always from the first shipping method in the array, regardless of what the user has selected.

You had mentioned in the post about some behaviour around the "$method" variable begin passed into the routine, but no details on what it does or how to fix the problem.

Thanks again for your help,
Bryan Kowalchuk

24 Jan 2017, 11:37 PM
#27
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Re: How to get custom shipping module costs through to checkout?

I would have to take a closer look. I don't recall off hand. If you give me the code you have, it would probably help me spot the problem more quickly. Post or PM. I think I'll have time tomorrow or maybe tonight.

25 Jan 2017, 3:38 PM
#28
bkowal avatar

bkowal

New Zenner

Join Date:
Dec 2016
Location:
Oakville, Ontario, Canada
Posts:
5
Plugin Contributions:
0

Re: How to get custom shipping module costs through to checkout?

s_mack:

I would have to take a closer look. I don't recall off hand. If you give me the code you have, it would probably help me spot the problem more quickly. Post or PM. I think I'll have time tomorrow or maybe tonight.

Thanks a ton. Below is the code (messy with debugs etc., an work in progress)
I believe I just need to understand the logic behind the $method variable and how to implement it

<?php
/**
 * @package shippingMethod
 * @copyright Copyright 2016 BILSI Inc
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: Author: Bryan Kowalchuk
 */
/**
 * bilsi
 *
 */
class bilsi extends base {
  /**
   * $code determines the internal 'code' name used to designate "this" payment module
   *
   * @var string
   */
  var $code;
  /**
   * $title is the displayed name for this payment method
   *
   * @var string
   */
  var $title;
  /**
   * $description is a soft name for this payment method
   *
   * @var string
   */
  var $description;
  /**
   * module's icon
   *
   * @var string
   */
  var $icon;
  /**
   * $enabled determines whether this module shows or not... during checkout.
   *
   * @var boolean
   */
  var $enabled;
  /**
     * Constructor
   *
   * @return BILSI
   */
  function __construct() {
    global $order, $db;

    $this->code = 'bilsi';

    $this->title = MODULE_SHIPPING_BILSI_TEXT_TITLE;
    $this->description = MODULE_SHIPPING_BILSI_TEXT_DESCRIPTION;
    $this->sort_order = MODULE_SHIPPING_BILSI_SORT_ORDER;
    $this->icon = '';
    $this->tax_class = MODULE_SHIPPING_BILSI_TAX_CLASS;
    $this->tax_basis = MODULE_SHIPPING_BILSI_TAX_BASIS;

    $shippingmarkup = 1.4;

/*
    // disable only when entire cart is free shipping
    if (zen_get_shipping_enabled($this->code)) {
      $this->enabled = ((MODULE_SHIPPING_BILSI_STATUS == 'True') ? true : false);
    }

    if ($this->enabled) {
      // check MODULE_SHIPPING_BILSI_HANDLING_METHOD is in
      $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_BILSI_HANDLING_METHOD'");
      if ($check_query->EOF) {
        $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Handling Per Order or Per Box', 'MODULE_SHIPPING_BILSI_HANDLING_METHOD', 'Order', 'Do you want to charge Handling Fee Per Order or Per Box?', '6', '0', 'zen_cfg_select_option(array(\'Order\', \'Box\'), ', now())");
      }
    }
*/
    $this->enabled = true;

  /*
    if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_BILSI_ZONE > 0) ) {
      $check_flag = false;
      $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . "
                             where geo_zone_id = '" . MODULE_SHIPPING_BILSI_ZONE . "'
                             and zone_country_id = '" . (int)$order->delivery['country']['id'] . "'
                             order by zone_id");
      while (!$check->EOF) {
        if ($check->fields['zone_id'] < 1) {
          $check_flag = true;
          break;
        } elseif ($check->fields['zone_id'] == $order->delivery['zone_id']) {
          $check_flag = true;
          break;
        }
        $check->MoveNext();
      }

      if ($check_flag == false) {
        $this->enabled = false;
      }
    }
*/    
  }
  /**
   * Obtain quote from shipping system/calculations
   *
   * @param string $method
   * @return array
   */
  function quote($method = '') {
    global $order, $shipping_weight, $shipping_num_boxes;

    $total_weight_units = $shipping_weight;

    // customer details      
    $street_address = $order->delivery['street_address'];
    $street_address2 = $order->delivery['suburb'];
    $city = $order->delivery['city'];
    $state = zen_get_zone_code($order->delivery['country']['id'], $order->delivery['zone_id'], '');
   // if ($state == "QC") $state = "PQ";
    $postcode = str_replace(array(' ', '-'), '', $order->delivery['postcode']);
    if(isset($order->delivery['country']['iso_code_2'])) {
      $country_id = $order->delivery['country']['iso_code_2'];
    }
    else {
     $country_id = $this->country_iso($order->delivery['country']);
    }  


    if ($method != '')
    {
      $this->quotes = array('id' => $this->code , 'module' => 'BILSI Shipping');
      $methods = array('id' => $_SESSION['shipping']->id , 'title' => 'Method: '.$method , 'cost' => 100000);
      return $quotes;
    } 



/*
    $webxmlrequest = '<?xml version="1.0" encoding="utf-8"?>
<ShipmentRateRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <User_Name>test</User_Name>
  <Password>test</Password>
  <Client_Id>test</Client_Id>
  <Receiver>
    <City>'.$city.'</City>
    <State_Province>'.$state.'</State_Province>
    <Postal_Zip_Code>'.$postcode.'</Postal_Zip_Code>
    <Country>'.$country_id.'</Country>
  </Receiver>
  <Sender>
    <SenderId>0</SenderId>
    <City>MISSISSAUGA</City>
    <State_Province>ON</State_Province>
    <Postal_Zip_Code>L5L5Y5</Postal_Zip_Code>
    <Country>CA</Country>
  </Sender>
  <Shipment_Info>
    <Wo_Type>SMP</Wo_Type>
    <No_Packages>1</No_Packages>
    <No_OverWeight_Packages>0</No_OverWeight_Packages>
    <No_Ltl_Skids>0</No_Ltl_Skids>
    <Total_Weight>'.$shipping_weight.'</Total_Weight>
    <Total_Dim_Weight>0</Total_Dim_Weight>
  </Shipment_Info>
  <SignatureRequired>false</SignatureRequired>
  <IsResidential>false</IsResidential>
  <DeclaredValue>0</DeclaredValue>
</ShipmentRateRequest>';
*/

//Object for use later in postback to Bilsi
$orderRequest['request'] = array( 'User_Name'=>'test',
                                'Password'=>'test',
                                'Client_Id'=>'test',
                                'Po_Number'=> '0',
                                'Appointment_Required'=> 'No',
                                'Appointment_Notes'=>'',
                                'Consignee_Info' => array( 'Consignee_Id'=> 0,
                                                          'Name'=>$_SESSION['customer_first_name'].' '.$_SESSION['customer_last_name'],
                                                          'Address_1'=>$street_address,
                                                          'Address_2'=>$street_address2,
                                                          'City'=>$city,
                                                          'State_Province'=>$state,
                                                          'Postal_Zip_Code'=>$postcode,
                                                          'Country'=>$country_id,
                                                          'Phone'=>'',
                                                          'Email'=>$_SESSION['customer_email_address'],
                                                          'ValidateAddressFlag'=>0),
                                'Shipment_Info' => array( 'Wo_Type'=>'SMP',
                                                          'No_Packages'=> $shipping_num_boxes,
                                                          'No_OverWeight_Packages'=>0,
                                                          'No_Ltl_Skids'=> 0,
                                                          'Total_Weight'=> $shipping_weight,
                                                          'Total_Dim_Weight'=> 0),
                                'GenerateShippingLabel'=>0,
                                'ShipFromAddressId'=>0,
                                'ServiceType'=>101,
                                'SignatureRequired'=>0,
                                'IsResidential'=>'true',
                                'DeclaredValue'=>0,
                                'ReferenceNumber'=>0);

//Add all the product info
/*
-<s:sequence>
<s:element name="ProductNumber" type="s:string" maxOccurs="1" minOccurs="0"/>
<s:element name="AlternateReference" type="s:string" maxOccurs="1" minOccurs="0"/>
<s:element name="Description" type="s:string" maxOccurs="1" minOccurs="0"/>
<s:element name="GeneralDescription" type="s:string" maxOccurs="1" minOccurs="0"/>
<s:element name="UnitPrice" type="s:float" maxOccurs="1" minOccurs="1"/>
<s:element name="Weight" type="s:float" maxOccurs="1" minOccurs="1"/>
<s:element name="Length" type="s:float" maxOccurs="1" minOccurs="1"/>
<s:element name="Height" type="s:float" maxOccurs="1" minOccurs="1"/>
<s:element name="Width" type="s:float" maxOccurs="1" minOccurs="1"/>
<s:element name="HSCode" type="s:string" maxOccurs="1" minOccurs="0"/>
<s:element name="CountryOfOrigin" type="s:string" maxOccurs="1" minOccurs="0"/>
<s:element name="CurrencyId" type="s:int" maxOccurs="1" minOccurs="1"/>
<s:element name="SystemOfUnitsId" type="s:int" maxOccurs="1" minOccurs="1"/>
<s:element name="ClientEnterHSCode" type="s:boolean" maxOccurs="1" minOccurs="1"/>
<s:element name="NAFTAApplied" type="s:boolean" maxOccurs="1" minOccurs="1"/>
<s:element name="Quantity" type="s:int" maxOccurs="1" minOccurs="1"/>
</s:sequence>

Product
    [0] => Array
        (
            [id] => 15
            [category] => 14
            [name] => Frantic Linked
            [model] => DVD-FRAN
            [image] => dvd/frantic.gif
            [price] => 35.0000
            [quantity] => 1
            [weight] => 7
            [final_price] => 35
            [onetime_charges] => 0
            [tax_class_id] => 1
            [attributes] => 
            [attributes_values] => 
            [products_priced_by_attribute] => 0
            [product_is_free] => 0
            [products_discount_type] => 0
            [products_discount_type_from] => 0
            [products_virtual] => 0
            [product_is_always_free_shipping] => 0
        )

*/

$products = $_SESSION['cart']->get_products();


foreach($products as $product)
{
 //   echo 'Product: '.$product['id'];  
  $nextproduct['ProductNumber'] = $product['id'];
  $nextproduct['Description'] = $product['name'];
  $nextproduct['UnitPrice'] = $product['price'];
  $nextproduct['Weight'] = $product['weight'];
  $nextproduct['Length'] = 0;
  $nextproduct['Height'] = 0;
  $nextproduct['Width'] = 0;
  $nextproduct['CurrencyId'] = 0;
  $nextproduct['SystemOfUnitsId'] = 0;
  $nextproduct['ClientEnterHSCode'] = 0;
  $nextproduct['NAFTAApplied']=0;
  $nextproduct['Quantity']=$product['quantity'];
  $nextproduct['CountryOfOrigin']='CN';
  $nextproduct['HSCode'] = '9999999999';
  $orderRequest['request']['Shipment_Info']['Products'][] = $nextproduct;  
}


$webrequest['request'] = array( 'User_Name'=>'test',
                                            'Password'=>'test',
                                            'Client_Id'=>'test',
                                            'Receiver' => array('City'=>$city,
                                                                'State_Province'=>$state,
                                                                'Postal_Zip_Code'=>$postcode,
                                                                'Country'=>$country_id),
                                            'Sender' => array('SenderId'=>'0',
                                                               'City'=>'MISSISSAUGA',
                                                               'State_Province'=>'ON',
                                                               'Postal_Zip_Code'=>'L5L5Y5',
                                                               'Country'=>'CA'),
                                            'Shipment_Info' => array('Wo_Type'=>'SMP',
                                                                      'No_Packages'=> $shipping_num_boxes,
                                                                      'No_OverWeight_Packages'=>0,
                                                                      'No_Ltl_Skids'=> 0,
                                                                      'Total_Weight'=> $shipping_weight,
                                                                      'Total_Dim_Weight'=> 0),
                                            'SignatureRequired'=>'false',
                                            'IsResidential'=>'true',
                                            'DeclaredValue'=>0);

  $url = 'http://www.bilsi.com/Freight/Services/ShipmentRateService.asmx?WSDL';
  $params = array('trace' => 1, 'soap_version'   => SOAP_1_2, 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP, 'encoding'=>'UTF-8', 'trace' => 1, 'exceptions' => true, 'cache_wsdl' => WSDL_CACHE_NONE, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS);
  $client = new SoapClient($url, $params);
 
  try{
    $result = $client->GetRate($webrequest);
  }
  catch (Exception $e)
  {
     $message = 'Error in processing transaction.<br /><br />'; 
     $message .= $response->Notifications->Severity;
     $message .= ': '.$e->getMessage();           
     $message .= $response->Notifications->Message . '<br />';
     $quotes = array('module' => $this->title,
                              'error'  => $message);
    echo 'Caught exception: ',  $e->getMessage();
    return $quotes; 
  }


//echo '<!-- Request: ';
//print_r($webrequest['request']);

echo '<!--  Shipping: ';
print_r($_SESSION['shipping']);

echo '-- Method';
echo $method;

    echo '<!-- Result: ';
    print_r($result);

/*
    $ratecount = count($result->GetRateResult->ShipmentRates->ShipmentRate);

    //Add the markup
    //$shiprate = $shiprate * $shippingmarkup;
    $this->quotes = array('id' => $this->code,
                          'module' => 'BILSI Shipping',
                          'methods' => array(array('id' => 'Air101',
                                                   'title' => $result->GetRateResult->ShipmentRates->ShipmentRate[0]->ServiceDescription,
                                                   'cost' => $result->GetRateResult->ShipmentRates->ShipmentRate[0]->Total_Charge),
                                                   array('id' => 'Ground102',
                                                   'title' => $result->GetRateResult->ShipmentRates->ShipmentRate[1]->ServiceDescription,
                                                   'cost' => $result->GetRateResult->ShipmentRates->ShipmentRate[1]->Total_Charge)));

echo '-- Quotes: ';
print_r( $this->quotes);
*/


    $shiprates = $result->GetRateResult->ShipmentRates->ShipmentRate;

    if (is_array($shiprates) && sizeof($shiprates) > 0)
    {
      $this->quotes = array('id' => $this->code , 'module' => 'BILSI Shipping');
      $methods = array();
  
      for ($i = 0; $i < sizeof($shiprates); $i ++)
      {
     //   list ($type, $cost) = each($shiprates[$i]);
   //     $type = html_entity_decode($type);
     //   if ($this->cp_online_handling == true)
     //   {
     //     if ($method == '' || $method == $type)
     //     {
     //       $methods[] = array('id' => $type , 'title' => $type , 'cost' => $cost + $this->handling_cp);
      //    }
     //   } else
      //  {
      //    if ($method == '' || $method == $type)
          
            $methods[$i] = array('id' => $shiprates[$i]->ServiceType , 'title' =>$shiprates[$i]->ServiceDescription , 'cost' => $shiprates[$i]->Total_Charge + $i);
          
        }
      }
  //    if ($this->tax_class > 0)
   //   {
   //     $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
   //   }
  
  
    $this->quotes['methods'] = $methods;

    echo '-- Quotes: ';
print_r( $this->quotes);


    if ($this->tax_class > 0) {
      $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
    }

    if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title);



//    echo '<!-- Quotes: ';
//    echo 'Products: ';
//    print_r($products);
//    echo 'Order: ';
 //   print_r($order);
 //   echo 'Request: ';
  //  print_r($_SESSION);S
  //  print_r($orderRequest);
    //print_r($this->quotes);
    //print_r($_SESSION['shipping']);
   // print_r($rateobj);
    echo '-- Bilsi Shipping Object -- ';
   //print_r($result->GetRateResult->ShipmentRates->ShipmentRate[0]->Total_Charge);
   //print_r($orderRequest);
  
    echo ' -- Shipping Rate: '.$shiprate;
 //   print_r($result);
    echo ' -->';

    //Create a session variable that can be retrived on the final order page
    $_SESSION['Bilsi_shipping'] = $orderRequest;
    return $this->quotes;
  }
  /**
   * Check to see whether module is installed
   *
   * @return boolean
   */
  function check() {
   /*
    global $db;
    if (!isset($this->_check)) {
      $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_BILSI_STATUS'");
      $this->_check = $check_query->RecordCount();
    }*/
    return true;
  }
  /**
   * Install the shipping module and its configuration settings
   *
   */
  function install() {
    global $db;
  }
  /**
   * Remove the module and all its settings
   *
   */
  function remove() {
    global $db;
  }
  /**
   * Internal list of configuration keys used for configuration of the module
   *
   * @return array
   */
  function keys() {
    return array('MODULE_SHIPPING_BILSI_STATUS', 'MODULE_SHIPPING_BILSI_COST', 'MODULE_SHIPPING_BILSI_HANDLING', 'MODULE_SHIPPING_BILSI_HANDLING_METHOD', 'MODULE_SHIPPING_BILSI_TAX_CLASS', 'MODULE_SHIPPING_BILSI_TAX_BASIS', 'MODULE_SHIPPING_BILSI_ZONE', 'MODULE_SHIPPING_BILSI_SORT_ORDER');
  }
}
?>
25 Jan 2017, 4:54 PM
#29
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: How to get custom shipping module costs through to checkout?

Hope you realize that everyone who has subscribed to this thread now has your username and password for this module...

Those values should be stored in the database using a constant that is set in the modules->shipping area for your module. That would be further helped by actually having code in the install section of this plugin.

That said, and I didn't look through "everything" just enough to possibly target the issue of returning/using the fact that $method is provided/not blank.

In your if statement of the quote function:

if ($method != '') {

You assign $this->quotes to something, but then return $quotes without setting $quotes to anything. The return should be $this->quotes and at least the data set above within the if statement will be provided back.

It otherwise looks like there is a lot to be done with the module to have it at full operation. For example, the module is always active, even if free shipping for the entire order is an option. There is no formal install, everyone will have the same username/password combination, the price markup is a constant (not modifiable in the admin), etc... just a few things noted as you begin/continue your way to getting the shipping module you want, desire, and/or need...

25 Jan 2017, 6:26 PM
#30
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Re: How to get custom shipping module costs through to checkout?

He did say it was a work in progress :)

MC#s is right, change $quotes to $this->quotes and you may be back in business

25 Jan 2017, 7:38 PM
#31
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: How to get custom shipping module costs through to checkout?

s_mack:

He did say it was a work in progress :)

MC#s is right, change $quotes to $this->quotes and you may be back in business

Quite true and by the gentile reminder, I must have blown my courtesy out in my last tissue... :)

My apologies, I did have an initial different perspective on the status of the module thinking that this was something of a "last" hurtle. I guess I was taken aback by the current status. Ahh well, we all work differently. Guess could say proof of concept is likely to work, now the hard part. :)

At the same time, it also isn't in my nature to not try to offer/identify areas of improvement. :) Like to see success, even if I (do/will) have nothing to do with it. :)

25 Jan 2017, 8:05 PM
#32
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Re: How to get custom shipping module costs through to checkout?

Your points were all valid, of course. Once he gets things functioning, he should act on your advice.

3 Feb 2017, 1:55 AM
#33
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: How to get custom shipping module costs through to checkout?

bkowal:

if ($method != '')    {
  $this->quotes = array('id' => $this->code , 'module' => 'BILSI Shipping');
  $methods = array('id' => $_SESSION['shipping']->id , 'title' => 'Method: '.$method , 'cost' => 100000);
  return $quotes;
}
I'm inclined to suggest changing that to be more akin to:```
    if ($method != '')
    {
      $this->quotes = array('id' => $this->code , 
                            'module' => 'BILSI Shipping',
                            'methods' => array('id' => $_SESSION['shipping']->id , 'title' => 'Method: '. $method , 'cost' => 100000),
                            );
      return $this->quotes;
    }

That should let you see more of what you expect. You can tweak the 'methods' sub-array in there as you continue your development.

However, it's worth pointing out, as s_mack has pointed out dozens of times in preceding posts, that some of this infrastructure is more complicated than it needs to be. Particularly the part that typically makes the shipping module re-retrieve quotes from 3rd party systems over and over again on each page of checkout, even when the "selected" method is fine. (It'd make sense to retrieve all possible options again if there were a need to alter the choice, but when it's decided then it should just be passed along.) This isn't the time to debate the internal workings of that. However, I'm pointing it out to explain why in other 3rd-party shipping modules you'll sometimes find that repetitive quote-retrieval happening ... and that too can make the code hard to understand.

3 Feb 2017, 5:16 AM
#34
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: How to get custom shipping module costs through to checkout?

DrByte:

Particularly the part that typically makes the shipping module re-retrieve quotes from 3rd party systems over and over again on each page of checkout, even when the "selected" method is fine.

Sorry - I feel a need to stick my nose in again, because I'm not convinced about the 'over and over' again - With all of dev work I've done with the ozpost module I've only ever noted one 'loop'. There is the initial quote request (that returns all methods from a given courier/carrier) and a second quote request for the chosen method.

I always thought it a little silly to re-request the quotes from the servers for this second request, so I created a caching mechanism so that the 'full list of quotes' gets saved to a SESSION file (or DB) , and a re-request (after checking that the products, destination, etc haven't changed) uses the cached data rather than hitting the servers again.

Ideally, this caching is something that should/could be done with the core code (as if it weren't complicated enough already), but since the latest OP is creating/customizing code anyway then I'm thinking that this suggestion to cache the data rather than re-requesting from the server would be a worthy addition.

Anyway, just a suggestion/idea.

Cheers
Rod