If this is your first visit, check our documentation. To post, register or login.

Looking For Help With a Plugin

Started by zippkits on 21 Nov 2016, 2:24 AM · Views: 345

Results 21 to 29 of 29
22 Nov 2016, 9:27 PM
#21
zippkits avatar

zippkits

New Zenner

Join Date:
Dec 2010
Location:
Central Indiana
Posts:
36
Plugin Contributions:
0

Looking For Help With a Plugin

Works perfectly!
Thanks MC!

I just added the code to a fresh copy of the php file, and it works!

Thank you so much!

Joe

22 Nov 2016, 9:30 PM
#22
mc12345678 avatar

mc12345678

Totally Zenned

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

Re: Looking For Help With a Plugin

Zippkits:

Works perfectly!
Thanks MC!

I just added the code to a fresh copy of the php file, and it works!

Thank you so much!

Joe
No promises, but will look into possibly submitting an update to the plugin unless someone "beats" me to it.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

22 Nov 2016, 9:41 PM
#23
zippkits avatar

zippkits

New Zenner

Join Date:
Dec 2010
Location:
Central Indiana
Posts:
36
Plugin Contributions:
0

Re: Looking For Help With a Plugin

Note also that it works perfectly on both 1.39h and 1.5.5b...

22 Nov 2016, 9:44 PM
#24
mc12345678 avatar

mc12345678

Totally Zenned

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

Re: Looking For Help With a Plugin

Zippkits:

Note also that it works perfectly on both 1.39h and 1.5.5b...

Good to know. Also a tribute to the design of ZC that a shipping module does all it needs in such varying environments.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

23 Nov 2016, 7:53 AM
#25
rodg avatar

rodg

Deceased

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

Re: Looking For Help With a Plugin

mc12345678:

So using the above code pasted/modified by rod:

$bkgdetails = $dhlQuote->GetQuoteResponse->BkgDetails;

$methods = array();

$db_allowed_metods = explode(", ", MODULE_SHIPPING_DHL_TYPES);
foreach($db_allowed_metods as $db_method){
$allowed_methods[] = substr($db_method, 0,1);
}
foreach($bkgdetails->QtdShp as $detailed){
if ((int)$detailed->ShippingCharge != 0 && (!zen_not_null($method) || zen_not_null($method) && (string)$method == (string)$detailed->GlobalProductCode)){
$title = ucwords(strtolower((string)$detailed->LocalProductName));
$title = trim(str_replace('Nondoc', "", $title));
$methods[] = array('id' => (string)$detailed->GlobalProductCode,
'title' => $title,
'cost' => ((string)$detailed->ShippingCharge) + (MODULE_SHIPPING_DHL_HANDLING_METHOD == 'Box' ? MODULE_SHIPPING_DHL_HANDLING * $shipping_num_boxes : MODULE_SHIPPING_DHL_HANDLING) );

      }
  }
  

if ( (is_array($methods)) && (sizeof($methods) > 0) ) {
  switch (SHIPPING_BOX_WEIGHT_DISPLAY) {
> 
> Sorry, I didn't remove all the extra text that Rod added

Just for clarification,the stuff highlighted in red is original code.The reason for highlighting was because It appears to be currently unused. In order to be useful, the config settings need the MODULE_SHIPPING_DHL_TYPES array variables, and the foreach loop needs a test/check so that only those in the $allowed_methods become part of the $methods array. 

Excellent work on the fix BTW.  

Cheers
RodG

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.

23 Nov 2016, 1:38 PM
#26
mc12345678 avatar

mc12345678

Totally Zenned

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

Re: Looking For Help With a Plugin

RodG:

Just for clarification,the stuff highlighted in red is original code.The reason for highlighting was because It appears to be currently unused. In order to be useful, the config settings need the MODULE_SHIPPING_DHL_TYPES array variables, and the foreach loop needs a test/check so that only those in the $allowed_methods become part of the $methods array.

Excellent work on the fix BTW.

Cheers
RodG

Ahhh... Gotcha now...

Unfortunately at the moment I don't see where MODULE_SHIPPING_DHL_TYPES is defined so I provide the following "intermediate" code to somewhat get there. I assume one goal is to provide selections in the admin control to choose which options/types are to be presented (such as to not show the medical option) but the way I incorporate below a coded define could be used to provide the selections. I am not familiar enough with DHL at the moment to be able to identify what options should be in the below expected comma separated list, but this would help out:

The code should then read

  $bkgdetails = $dhlQuote->GetQuoteResponse->BkgDetails;
    
    $methods = array();
    $allowed_methods = array();
      $db_allowed_metods = explode(",", MODULE_SHIPPING_DHL_TYPES);
      foreach($db_allowed_metods as $db_method){
          $add_method = trim($db_method);
          if (zen_not_null($add_method)) {
              $allowed_methods[] = substr($add_method, 0,1);
          }
      }
      unset($add_method);
      unset($db_method);
      unset($db_allowed_metods);

      foreach($bkgdetails->QtdShp as $detailed){
          if ((int)$detailed->ShippingCharge != 0 && (!zen_not_null($method) || zen_not_null($method) && (string)$method == (string)$detailed->GlobalProductCode) && (defined(MODULE_SHIPPING_DHL_TYPES) ? count($allowed_methods) > 0 && in_array((string)$detailed->GlobalProductCode, $allowed_methods): true))){
              $title = ucwords(strtolower((string)$detailed->LocalProductName));
              $title = trim(str_replace('Nondoc', "", $title));
              $methods[] = array('id' => (string)$detailed->GlobalProductCode,
                           'title' => $title,
                           'cost' => ((string)$detailed->ShippingCharge) + (MODULE_SHIPPING_DHL_HANDLING_METHOD == 'Box' ? MODULE_SHIPPING_DHL_HANDLING * $shipping_num_boxes : MODULE_SHIPPING_DHL_HANDLING) );
     
          }
      }
      
    if ( (is_array($methods)) && (sizeof($methods) > 0) ) {
      switch (SHIPPING_BOX_WEIGHT_DISPLAY) {

Now it does this: if there is no $method provided then, add whatever is returned, if there is a method provided to the quote then only add the data below that matches the method sought and in both cases provided the following evaluates to true. If the constant MODULE_SHIPPING_DHL_TYPES is defined then evaluate the allowed methods to determine if the current method should be added or not. If the constant is defined and in the definition there is at least one allowed method then if the evaluated method is allowed then add it. If the evaluated method is not in the allowed list or the constant is defined but doesn't contain a method then do not add the method to the quote. Now, if the constant is not defined (current default behavior with this plugin) then this portion of the evaluation is true and the method is added if the previous logic is correct/true. Further if no method is returned that matches then no method is added.

Okay, so how should the constant be populated? Well, it appears that DHL or perhaps it is just this plugin, looks at the first character of the string though not sure if DHL uses capitalization such as b and B differently, but the above code will evaluate those two differently. Means that there are 62 combinations available when using numbers and english letters [0-9, a-z and A-Z] only.

Unlike the previous/original code which expected the string to be "well" entered with a space following a comma, the above ignores the spaces, whether present or not and only populates the $allowed_methods with values that exist (ie. a defined empty constant will result in no matches and no results being provided as well if a comma is "accidentally" added that would cause a "method" to appear present then that empty method is not added).

So the define could be something like this with the appropriate "types" included. I thought I recalled seeing that some of the types included: 8 and P, I didn't pay that much attention. So the define which could be added into the store side includes/extra_configures:

<?php 
define('MODULE_SHIPPING_DHL_TYPES', '8,P');

Otherwise some other preferably user friendly "method" of defining the available and/or allowable types is needed for this plugin. At the very least the above define should be in advance of its first use.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

24 Nov 2016, 9:09 AM
#27
rodg avatar

rodg

Deceased

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

Re: Looking For Help With a Plugin

mc12345678:

Ahhh... Gotcha now...

Unfortunately at the moment I don't see where MODULE_SHIPPING_DHL_TYPES is defined

That's because the'ye not defined. Hense that part of code is unsued.

mc12345678:

So the define could be something like this with the appropriate "types" included. I thought I recalled seeing that some of the types included: 8 and P, I didn't pay that much attention. So the define which could be added into the store side includes/extra_configures:

<?php define('MODULE_SHIPPING_DHL_TYPES', '8,P'); ``` > > Otherwise some other preferably user friendly "method" of defining the available and/or allowable types is needed for this plugin. At the very least the above define should be in advance of its first use. Something like this should do the job: ``` $db->Execute("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Methods', 'MODULE_SHIPPING_DHL_TYPES', '', 'Select the methods to allow', '6', '19', 'zen_cfg_select_multioption(array(\'Medical Express\', \'Express Worldwide\', \'Express Easy\'), ', now())"); ``` Alas, I don't know what 'methods' DHL support either, so I've just used values 'Medical Express ' , 'Express Worldwide' & 'Express Easy' in the code example as per the screenshot posted earlier. Cheers Rod ps. Module will need to be uninstalled/reinstalled to enable this new option.

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.

24 Nov 2016, 12:58 PM
#28
mc12345678 avatar

mc12345678

Totally Zenned

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

Re: Looking For Help With a Plugin

Won't quite be that "easy", again, the code uses the first letter of some string as the id for the method, two of those methods start with the same letter, so there needs to be something else involved, either the addition of the unique character to the beginning of "each" of the texts or the use of a separate id portion of the array.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

25 Nov 2016, 6:21 AM
#29
rodg avatar

rodg

Deceased

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

Re: Looking For Help With a Plugin

mc12345678:

Won't quite be that "easy", again, the code uses the first letter of some string as the id for the method, two of those methods start with the same letter, so there needs to be something else involved, either the addition of the unique character to the beginning of "each" of the texts or the use of a separate id portion of the array.

Aha. I see what you are doing, try this:

Change:

in_array((string)$detailed->GlobalProductCode, $allowed_methods)

To:

in_array((string)$detailed->LocalProductName, $allowed_methods)

IOW, do the 'allowed' check based on the name rather than the code.

Well, that's the theory. In practice, I've no idea that this is really for....,

              $title = ucwords(strtolower((string)$detailed->LocalProductName));
              $title = trim(str_replace('Nondoc', "", $title));

....but if the LocalProductName's do include the text ''Nondoc', then you'll need to move these two lines so they occur before your allowed_methods test, and then change the test to

in_array(($title, $allowed_methods)

The ozpost module works very similar to this because by taking the approach you have, the settings will need to hold the ID/Codes rather than the names, and for configuration purposes these are pretty meaningless. You'll still need to use the ProductCodes for the methods[] array id for it to function though but as long as they are unique (which I assume they would be), but I don't see any other problem. The ID/Codes don't get displayed anywhere and even if several start with the same letter it doesn't really matter, as long as they are as unique as the descriptions/titles themselves.

The code should then look something like this:

       foreach($bkgdetails->QtdShp as $detailed){
            $title = ucwords(strtolower((string)$detailed->LocalProductName));
              $title = trim(str_replace('Nondoc', "", $title));
              if (in_array($title, $allowed_methods)) {
          
             if ((int)$detailed->ShippingCharge != 0 && (!zen_not_null($method) || zen_not_null($method) && (string)$method == (string)$detailed->GlobalProductCode) ){
             
              $methods[] = array('id' => (string)$detailed->GlobalProductCode,
                           'title' => $title,
                           'cost' => ((string)$detailed->ShippingCharge) + (MODULE_SHIPPING_DHL_HANDLING_METHOD == 'Box' ? MODULE_SHIPPING_DHL_HANDLING * $shipping_num_boxes : MODULE_SHIPPING_DHL_HANDLING) );
          }
              }

Cheers
RodG

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.