Need help with hook for shipping module

Open to all! Ask other shopowners for help.
Post Reply
lecarlb
Contributor
Posts: 316
Joined: Mon Oct 26, 2020 5:26 pm
Phoenix Version:
Has thanked: 48 times
Been thanked: 9 times

Need help with hook for shipping module

Post by lecarlb »

Hello,

I have a shipping module that was coded to have a tab in the product edit area where a different shipping price can be set for each product. The issue is the tab isn't showing and I believe the issue is in the hook file. There are no errors in the error logs. Below is the code of the hook file. I appreciate any help. Thanks

Code: Select all

<?php
/*
  

  This work is licensed under a 
  Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.

  You should have received a copy of the license along with this work.
  If not, see <http://creativecommons.org/licenses/by-nc-nd/4.0/>.
*/

class hook_admin_categories_shipping {
  var $version = '1.0.0';
    
  function listen_productTab() {
    global $pInfo;
    
    $this->load_lang();
    
    $tab_title = addslashes(SHIPPING_TITLE);
    $tab_link  = '#section_shipping';
    
    $add_edit_intro = SHIPPING_INTRO;
    
    $handling_title = HANDLING_TITLE;
    $extra_title    = EXTRA_TITLE;

    $handling_input = tep_draw_input_field('products_handling_shipping', $pInfo->products_handling_shipping ?? null, 'autocomplete="off" class="form-control w-25"');
    $extra_input = tep_draw_input_field('products_extra_shipping', $pInfo->products_extra_shipping ?? null, 'autocomplete="off" class="form-control w-25"');
    
    $output = <<<EOD
<script>
$(function() {
  $('#productTabs ul.nav.nav-tabs').append('<li class="nav-item"><a class="nav-link" data-toggle="tab" href="{$tab_link}" role="tab">{$tab_title}</a></li>');
});
</script>

<div class="tab-pane fade" id="section_shipping" role="tabpanel">
  <div class="alert alert-info">
    {$add_edit_intro}
  </div>
  <table class="table table-sm">
    <tr>
      <th class="text-right">{$handling_title}&nbsp;</th>
      <td>{$handling_input}</td>
    </tr>
    <tr>
      <th class="text-right">{$extra_title}&nbsp;</th>
      <td>{$extra_input}</td>
    </tr>
  </table>
</div>
EOD;

      return $output;
    }
    
    function listen_productActionSave() {
      global $products_id;
      
      $insert_sql_data = ['products_handling_shipping' => tep_db_prepare_input($_POST['products_handling_shipping']), 
                          'products_extra_shipping'    => tep_db_prepare_input($_POST['products_extra_shipping'])];

      tep_db_perform('products', $insert_sql_data, 'update', "products_id = '" . (int)$products_id . "'");
    } 

    function load_lang() {
      global $language;

      require(DIR_FS_CATALOG . 'includes/languages/' . $language . '/hooks/admin/categories/shipping.php');
    }  
    
  }

Tags:


Join The Code Co-op to get access to your library in the Code Co-op Forum
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: Need help with hook for shipping module

Post by ecartz »

You don't mention Phoenix version. If the latest, you might check supporters' code for examples:

S02e06
S02e08
S02e10
S04e10
S05e04
S05e07
S10e02
S10e06

Hint: hook_admin_catalog_shipping and

Code: Select all

  public function listen_updateProductAction() {
    $this->listen_productActionSave();
  }

  public function listen_insertProductAction() {
    $this->listen_productActionSave();
  }
lecarlb
Contributor
Posts: 316
Joined: Mon Oct 26, 2020 5:26 pm
Phoenix Version:
Has thanked: 48 times
Been thanked: 9 times

Re: Need help with hook for shipping module

Post by lecarlb »

@ecartz The latest version I have this shipping module working in is 1.0.8.4. I'm currently trying to get it to work in 1.0.8.16.


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply