well after a few days at this it seems that the more popular it becomes the more confused it gets so if you use it in a busy period it is more likely to make mistakes. we had a module that showed in the dashboard at one point, sadly now we have the following and it has timed me out for an hour for possibly the last time i find entertaining :s
Code:
[26-Jan-2023 02:01:32 UTC] PHP Fatal error: Uncaught Error: Using $this when not in object context in /includes/modules/shipping/royalmail_clickanddrop.php:32
Stack trace:
#0 /adminfoldername/modules.php(184): include()
#1 /adminfoldername/index.php(11): require('/home/u55452107...')
#2 {main}
thrown in /includes/modules/shipping/royalmail_clickanddrop.php on line 32
[26-Jan-2023 02:01:32 UTC] Request URI: /adminfoldername/index.php?cmd=modules&set=shipping, IP address: 86.25.115.190
--> PHP Fatal error: Uncaught Error: Using $this when not in object context in /includes/modules/shipping/royalmail_clickanddrop.php:32
Stack trace:
#0 /adminfoldername/modules.php(184): include()
#1 /adminfoldername/index.php(11): require('/home/u55452107...')
#2 {main}
thrown in /includes/modules/shipping/royalmail_clickanddrop.php on line 32.
my code for this file if anyone does come across this out of curiosity is currently about the 14th revision and possibly a typo or curly bracket away from working or that far off its hopeless?
Code:
<?php
class royalmail_clickanddrop {
public $code;
public $title;
public $description;
public $enabled;
public $api_key;
public $category_exclude;
public $free_shipping_over;
public $free_shipping_over_category;
public $box_size;
public function check() {
global $order;
// class constructor
function __construct() {
global $order;
$this->types = array('letter' => 'Letter',
'largeLetter' => 'Large Letter',
'smallParcel' => 'Small Parcel',
'mediumParcel' => 'Medium Parcel',
'parcel' => 'Parcel',
'documents' => 'Documents');
}
}
}
$this->code = 'royalmail_clickanddrop';
$this->title = MODULE_SHIPPING_ROYALMAIL_CLICKANDDROP_TEXT_TITLE;
$this->description = MODULE_SHIPPING_ROYALMAIL_CLICKANDDROP_TEXT_DESCRIPTION;
$this->sort_order = MODULE_SHIPPING_ROYALMAIL_CLICKANDDROP_SORT_ORDER;
$this->icon = '';
$this->tax_class = MODULE_SHIPPING_ROYALMAIL_CLICKANDDROP_TAX_CLASS;
$this->enabled = ((MODULE_SHIPPING_ROYALMAIL_CLICKANDDROP_STATUS == 'True') ? true : false);
$this->api_key = defined('MODULE_SHIPPING_ROYALMAIL_CLICKANDDROP_API_KEY') ? MODULE_SHIPPING_ROYALMAIL_CLICKANDDROP_API_KEY : '';
$this->category_exclude = explode(',',MODULE_SHIPPING_ROYALMAIL_CLICKANDDROP_CATEGORY_EXCLUDE);
$this->free_shipping_over = MODULE_SHIPPING_ROYALMAIL_CLICKANDDROP_FREE_SHIPPING_OVER;
$this->free_shipping_over_category = explode(',',MODULE_SHIPPING_ROYALMAIL_CLICKANDDROP_FREE_SHIPPING_OVER_CATEGORY);
$this->box_size = explode(',',MODULE_SHIPPING_ROYALMAIL_CLICKANDDROP_BOX_SIZE);
$this->check();
if (MODULE_SHIPPING_ROYALMAIL_CLICKANDDROP_STATUS == 'True') {
if (($this->enabled == true) && ((int)MODULE_SHIPPING_ROYALMAIL_CLICKANDDROP_ZONE > 0)) {
$check_flag = false;
$check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_ROYALMAIL_CLICKANDDROP_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
while ($check = tep_db_fetch_array($check_query)) {
if ($check['zone_id'] < 1) {
$check_flag = true;
break;
} elseif ($check['zone_id'] == $order->delivery['zone_id']) {
$check_flag = true;
break;
}
}
// class methods
function quote($method = '') {
global $order, $shipping_weight, $shipping_num_boxes;
$dest_country = $order->delivery['country']['iso_code_2'];
$dest_zip = $order->delivery['postcode'];
$weight = $shipping_weight;
$weight_class = 'kg';
$weight = zen_get_shipping_weight($weight, $weight_class);
// Check if the current product category is excluded from shipping
$product_categories = zen_get_categories_for_product($_SESSION['cart']->get_products()[0]['id']);
foreach($product_categories as $category_id) {
if(in_array($category_id,$this->category_exclude)) {
return array();
}
}
$api_url = 'https://api.royalmail.com/shipping/v2/pricing/' . $dest_country . '/' . $weight;
$api_headers = array(
'Content-Type: application/json',
'Authorization: Bearer ' . $this->api_key
);
$box_size = $this->check_box_size($_SESSION['cart']->get_products()[0]['id']);
$api_url .= '/' . $box_size;
if($this->api_key == ''){
trigger_error('API Key is not set', E_USER_ERROR);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $api_headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_errno($ch)) {
trigger_error('Error connecting to the Royal Mail API: ' . curl_error($ch), E_USER_ERROR);
}
curl_close($ch);
$response_data = json_decode($response, true);
if ($response_data['status'] != 'success') {
trigger_error('Error in response from the Royal Mail API: ' . $response_data['message'], E_USER_ERROR);
}
$quote_data = array();
foreach($response_data['prices'] as $service => $price) {
$quote_data['royalmail_clickanddrop_' . $service] = array(
'id' => 'royalmail_clickanddrop_' . $service,
'title' => $service,
'cost' => $price,
'tax' => zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']),
'cod_fee' => 0,
'calc_tax' => 'per_item'
);
}
// Free shipping over certain order value or category
if ($this->free_shipping_over != '') {
$free_shipping = false;
if (is_numeric($this->free_shipping_over) && $this->free_shipping_over <= $order->info['subtotal']) {
$free_shipping = true;
} elseif (in_array($_SESSION['cart']->get_products()[0]['id'],$this->free_shipping_over_category)) {
$free_shipping = true;
}
if ($free_shipping) {
foreach($quote_data as $key => $value) {
$quote_data[$key]['cost'] = 0;
}
}
}
return $quote_data;
}
function check_box_size($product_id) {
global$db;
$box_size = $this->box_size;
// Check if a custom box size has been set for this product
$product_query = $db->Execute("SELECT products_box_size FROM " . TABLE_PRODUCTS . " WHERE products_id = " . (int)$product_id);
if ($product_query->RecordCount() > 0) {
$custom_box_size = $product_query->fields['products_box_size'];
if (!empty($custom_box_size)) {
$box_size = $custom_box_size;
}
}
return $box_size;
}
}
}
i think its safe to say if the qr tickets module doesnt work when installed and tested it will probably need a lot of magic too, we shall see on that one but i dont want to test install another module without getting this one working right and it seems like i'm just re editing this same file over and over again with new suggestions from the ai sadly on the royal mail module
Bookmarks