Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2010
    Posts
    16
    Plugin Contributions
    0

    help question Problem with new shipping module ported from osc

    Hello,

    I have a problem with new shipping module which initially was written for oscommece but I modified it for zencart in accordance with this article: http://www.zen-cart.com/wiki/index.p...dules_from_osC

    Module was properly installed and properly works in admin panel but when I add any product to the cart from client side and I try to cross to the "checkout shipping" stage I see a blank page.

    I checked logs and there are following errors:

    Code:
    Call to undefined function zen_db_fetch_array()   on line 35
    and

    Code:
    Cannot use object of type queryFactoryResult  on line 39
    I tried various solutions but I still receive a blank page and errors in logs. Could you help me in find proper solution for this problem, please?


    Piece of module which generates errors:

    Code:
      function pobierz_klienta() {
    
        global $customer_id, $sendto, $db;
    
        $account_query = $db->Execute("select
        customers_email_address from 
        " . TABLE_CUSTOMERS . " where customers_id = '" . (int)$customer_id . "'");
        $account = zen_db_fetch_array($account_query);
    	  $klient['email']=$account['customers_email_address'];
    	
        $account_query = $db->Execute("select
        entry_postcode from 
        " . TABLE_ADDRESS_BOOK . " where address_book_id = '" . (int)$sendto . "'");
        $account = zen_db_fetch_array($account_query);
        $klient['kod']=$account['entry_postcode'];
        
        return $klient;
       
      }

  2. #2
    Join Date
    Jan 2004
    Posts
    66,444
    Plugin Contributions
    279

    Default Re: Problem with new shipping module ported from osc

    There's no such thing as "zen_db_fetch_array" function. There are several examples, in the link you mentioned, of the correct approach for porting those lines over.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Sep 2010
    Posts
    16
    Plugin Contributions
    0

    Default Re: Problem with new shipping module ported from osc

    I think that I modified this script accordingly with the solution but unfortunately it still doesn't work in 100% properly (script doesn't send postcode to the external server etc.). Could someone tell me what I done wrong?


    <?php

    Code:
    class paczkomaty {
    
      var $code, $title, $description, $enabled, $num_zones;
    
      function paczkomaty() {
    
      	global $order, $total_weight;
    
        $this->code = 'paczkomaty';
        $this->title = MODULE_SHIPPING_PACZKOMATY_TEXT_TITLE;
        $this->description = MODULE_SHIPPING_PACZKOMATY_TEXT_DESCRIPTION;
        $this->sort_order = MODULE_SHIPPING_PACZKOMATY_SORT_ORDER;
        $this->icon = 'http://media.paczkomaty.pl/pieczatka.gif'; 
        $this->tax_class = MODULE_SHIPPING_PACZKOMATY_TAX_CLASS;
        $this->enabled = ((MODULE_SHIPPING_PACZKOMATY_STATUS == 'True') ? true : false);
        $this->num_zones = 1;
    								 	
      }
    
      function pobierz_klienta() {
    
        global $customer_id, $sendto, $db;
    
        $account_query = $db->Execute("select
        customers_email_address from 
        " . TABLE_CUSTOMERS . " where customers_id = '" . (int)$customer_id . "'");
        $klient['email']=$account_query->fields['customers_email_address'];
    	
        $account_query = $db->Execute("select
        entry_postcode from 
        " . TABLE_ADDRESS_BOOK . " where address_book_id = '" . (int)$sendto . "'");
        $klient['kod']=$account_query->fields['entry_postcode'];
        
        return $klient;
       
      }
        
        
      function pobierz_paczkomaty($postcode) {
    
        $inpost_api_url = constant('MODULE_SHIPPING_PACZKOMATY_API_URL');
      
        if ($machinesContents = @file_get_contents("$inpost_api_url/?do=findnearestmachines_csv&postcode=$postcode")) {
          if ($machinesContents=='Error') return 0;            
          $machinesArray = split("\n",$machinesContents);
          if (count($machinesArray)) {      
            foreach ($machinesArray as $machine) {
              $machine = split(";",$machine);
              $data[] = $machine;
            }            
            return $data;   
          } 
        }
        
        return 0;
      
      }
    
      function znajdz_klienta($email) {
        
        $inpost_api_url = constant('MODULE_SHIPPING_PACZKOMATY_API_URL');
      
        if ($machinesContents = @file_get_contents("$inpost_api_url/?do=findcustomer_csv&email=$email")) {
          if ($machinesContents=='Error') return 0;      
          $machine = split(";", $machinesContents);
          return $machine;
        }
      
        return 0;
      
      }
           
      function quote($method = '') {
      
    	  global $order, $total_weight, $shipping_weight, $shipping_num_boxes, $customer_id, $sendto;
    
        $klient =$this->pobierz_klienta();
    
        $dest_country = $order->delivery['country']['iso_code_2'];
        $dest_zone = 0;
        $error = false;
    	  	
        if ($order->delivery['country']['iso_code_2'] == 'PL')  {  // tylko na terenie Polski
    	  	
          for ($i=1; $i<=$this->num_zones; $i++) {
            $countries_table = constant('MODULE_SHIPPING_PACZKOMATY_COUNTRIES_' . $i);
            $country_zones = split("[,]", $countries_table);
            if (in_array($dest_country, $country_zones)) {
              $dest_zone = $i;
              break;
            }
          }
     		
          if ($dest_zone == 0) {
            $this->quotes['error'] = MODULE_SHIPPING_ZONES_INVALID_ZONE;
            return $this->quotes;
          } 
          
          $shipping_method = MODULE_SHIPPING_PACZKOMATY_TEXT_WAY . ' : ' . $shipping_weight . ' ' . MODULE_SHIPPING_PACZKOMATY_TEXT_UNITS . ' ' . MODULE_SHIPPING_PACZKOMATY_DELIVERY_TIMES; 
          $shipping_cost = constant('MODULE_SHIPPING_PACZKOMATY_COST_' . $dest_zone)* $shipping_num_boxes;
            
        }
          
        if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title);
          
        if ($dest_zone == 0) {   // poza rejonem
          $this->quotes['error'] = MODULE_SHIPPING_ZONES_INVALID_ZONE;
          return $this->quotes;
        } 
            
       	if ($total_weight >12) { // nie pokazuj dla przesylek > 12kg
          $this->quotes['error'] = MODULE_SHIPPING_PACZKOMATY_UNDEFINED_RATE;
    	    return $this->quotes;
        }	      
    
        $this->quotes = array('id' => $this->code,
                              'module' => MODULE_SHIPPING_PACZKOMATY_TEXT_TITLE);        
                                                         
        $paczkomaty=$this->pobierz_paczkomaty($klient['kod']);
                
        if (!$paczkomaty) {  
    			$this->quotes['error'] = MODULE_SHIPPING_PACZKOMATY_TEXT_MACHINES_NOT_FOUND;
    			return $this->quotes;
        }	
                
        $paczkomat_domyslny=$this->znajdz_klienta($klient['email']);
          
        if (!$paczkomat_domyslny) {  	
    			$this->quotes['error'] = MODULE_SHIPPING_PACZKOMATY_TEXT_USER_NOT_FOUND;
    			return $this->quotes;
        }	
          
        $this->quotes['methods'][]=array('id' => $this->code,
                                         'title' => 'Paczkomat domyślny '.$paczkomat_domyslny[0].', '.$paczkomat_domyslny[1],
                                         'cost' => $shipping_cost);
        
        if (count($paczkomaty)) {  
          foreach ($paczkomaty as $paczkomat) {
            $this->quotes['methods'][]=array('id' => $this->code,
                                              'title' => 'Paczkomat '.$paczkomat[0].', '.$paczkomat[1].', ('.$paczkomat[3].'km od '.$klient['kod'].")",
                                              'cost' => $shipping_cost);
          }                        
        }                             
    
        if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title);
                                                         
        return $this->quotes;
          
    	}
    	
    
      function check() {
        global $db;  
        if (!isset($this->_check)) {
          $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_PACZKOMATY_STATUS'");
          $this->_check = $check_query->RecordCount();
        }
        
        return $this->_check;
        
      }
    
      function install() {
        global $db;
        $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Włącz wysyłkę do paczkomatów', 'MODULE_SHIPPING_PACZKOMATY_STATUS', 'True', 'Czy chcesz dodać opcję wysyłki do paczkomatów?', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
        $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Ściezka do api', 'MODULE_SHIPPING_PACZKOMATY_API_URL', 'https://api.paczkomaty.pl', 'Ścieżka do api paczkomaty', '6', '0', now())");	  
        $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sortowanie', 'MODULE_SHIPPING_PACZKOMATY_SORT_ORDER', '1', 'Sortowanie', '6', '0', now())");
        for ($i = 1; $i <= $this->num_zones; $i++) {
          $default_countries = '';
          if ($i == 1) {
            $default_countries = 'PL';
          }
          $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Dostępne kraje', 'MODULE_SHIPPING_PACZKOMATY_COUNTRIES_" . $i ."', '" . $default_countries . "', 'WprowadĽ oznaczenie kraju dla którego usługa jest dostępna (Default: PL)', '6', '0', now())");
          $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Cena przesyłki', 'MODULE_SHIPPING_PACZKOMATY_COST_" . $i ."', '6.99', 'Domyślny koszt wysyłki', '6', '0', now())");   
        }
        
      }
    
      function remove() {
        global $db;
        $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
        
      }
    
      function keys() {
      
        $keys = array('MODULE_SHIPPING_PACZKOMATY_STATUS', 'MODULE_SHIPPING_PACZKOMATY_API_URL', 'MODULE_SHIPPING_PACZKOMATY_SORT_ORDER');
        for ($i=1; $i<=$this->num_zones; $i++) {
          $keys[] = 'MODULE_SHIPPING_PACZKOMATY_COUNTRIES_' . $i;
          $keys[] = 'MODULE_SHIPPING_PACZKOMATY_COST_' . $i;
        }
        
        return $keys;
        
      }
    
    }
    
    ?>

  4. #4
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Problem with new shipping module ported from osc

    I believe the problem is in the $sendto variable ...

    As an Example, you have:
    Code:
        $account_query = $db->Execute("select
        entry_postcode from 
        " . TABLE_ADDRESS_BOOK . " where address_book_id = '" . (int)$sendto . "'");
        $klient['kod']=$account_query->fields['entry_postcode'];
    From what I can see, that variable doesn't equal anything, unless you happen to go to the Shipping Estimator and then it will be set to what the customer is looking at on the shipping estimator but not necessarily what they select on checkout ...

    What if instead you use for $sendto:
    $_SESSION['sendto']
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  5. #5
    Join Date
    Sep 2010
    Posts
    16
    Plugin Contributions
    0

    Default Re: Problem with new shipping module ported from osc

    I modified to
    Code:
      function pobierz_klienta() {
    
        global $db;
    
        $account_query = $db->Execute("select
        customers_email_address from 
        " . TABLE_CUSTOMERS . " where customers_id = '" . $_SESSION['customer_id'] . "'");
        $klient['email']=$account_query->fields['customers_email_address'];
    	
        $account_query = $db->Execute("select
        entry_postcode from 
        " . TABLE_ADDRESS_BOOK . " where address_book_id = '" . $_SESSION['sendto'] . "'");
        $klient['kod']=$account_query->fields['entry_postcode'];
        
        return $klient;
       
      }
    and it works perfectly. Thank you very much and have a nice day :)

  6. #6
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Problem with new shipping module ported from osc

    You are most welcome ... thanks for the update that you were just using the wrong variable and now things are working ...
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

 

 

Similar Threads

  1. array_merge error on ported OSC database
    By edadk in forum General Questions
    Replies: 12
    Last Post: 14 Nov 2008, 01:18 AM
  2. shipping module convert from osc help
    By FrilansReklam in forum Addon Shipping Modules
    Replies: 0
    Last Post: 8 Oct 2008, 06:38 PM
  3. Fedex Freight Module ported from OsCommerce
    By chadderuski in forum Addon Shipping Modules
    Replies: 19
    Last Post: 16 May 2008, 04:50 PM
  4. PriceTag Payment Module Ported From OsCommerce
    By psychox in forum Addon Payment Modules
    Replies: 0
    Last Post: 3 Jan 2007, 05:44 PM

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