Zen Cart Logo
Forums / Addon Shipping Modules / Problem with new shipping module ported from osc

Problem with new shipping module ported from osc

Views: 1,578

Results 1 to 6 of 6
18 Nov 2010, 11:59 AM
#1
blood2 avatar

blood2

New Zenner

Join Date:
Sep 2010
Posts:
16
Plugin Contributions:
0

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.php/Developers_-_Porting_modules_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:

Call to undefined function zen_db_fetch_array()   on line 35

and

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:

  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;
   
  }
18 Nov 2010, 5:25 PM
#2
drbyte avatar

drbyte

Sensei

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

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.

27 Jan 2011, 3:56 PM
#3
blood2 avatar

blood2

New Zenner

Join Date:
Sep 2010
Posts:
16
Plugin Contributions:
0

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 ``` 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; } } ?>
27 Jan 2011, 4:36 PM
#4
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Problem with new shipping module ported from osc

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

As an Example, you have:

    $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']

28 Jan 2011, 11:21 AM
#5
blood2 avatar

blood2

New Zenner

Join Date:
Sep 2010
Posts:
16
Plugin Contributions:
0

Re: Problem with new shipping module ported from osc

I modified to

  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 :)

28 Jan 2011, 2:28 PM
#6
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

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 ... :smile: