Page 1 of 2

Updating old Card Accept box module

Posted: Sun May 22, 2022 2:31 pm
by Pierre_P
I'm a bit stuck on updating this old code to work on 1.0.8.14

I was unable to find the original code for this, i have it working on 1.0.5.0
Basically a box in catalog that shows an image of what payments are accepted.
Getting error in admin: Parse error: syntax error, unexpected '''' (T_CONSTANT_ENCAPSED_STRING) in..

Any help please.

Code: Select all

  class bm_card_acceptance extends abstract_block_module {

    const CONFIG_KEY_BASE = 'MODULE_BOXES_CARD_ACCEPTANCE_';

 function execute() {
     global $PHP_SELF;

      if ( (substr(basename($PHP_SELF), 0, 8) != 'checkout') && tep_not_null(MODULE_BOXES_CARD_ACCEPTANCE_LOGOS) ) {
        $output = NULL;

        foreach ( explode(';', MODULE_BOXES_CARD_ACCEPTANCE_LOGOS) as $logo ) {
          $output .= tep_image('images/card_acceptance/' . basename($logo));
        }
        $tpl_data = [ 'group' => $this->group, 'file' => __FILE__ ];
        include 'includes/modules/block_template.php';
      }
 }
    protected function get_parameters() {
      return [
        'MODULE_BOXES_CARD_ACCEPTANCE_STATUS' => [
          'title' => 'Enable Acceptance Cards Module',
          'value' => 'True',
          'desc' => 'Do you want to add the module to your shop?',
          'set_func' => "Config::select_one(['True', 'False'], ",
        ],
        'MODULE_BOXES_CARD_ACCEPTANCE_LOGOS' => [
          'title' => 'Logos',
          'value' => 'bank_logo.gif',
          'desc' => 'Minimum number of best sellers to make the box display',
		  'use_function' => 'bm_card_acceptance_show_logos',
          'set_func' => 'bm_card_acceptance_edit_logos',
        ],
        'MODULE_BOXES_CARD_ACCEPTANCE_CONTENT_PLACEMENT' => [
          'title' => 'Content Placement',
          'value' => 'Right Column',
          'desc' => 'Should the module be loaded in the left or right column?',
          'set_func' => "Config::select_one(['Left Column', 'Right Column'], ",
        ],
        'MODULE_BOXES_CARD_ACCEPTANCE_SORT_ORDER' => [
          'title' => 'Sort Order',
          'value' => '0',
          'desc' => 'Sort order of display. Lowest is displayed first.',
        ],
      ];
   }
    function remove() {
      tep_db_query("delete from configuration where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }

    function keys() {
      return array('MODULE_BOXES_CARD_ACCEPTANCE_STATUS', 'MODULE_BOXES_CARD_ACCEPTANCE_LOGOS', 'MODULE_BOXES_CARD_ACCEPTANCE_CONTENT_PLACEMENT', 'MODULE_BOXES_CARD_ACCEPTANCE_SORT_ORDER');
    }

  function bm_card_acceptance_show_logos($text) {
    $output = '';

    if ( !empty($text) ) {
      $output = '<ul style="list-style-type: none; margin: 0; padding: 5px; margin-bottom: 10px;">';

      foreach (explode(';', $text) as $card) {
        $output .= '<li style="padding: 2px;">' . tep_image('images/card_acceptance/' . basename($card), basename($card)) . '</li>';
      }

      $output .= '</ul>';
    }

    return $output;
  }

  function bm_card_acceptance_edit_logos($values, $key) {
    $files_array = array();

    if ( $dir = @dir(DIR_FS_CATALOG . 'images/card_acceptance') ) {
      while ( $file = $dir->read() ) {
        if ( !is_dir(DIR_FS_CATALOG . 'images/card_acceptance/' . $file) ) {
          if ( in_array(substr($file, strrpos($file, '.')+1), array('gif', 'jpg', 'png')) ) {
            $files_array[] = $file;
          }
        }
      }

      sort($files_array);

      $dir->close();
    }

    $values_array = !empty($values) ? explode(';', $values) : array();

    $output = '<h3 class="h3">' . MODULE_BOXES_CARD_ACCEPTANCE_SHOWN_CARDS . '</h3>' .
              '<ul id="ca_logos" style="list-style-type: none; margin: 0; padding: 5px; margin-bottom: 10px;">';

    foreach ($values_array as $file) {
      $output .= '<li style="padding: 2px;">' . tep_image('images/card_acceptance/' . $file, $file) . tep_draw_hidden_field('bm_card_acceptance_logos[]', $file) . '</li>';
    }

    $output .= '</ul>';

    $output .= '<h3 class="h3">' . MODULE_BOXES_CARD_ACCEPTANCE_NEW_CARDS . '</h3><ul id="new_ca_logos" style="list-style-type: none; margin: 0; padding: 5px; margin-bottom: 10px;">';

    foreach ($files_array as $file) {
      if ( !in_array($file, $values_array) ) {
        $output .= '<li style="padding: 2px;">' . tep_image('images/card_acceptance/' . $file, $file) . tep_draw_hidden_field('bm_card_acceptance_logos[]', $file) . '</li>';
      }
    }

    $output .= '</ul>';

    $output .= tep_draw_hidden_field('configuration[' . $key . ']', '', 'id="ca_logo_cards"');

    $drag_here_li = '<li id="caLogoEmpty" style="background-color: #fcf8e3; border: 1px #faedd0 solid; color: #a67d57; padding: 5px;">' . addslashes(MODULE_BOXES_CARD_ACCEPTANCE_DRAG_HERE) . '</li>';

    $output .= <<<EOD
<script>
$(function() {
  var drag_here_li = '{$drag_here_li}';

  if ( $('#ca_logos li').size() < 1 ) {
    $('#ca_logos').append(drag_here_li);
  }

  $('#ca_logos').sortable({
    connectWith: '#new_ca_logos',
    items: 'li:not("#caLogoEmpty")',
    stop: function (event, ui) {
      if ( $('#ca_logos li').size() < 1 ) {
        $('#ca_logos').append(drag_here_li);
      } else if ( $('#caLogoEmpty').length > 0 ) {
        $('#caLogoEmpty').remove();
      }
    }
  });

  $('#new_ca_logos').sortable({
    connectWith: '#ca_logos',
    stop: function (event, ui) {
      if ( $('#ca_logos li').size() < 1 ) {
        $('#ca_logos').append(drag_here_li);
      } else if ( $('#caLogoEmpty').length > 0 ) {
        $('#caLogoEmpty').remove();
      }
    }
  });

  $('#ca_logos, #new_ca_logos').disableSelection();

  $('form[name="modules"]').submit(function(event) {
    var ca_selected_cards = '';

    if ( $('#ca_logos li').size() > 0 ) {
      $('#ca_logos li input[name="bm_card_acceptance_logos[]"]').each(function() {
        ca_selected_cards += $(this).attr('value') + ';';
      });
    }

    if (ca_selected_cards.length > 0) {
      ca_selected_cards = ca_selected_cards.substring(0, ca_selected_cards.length - 1);
    }

    $('#ca_logo_cards').val(ca_selected_cards);
  });
});
</script>
EOD;

    return $output;
   } 
  }	        
?>
Template file = echo $output

Re: Updating old Card Accept box module

Posted: Sun May 22, 2022 3:28 pm
by raiwa
Posting the complete error message including line number would be very helpful.

Re: Updating old Card Accept box module

Posted: Sun May 22, 2022 3:38 pm
by heatherbell
Pierre_P wrote: Sun May 22, 2022 2:31 pm Any help please.
I am not a coder but first I always try to compare code with what is currently used in core, a simple game of "spot the difference". Comparing the code with https://github.com/CE-PhoenixCart/Phoen ... ellers.php, on which your code appears to be based, shows that neither function remove() nor function keys() are now used.
Perhaps try removing them? Just a guess.

Re: Updating old Card Accept box module

Posted: Sun May 22, 2022 4:50 pm
by Pierre_P
Yes, i was comparing structures to newer files @heatherbell

Removed lines as suggested - no change

the complete message :
Parse error: syntax error, unexpected '''' (T_CONSTANT_ENCAPSED_STRING) in /usr/www/users/alarmspggy/phoenix8/admin/includes/actions/modules/infoboxes/edit.php(18) : eval()'d code on line 1

bank_logo.gif is what is giving unexpected '''' if i manually edit the database and insert bank_logo.gif it will show - Parse error: syntax error, unexpected"bank_logo.gif''.... for example

/infoboxes/edit.php(18) refers to:
if ($value['set_function']) {
eval('$keys .= ' . $value['set_function'] . "'" . addslashes($value['value']) . "', '" . $key . "');");
} else {
$keys .= new Input('configuration[' . $key . ']', ['value' => $value['value']]);
}

The older working code:

Code: Select all

<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2018 osCommerce

  Released under the GNU General Public License
*/

  class bm_card_acceptance {
    var $code = 'bm_card_acceptance';
    var $group = 'boxes';
    var $title;
    var $description;
    var $sort_order;
    var $enabled = false;

    function __construct() {
      $this->title = MODULE_BOXES_CARD_ACCEPTANCE_TITLE;
      $this->description = MODULE_BOXES_CARD_ACCEPTANCE_DESCRIPTION;

      if ( defined('MODULE_BOXES_CARD_ACCEPTANCE_STATUS') ) {
        $this->sort_order = MODULE_BOXES_CARD_ACCEPTANCE_SORT_ORDER;
        $this->enabled = (MODULE_BOXES_CARD_ACCEPTANCE_STATUS == 'True');

        $this->group = ((MODULE_BOXES_CARD_ACCEPTANCE_CONTENT_PLACEMENT == 'Left Column') ? 'boxes_column_left' : 'boxes_column_right');
      }
    }

    function execute() {
      global $PHP_SELF, $oscTemplate;

      if ( (substr(basename($PHP_SELF), 0, 8) != 'checkout') && tep_not_null(MODULE_BOXES_CARD_ACCEPTANCE_LOGOS) ) {
        $output = NULL;

        foreach ( explode(';', MODULE_BOXES_CARD_ACCEPTANCE_LOGOS) as $logo ) {
          $output .= tep_image('images/card_acceptance/' . basename($logo));
        }
                   
        ob_start();
        include('includes/modules/boxes/templates/tpl_' . basename(__FILE__));
        $data = ob_get_clean();

        $oscTemplate->addBlock($data, $this->group);
      }
    }

    function isEnabled() {
      return $this->enabled;
    }

    function check() {
      return defined('MODULE_BOXES_CARD_ACCEPTANCE_STATUS');
    }

    function install() {
      tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Card Acceptance Module', 'MODULE_BOXES_CARD_ACCEPTANCE_STATUS', 'True', 'Do you want to add the module to your shop?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
      tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Logos', 'MODULE_BOXES_CARD_ACCEPTANCE_LOGOS', 'bank_logo.gif', 'The card acceptance logos to show. Usage: Drag and drop logo image between Shown Cards and New Cards to activate or remove.', '6', '0', 'bm_card_acceptance_show_logos', 'bm_card_acceptance_edit_logos(', now())");
      tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Content Placement', 'MODULE_BOXES_CARD_ACCEPTANCE_CONTENT_PLACEMENT', 'Right Column', 'Should the module be loaded in the left or right column?', '6', '1', 'tep_cfg_select_option(array(\'Left Column\', \'Right Column\'), ', now())");
      tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_BOXES_CARD_ACCEPTANCE_SORT_ORDER', '50', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
    }

    function remove() {
      tep_db_query("delete from configuration where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }

    function keys() {
      return array('MODULE_BOXES_CARD_ACCEPTANCE_STATUS', 'MODULE_BOXES_CARD_ACCEPTANCE_LOGOS', 'MODULE_BOXES_CARD_ACCEPTANCE_CONTENT_PLACEMENT', 'MODULE_BOXES_CARD_ACCEPTANCE_SORT_ORDER');
    }
  }

  function bm_card_acceptance_show_logos($text) {
    $output = '';

    if ( !empty($text) ) {
      $output = '<ul style="list-style-type: none; margin: 0; padding: 5px; margin-bottom: 10px;">';

      foreach (explode(';', $text) as $card) {
        $output .= '<li style="padding: 2px;">' . tep_image(DIR_WS_CATALOG_IMAGES . 'card_acceptance/' . basename($card), basename($card)) . '</li>';
      }

      $output .= '</ul>';
    }

    return $output;
  }

  function bm_card_acceptance_edit_logos($values, $key) {
    $files_array = array();

    if ( $dir = @dir(DIR_FS_CATALOG . 'images/card_acceptance') ) {
      while ( $file = $dir->read() ) {
        if ( !is_dir(DIR_FS_CATALOG . 'images/card_acceptance/' . $file) ) {
          if ( in_array(substr($file, strrpos($file, '.')+1), array('gif', 'jpg', 'png')) ) {
            $files_array[] = $file;
          }
        }
      }

      sort($files_array);

      $dir->close();
    }

    $values_array = !empty($values) ? explode(';', $values) : array();

    $output = '<h3 class="h3">' . MODULE_BOXES_CARD_ACCEPTANCE_SHOWN_CARDS . '</h3>' .
              '<ul id="ca_logos" style="list-style-type: none; margin: 0; padding: 5px; margin-bottom: 10px;">';

    foreach ($values_array as $file) {
      $output .= '<li style="padding: 2px;">' . tep_image(DIR_WS_CATALOG_IMAGES . 'card_acceptance/' . $file, $file) . tep_draw_hidden_field('bm_card_acceptance_logos[]', $file) . '</li>';
    }

    $output .= '</ul>';

    $output .= '<h3 class="h3">' . MODULE_BOXES_CARD_ACCEPTANCE_NEW_CARDS . '</h3><ul id="new_ca_logos" style="list-style-type: none; margin: 0; padding: 5px; margin-bottom: 10px;">';

    foreach ($files_array as $file) {
      if ( !in_array($file, $values_array) ) {
        $output .= '<li style="padding: 2px;">' . tep_image(DIR_WS_CATALOG_IMAGES . 'card_acceptance/' . $file, $file) . tep_draw_hidden_field('bm_card_acceptance_logos[]', $file) . '</li>';
      }
    }

    $output .= '</ul>';

    $output .= tep_draw_hidden_field('configuration[' . $key . ']', '', 'id="ca_logo_cards"');

    $drag_here_li = '<li id="caLogoEmpty" style="background-color: #fcf8e3; border: 1px #faedd0 solid; color: #a67d57; padding: 5px;">' . addslashes(MODULE_BOXES_CARD_ACCEPTANCE_DRAG_HERE) . '</li>';

    $output .= <<<EOD
<script>
$(function() {
  var drag_here_li = '{$drag_here_li}';

  if ( $('#ca_logos li').size() < 1 ) {
    $('#ca_logos').append(drag_here_li);
  }

  $('#ca_logos').sortable({
    connectWith: '#new_ca_logos',
    items: 'li:not("#caLogoEmpty")',
    stop: function (event, ui) {
      if ( $('#ca_logos li').size() < 1 ) {
        $('#ca_logos').append(drag_here_li);
      } else if ( $('#caLogoEmpty').length > 0 ) {
        $('#caLogoEmpty').remove();
      }
    }
  });

  $('#new_ca_logos').sortable({
    connectWith: '#ca_logos',
    stop: function (event, ui) {
      if ( $('#ca_logos li').size() < 1 ) {
        $('#ca_logos').append(drag_here_li);
      } else if ( $('#caLogoEmpty').length > 0 ) {
        $('#caLogoEmpty').remove();
      }
    }
  });

  $('#ca_logos, #new_ca_logos').disableSelection();

  $('form[name="modules"]').submit(function(event) {
    var ca_selected_cards = '';

    if ( $('#ca_logos li').size() > 0 ) {
      $('#ca_logos li input[name="bm_card_acceptance_logos[]"]').each(function() {
        ca_selected_cards += $(this).attr('value') + ';';
      });
    }

    if (ca_selected_cards.length > 0) {
      ca_selected_cards = ca_selected_cards.substring(0, ca_selected_cards.length - 1);
    }

    $('#ca_logo_cards').val(ca_selected_cards);
  });
});
</script>
EOD;

    return $output;
  }
?>

Re: Updating old Card Accept box module

Posted: Sun May 22, 2022 6:25 pm
by raiwa
To use custom functions in the configurations, you should call them like this:

Code: Select all

          'use_function' => 'bm_card_acceptance::show_logos',
          'set_func' => 'bm_card_acceptance::edit_logos(',
I shortened the function names and the functions should be made static:

Code: Select all

    
    public static function show_logos($text) {

.............................
    
    
    public static function edit_logos($values, $key) {
And note that you were missing the parentheses at the end of "set function".

There are still deprecated functions in the code which may work in Phoenix 1.0.8.14, but should be updated to native methods to ensure future compatibility.
Examples: tep_image, tep_draw_hidden_field
Have a look in my Phoenix Change Log Cheat Set on Google Sheets see the link in my footer.

Re: Updating old Card Accept box module

Posted: Mon May 23, 2022 5:52 am
by Pierre_P
Hello @raiwa

Thanks, almost there :)
this line is giving me problems:
$output .= tep_draw_hidden_field('configuration[' . $key . ']', '', 'id="ca_logo_cards"');

I tried it
$output .= new Input('configuration[' . $key . ']', '', 'hidden' . ' id="ca_logo_cards"');

Fatal error: Uncaught TypeError: Argument 2 passed to Input::__construct() must be of the type array, string given, called in /usr/www/users/---/phoenix8/includes/modules/boxes/bm_card_acceptance.php on line 117 and defined in /usr/www/users/---/phoenix8/includes/system/versioned/1.0.8.1/input.php:22 Stack trace: #0 /usr/www/users/---/phoenix8/includes/modules/boxes/bm_card_acceptance.php(117): Input->__construct('configuration[M...', '', 'hidden id="ca_l...') #1 /usr/www/users/---/phoenix8/admin/includes/actions/modules/infoboxes/edit.php(18) : eval()'d code(1): bm_card_acceptance::edit_logos('bank_logo.gif', 'MODULE_BOXES_CA...') #2 /usr/www/users/---/phoenix8/admin/includes/actions/modules/infoboxes/edit.php(18..

Code: Select all

<?php
/*
  $Id$

  CE Phoenix, E-Commerce made Easy
  https://phoenixcart.org

  Copyright (c) 2022 Phoenix Cart

  Released under the GNU General Public License
*/

  class bm_card_acceptance extends abstract_block_module {

    const CONFIG_KEY_BASE = 'MODULE_BOXES_CARD_ACCEPTANCE_';

 function execute() {
     global $PHP_SELF;
// if ( (substr(basename($PHP_SELF), 0, 8) != 'checkout') && tep_not_null(MODULE_BOXES_CARD_ACCEPTANCE_LOGOS) ) {
// if (substr(basename(Request::get_page()), 0, 8) !== 'checkout')
      if ( (substr(basename(Request::get_page()), 0, 8) !== 'checkout') && !empty(MODULE_BOXES_CARD_ACCEPTANCE_LOGOS) ) {
        $output = NULL;

        foreach ( explode(';', MODULE_BOXES_CARD_ACCEPTANCE_LOGOS) as $logo ) {
          $output .= new Image(DIR_WS_CATALOG_IMAGES . 'card_acceptance/' . basename($logo));
        }
        $tpl_data = [ 'group' => $this->group, 'file' => __FILE__ ];
        include 'includes/modules/block_template.php';
      }
 }
    protected function get_parameters() {
      return [
        'MODULE_BOXES_CARD_ACCEPTANCE_STATUS' => [
          'title' => 'Enable Acceptance Cards Module',
          'value' => 'True',
          'desc' => 'Do you want to add the module to your shop?',
          'set_func' => "Config::select_one(['True', 'False'], ",
        ],
        'MODULE_BOXES_CARD_ACCEPTANCE_LOGOS' => [
          'title' => 'Logos',
          'value' => 'bank_logo.gif',
          'desc' => 'Minimum number of best sellers to make the box display',
		  'use_function' => 'bm_card_acceptance::show_logos',
          'set_func' => 'bm_card_acceptance::edit_logos(',
        ],
        'MODULE_BOXES_CARD_ACCEPTANCE_CONTENT_PLACEMENT' => [
          'title' => 'Content Placement',
          'value' => 'Right Column',
          'desc' => 'Should the module be loaded in the left or right column?',
          'set_func' => "Config::select_one(['Left Column', 'Right Column'], ",
        ],
        'MODULE_BOXES_CARD_ACCEPTANCE_SORT_ORDER' => [
          'title' => 'Sort Order',
          'value' => '0',
          'desc' => 'Sort order of display. Lowest is displayed first.',
        ],
      ];
   }


 public static function show_logos($text) {
    $output = '';

    if ( !empty($text) ) {
      $output = '<ul style="list-style-type: none; margin: 0; padding: 5px; margin-bottom: 10px;">';

      foreach (explode(';', $text) as $card) {
        $output .= '<li style="padding: 2px;">' . new Image(DIR_WS_CATALOG_IMAGES . 'card_acceptance/' . basename($card), basename($card)) . '</li>';
      }

      $output .= '</ul>';
    }

    return $output;
  }

  public static function edit_logos($values, $key) {
    $files_array = array();

    if ( $dir = @dir(DIR_FS_CATALOG . new Image(DIR_WS_CATALOG_IMAGES . 'card_acceptance') ) ) {
      while ( $file = $dir->read() ) {
        if ( !is_dir(DIR_FS_CATALOG .new Image(DIR_WS_CATALOG_IMAGES . 'card_acceptance/' . $file)) ) {
          if ( in_array(substr($file, strrpos($file, '.')+1), array('gif', 'jpg', 'png')) ) {
            $files_array[] = $file;
          }
        }
      }

      sort($files_array);

      $dir->close();
    }

    $values_array = !empty($values) ? explode(';', $values) : array();

    $output = '<h3 class="h3">' . MODULE_BOXES_CARD_ACCEPTANCE_SHOWN_CARDS . '</h3>' .
              '<ul id="ca_logos" style="list-style-type: none; margin: 0; padding: 5px; margin-bottom: 10px;">';

    foreach ($values_array as $file) {
		      $output .= '<li style="padding: 2px;">' . new Image(DIR_WS_CATALOG_IMAGES . 'card_acceptance/' . $file) . tep_draw_hidden_field('bm_card_acceptance_logos[]', $file, $file) . '</li>';
  //    $output .= '<li style="padding: 2px;">' . new Image('images/card_acceptance/' . $file) . new Input('bm_card_acceptance_logos', ['value' => $file] , 'hidden') . '</li>';
    }

    $output .= '</ul>';

    $output .= '<h3 class="h3">' . MODULE_BOXES_CARD_ACCEPTANCE_NEW_CARDS . '</h3><ul id="new_ca_logos" style="list-style-type: none; margin: 0; padding: 5px; margin-bottom: 10px;">';

    foreach ($files_array as $file) {
      if ( !in_array($file, $values_array) ) {
        $output .= '<li style="padding: 2px;">' . new Image(DIR_WS_CATALOG_IMAGES . 'card_acceptance/' . $file, $file) .
		 new Input('bm_card_acceptance_logos[]', $file) . '</li>';
      }
    }

    $output .= '</ul>';

    $output .= new Input('configuration[' . $key . ']', '', 'hidden' . ' id="ca_logo_cards"');

    $drag_here_li = '<li id="caLogoEmpty" style="background-color: #fcf8e3; border: 1px #faedd0 solid; color: #a67d57; padding: 5px;">' . addslashes(MODULE_BOXES_CARD_ACCEPTANCE_DRAG_HERE) . '</li>';

    $output .= <<<EOD
<script>
$(function() {
  var drag_here_li = '{$drag_here_li}';

  if ( $('#ca_logos li').size() < 1 ) {
    $('#ca_logos').append(drag_here_li);
  }

  $('#ca_logos').sortable({
    connectWith: '#new_ca_logos',
    items: 'li:not("#caLogoEmpty")',
    stop: function (event, ui) {
      if ( $('#ca_logos li').size() < 1 ) {
        $('#ca_logos').append(drag_here_li);
      } else if ( $('#caLogoEmpty').length > 0 ) {
        $('#caLogoEmpty').remove();
      }
    }
  });

  $('#new_ca_logos').sortable({
    connectWith: '#ca_logos',
    stop: function (event, ui) {
      if ( $('#ca_logos li').size() < 1 ) {
        $('#ca_logos').append(drag_here_li);
      } else if ( $('#caLogoEmpty').length > 0 ) {
        $('#caLogoEmpty').remove();
      }
    }
  });

  $('#ca_logos, #new_ca_logos').disableSelection();

  $('form[name="modules"]').submit(function(event) {
    var ca_selected_cards = '';

    if ( $('#ca_logos li').size() > 0 ) {
      $('#ca_logos li input[name="bm_card_acceptance_logos[]"]').each(function() {
        ca_selected_cards += $(this).attr('value') + ';';
      });
    }

    if (ca_selected_cards.length > 0) {
      ca_selected_cards = ca_selected_cards.substring(0, ca_selected_cards.length - 1);
    }

    $('#ca_logo_cards').val(ca_selected_cards);
  });
});
</script>
EOD;

    return $output;
   } 
  }	        
?>

Re: Updating old Card Accept box module

Posted: Mon May 23, 2022 6:09 am
by ecartz

Code: Select all

$output .= new Input('configuration[' . $key . ']', ['id' => 'ca_logo_cards'], 'hidden');

Re: Updating old Card Accept box module

Posted: Mon May 23, 2022 6:51 am
by raiwa
DIR_WS_CATALOG_IMAGES has been removed.
You must hardcode the image directory:
DIR_WS_CATALOG . 'images/card_acceptance......

Re: Updating old Card Accept box module

Posted: Mon May 23, 2022 9:41 am
by Pierre_P
One step at a time
The jquery small fix(if im correct)

Line 97 and 107 have got tep_draw_hidden_field
If i update to newer new Input('bm_card_acceptance_logos', ['value'= $file], 'hidden') then admin dragging images around does not save filename so i left as is - i could have this wrong also!

Working for now.

Thank you everyone for help!

Code: Select all

<?php
/*
  $Id$

  CE Phoenix, E-Commerce made Easy
  https://phoenixcart.org

  Copyright (c) 2022 Phoenix Cart

  Released under the GNU General Public License
*/

  class bm_card_acceptance extends abstract_block_module {

    const CONFIG_KEY_BASE = 'MODULE_BOXES_CARD_ACCEPTANCE_';

 function execute() {
     global $PHP_SELF;
      if ( (substr(basename(Request::get_page()), 0, 8) !== 'checkout') && !empty(MODULE_BOXES_CARD_ACCEPTANCE_LOGOS) ) {
        $output = NULL;

        foreach ( explode(';', MODULE_BOXES_CARD_ACCEPTANCE_LOGOS) as $logo ) {
          $output .= new Image(DIR_WS_CATALOG . 'images/card_acceptance/' . basename($logo));
        }
        $tpl_data = [ 'group' => $this->group, 'file' => __FILE__ ];
        include 'includes/modules/block_template.php';
      }
 }
    protected function get_parameters() {
      return [
        'MODULE_BOXES_CARD_ACCEPTANCE_STATUS' => [
          'title' => 'Enable Acceptance Cards Module',
          'value' => 'True',
          'desc' => 'Do you want to add the module to your shop?',
          'set_func' => "Config::select_one(['True', 'False'], ",
        ],
        'MODULE_BOXES_CARD_ACCEPTANCE_LOGOS' => [
          'title' => 'Logos',
          'value' => 'bank_logo.gif',
          'desc' => 'The card acceptance logos to show. Usage: Drag and drop logo image between Shown Cards and New Cards to activate or remove',
		  'use_function' => 'bm_card_acceptance::show_logos',
          'set_func' => 'bm_card_acceptance::edit_logos(',
        ],
        'MODULE_BOXES_CARD_ACCEPTANCE_CONTENT_PLACEMENT' => [
          'title' => 'Content Placement',
          'value' => 'Right Column',
          'desc' => 'Should the module be loaded in the left or right column?',
          'set_func' => "Config::select_one(['Left Column', 'Right Column'], ",
        ],
        'MODULE_BOXES_CARD_ACCEPTANCE_SORT_ORDER' => [
          'title' => 'Sort Order',
          'value' => '90',
          'desc' => 'Sort order of display. Lowest is displayed first.',
        ],
      ];
   }


 public static function show_logos($text) {
    $output = '';

    if ( !empty($text) ) {
      $output = '<ul style="list-style-type: none; margin: 0; padding: 5px; margin-bottom: 10px;">';

      foreach (explode(';', $text) as $card) {
        $output .= '<li style="padding: 2px;">' . new Image(DIR_WS_CATALOG . 'images/card_acceptance/' . basename($card), basename($card)) . '</li>';
      }

      $output .= '</ul>';
    }

    return $output;
  }

  public static function edit_logos($values, $key) {
    $files_array = array();

    if ( $dir = @dir(DIR_FS_CATALOG . 'images/card_acceptance')) {
      while ( $file = $dir->read() ) {
        if ( !is_dir(DIR_FS_CATALOG . 'images/card_acceptance/' . $file)) {
          if ( in_array(substr($file, strrpos($file, '.')+1), array('gif', 'jpg', 'png')) ) {
            $files_array[] = $file;
          }
        }
      }

      sort($files_array);

      $dir->close();
    }

    $values_array = !empty($values) ? explode(';', $values) : array();

    $output = '<h3 class="h3">' . MODULE_BOXES_CARD_ACCEPTANCE_SHOWN_CARDS . '</h3>' .
              '<ul id="ca_logos" style="list-style-type: none; margin: 0; padding: 5px; margin-bottom: 10px;">';

    foreach ($values_array as $file) {
      $output .= '<li style="padding: 2px;">' . tep_image(DIR_WS_CATALOG . 'images/card_acceptance/' . $file, $file) . tep_draw_hidden_field('bm_card_acceptance_logos[]', $file) . '</li>';
    }

    $output .= '</ul>';

    $output .= '<h3 class="h3">' . MODULE_BOXES_CARD_ACCEPTANCE_NEW_CARDS . '</h3><ul id="new_ca_logos" style="list-style-type: none; margin: 0; padding: 5px; margin-bottom: 10px;">';

    foreach ($files_array as $file) {
      if ( !in_array($file, $values_array) ) {
        $output .= '<li style="padding: 2px;">' . tep_image(DIR_WS_CATALOG . 'images/card_acceptance/' . $file, $file) . tep_draw_hidden_field('bm_card_acceptance_logos[]', $file) . '</li>';
      }
    }

    $output .= '</ul>';

    $output .= new Input('configuration[' . $key . ']', ['id' => 'ca_logo_cards'], 'hidden');

    $drag_here_li = '<li id="caLogoEmpty" style="background-color: #fcf8e3; border: 1px #faedd0 solid; color: #a67d57; padding: 5px;">' . addslashes(MODULE_BOXES_CARD_ACCEPTANCE_DRAG_HERE) . '</li>';

    $output .= <<<EOD
<script>
$(function() {
  var drag_here_li = '{$drag_here_li}';

  if ( $('#ca_logos li').length < 1 ) {
    $('#ca_logos').append(drag_here_li);
  }

  $('#ca_logos').sortable({
    connectWith: '#new_ca_logos',
    items: 'li:not("#caLogoEmpty")',
    stop: function (event, ui) {
      if ( $('#ca_logos li').length < 1 ) {
        $('#ca_logos').append(drag_here_li);
      } else if ( $('#caLogoEmpty').length > 0 ) {
        $('#caLogoEmpty').remove();
      }
    }
  });

  $('#new_ca_logos').sortable({
    connectWith: '#ca_logos',
    stop: function (event, ui) {
      if ( $('#ca_logos li').length < 1 ) {
        $('#ca_logos').append(drag_here_li);
      } else if ( $('#caLogoEmpty').length > 0 ) {
        $('#caLogoEmpty').remove();
      }
    }
  });

  $('#ca_logos, #new_ca_logos').disableSelection();

  $('form[name="modules"]').submit(function(event) {
    var ca_selected_cards = '';

    if ( $('#ca_logos li').length > 0 ) {
      $('#ca_logos li input[name="bm_card_acceptance_logos[]"]').each(function() {
        ca_selected_cards += $(this).attr('value') + ';';
      });
    }

    if (ca_selected_cards.length > 0) {
      ca_selected_cards = ca_selected_cards.substring(0, ca_selected_cards.length - 1);
    }

    $('#ca_logo_cards').val(ca_selected_cards);
  });
});
</script>
EOD;

    return $output;
   } 
  }	        
?>

Re: Updating old Card Accept box module

Posted: Tue May 24, 2022 3:58 pm
by 14Steve14
This may sound silly but do you actually need a card acceptance box module when there is already one in the footer_suffix area of the site.

It may be eassier to modify or copy that module and just update what is already there.