Hello guys. Im really disperated. I use the Smartbill for Romanian Invoices.
The problem its like this.
That sistem have automaticaly updating quantity to my website.
I receive the following erorrs and cant update quantity:
2025-02-05 10:58:10 - PHP Unknown: Constant FILTER_SANITIZE_STRING is deprecated in /home/xxx/public_html/admin/model/extension/smartbill_product.php on line 176
2025-02-05 10:58:10 - PHP Unknown: Constant FILTER_SANITIZE_STRING is deprecated in /home/xxx/public_html/admin/model/extension/smartbill_product.php on line 177
Error! SyntaxError: Unexpected token '<', "Unknown"... is not valid JSON.
Opencart version 3.0.3.9 php version 8.2.
Thank you all !
The problem its like this.
That sistem have automaticaly updating quantity to my website.
I receive the following erorrs and cant update quantity:
2025-02-05 10:58:10 - PHP Unknown: Constant FILTER_SANITIZE_STRING is deprecated in /home/xxx/public_html/admin/model/extension/smartbill_product.php on line 176
2025-02-05 10:58:10 - PHP Unknown: Constant FILTER_SANITIZE_STRING is deprecated in /home/xxx/public_html/admin/model/extension/smartbill_product.php on line 177
Error! SyntaxError: Unexpected token '<', "Unknown"... is not valid JSON.
Opencart version 3.0.3.9 php version 8.2.
Thank you all !
Is there any reason you won't contact the extension author? This does not appear to be an issue caused by OpenCart.
BTW.: You should upgrade to OC 3.0.4.0, it has a number of bugfixes, and better PHP 8 support.
BTW.: You should upgrade to OC 3.0.4.0, it has a number of bugfixes, and better PHP 8 support.
Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig
Thank you. I have some extensions that working on only version 3.0.3.9,t he autor of smartbill doesent answer ..
Try switching off error display as a workaround, until it's fixed. You may have to switch error display of in all 3 places.
2025-02-05 10:58:10 - PHP Unknown: Constant FILTER_SANITIZE_STRING is deprecated in /home/xxx/public_html/admin/model/extension/smartbill_product.php on line 176
2025-02-05 10:58:10 - PHP Unknown: Constant FILTER_SANITIZE_STRING is deprecated in /home/xxx/public_html/admin/model/extension/smartbill_product.php on line 177
Code: Select all
<?php
/**
*
* Class for mapping SmartBill Products
*
* @link http://www.smartbill.ro
* @since 1.0.0
*
* @copyright Intelligent IT SRL 2018
*/
class SmartBill_Product {
/**
* The Name of the SmartBill product.
*
* @since 3.0.2
* @access private
* @var string $name The Name of the SmartBill product.
*/
private $name;
/**
* The sku code of the SmartBill product.
*
* @since 3.0.2
* @access private
* @var string $sku The sku code of the SmartBill product.
*/
private $sku;
/**
* The measuring unit of the SmartBill product.
*
* @since 3.0.2
* @access private
* @var string $measuring_unit The measuring unit of the SmartBill product.
*/
private $measuring_unit;
/**
* The quantity of the SmartBill product.
*
* @since 3.0.2
* @access private
* @var int $quantity The quantity of the SmartBill product.
*/
private $quantity;
/**
* The opencart product that coresponds to the SmartBill product.
*
* @since 3.0.2
* @access private
* @var string|null $oc_product opencart product id.
*/
private $oc_product=null;
/**
* The database column for searching product by code
*
* @since 3.0.2
* @access private
* @var string $sku_type column name.
*/
private $sku_type;
/**
* Opencart language id;
*
* @since 3.0.2
* @access private
* @var int $language_id column name.
*/
private $language_id;
/**
* Initialize the class and set its properties.
*
* @since 3.0.2
* @param string $name The Name of the SmartBill product.
* @param string $sku The sku code of the SmartBill product.
* @param string $measuring_unit The measuring unit of the SmartBill product.
* @param int $quantity The quantity of the SmartBill product.
* @param string $sku_type .
* @param int $language_id .
*
*/
public function __construct($n, $c, $mu, $q, $st, $lang){
$this->name = (string) $n;
$this->sku = (string) $c;
$this->measuring_unit = (string) $mu;
$this->quantity = (int) $q;
$this->sku_type = (string) $st;
$this->language_id = (int) $lang;
$this->db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
}
/**
* Find opencart product either by sku or by name.
*
* @return string|null $opencart_product opencart product id.
*/
private function find_oc_product(){
if(!empty( $this->sku )){
$this->oc_product = $this->get_opencart_product_by_code($this->sku, $this->sku_type);
}else{
if(preg_match("/(?=.*[;])(?=.*[(])(?=.*[)])/i", $product->productName)===0){
$this->oc_product = $this->get_opencart_product_by_name($this->name);
}else{
$temp_name=trim($this->name);
$temp_name=substr($temp_name, 0, -1);
$temp_name=explode('(',$temp_name);
$product_options=trim($temp_name[1]);
$product_options=explode(';',$product_options);
$temp_name=trim($temp_name[0]);
$this->oc_product = $this->get_product_with_options_by_name($temp_name,$product_options);
}
}
return $this->oc_product;
}
/**
* Update woocomemrce product stock if possible.
*
* @return boolean
*/
public function sync_quantity(){
$product = $this->find_oc_product();
if( empty($product) ){
return false;
}
$update=$this->db->query("UPDATE ".DB_PREFIX ."product SET `quantity` = '".$this->quantity."' WHERE `product_id` = '$product'");
if( false !== $update ){
return true;
}else{
return false;
}
}
/**
* Search for opencart product by name.
*
* @param string $product_name product name.
*
* @return Product|null $opencart_product
*/
private function get_opencart_product_by_name($product_name){
$product_name=$this->db->escape($product_name);
$product_name = filter_var($product_name, FILTER_SANITIZE_STRING);
$query = $this->db->query("SELECT `product_id` FROM ".DB_PREFIX."product_description WHERE name LIKE '".$product_name."'");
if ($query->num_rows) {
return $query->row['product_id'];
}else{
return null;
}
}
/**
* Search for opencart product by code.
*
* @param string $product_code product sku.
* @param string $sku_type column name for searching products.
*
* @return string|null $opencart_product
*/
private function get_opencart_product_by_code($product_code,$sku_type){
$product_code=$this->db->escape((string)$product_code);
$sku_type=$this->db->escape((string)$sku_type);
$product_code = filter_var($product_code, FILTER_SANITIZE_STRING);
$sku_type = filter_var($sku_type, FILTER_SANITIZE_STRING);
$query = $this->db->query( "SELECT `product_id` FROM ".DB_PREFIX."product WHERE `".$sku_type."` = '".$product_code."' ");
if ($query->num_rows) {
return $query->row['product_id'];
}else{
return null;
}
}
/**
* Search for opencart product with option by name.
*
* @param string $product_name product name.
* @param string $options options.
*
* @return string|null $opencart_product
*/
private function get_product_with_options_by_name($product_name,$options){
$product_name=$this->db->escape($product_name);
$product_name = filter_var($product_name, FILTER_SANITIZE_STRING);
//Create a sting with options (from smartbill product name) and sanitize
$product_options="";
foreach($options as $option){
$option=$this->db->escape($option);
$option=filter_var($option, FILTER_SANITIZE_STRING);
$product_options.="'".trim($option)."'";
$product_options.=",";
}
$product_options=substr($product_options, 0, -1);
//Select products that have only the searched options
//Has a count on options for excluding products that have more values in options
//That means that for example if i search for Hoodie with pocket (Dimension: 40x60cm; Color: Red) there must be a product with the options dimension and color that have ONLY 1 values each, Red and 40x60cm
$query = $this->db->query(" SELECT product_id, Count(Options) AS CountOfOptions
FROM (
SELECT ".DB_PREFIX."product_description.product_id, ((".DB_PREFIX."option_description.name & ': ' & ".DB_PREFIX."option_value_description.name)) AS Options, ".DB_PREFIX."product_description.name
FROM ".DB_PREFIX."product_description
INNER JOIN (".DB_PREFIX."option_description
INNER JOIN (".DB_PREFIX."product_option_value
INNER JOIN ".DB_PREFIX."option_value_description
ON ".DB_PREFIX."product_option_value.option_value_id = ".DB_PREFIX."option_value_description.option_value_id)
ON (".DB_PREFIX."option_description.option_id = ".DB_PREFIX."product_option_value.option_id)
AND (".DB_PREFIX."option_description.option_id = ".DB_PREFIX."option_value_description.option_id))
ON ".DB_PREFIX."product_description.product_id = ".DB_PREFIX."product_option_value.product_id
WHERE (((((".DB_PREFIX."option_description.name & ': ' & ".DB_PREFIX."option_value_description.name)))
In ($product_options))
And ((".DB_PREFIX."product_description.name)='$product_name'))) AS CountOfOptions
GROUP BY product_id HAVING (((Count(Options))=".count($options)."))");
if ($query->num_rows) {
return $query->row['product_id'];
}else{
return null;
}
}
/**
* Get Object properties as array for use in csv export.
*
* @return Array $product.
*/
public function to_arr(){
$product_id = $this->oc_product;
if(empty($product_id)){
$product_title = 'Produsul nu a fost gasit in nomenclatorul opencart.';
$product_id="";
}else{
$product = $this->get_product($product_id);
if(!empty($product) && isset($product['name'])){
$product_title = $product['name'];
}else{
$product_title = 'Produsul nu a fost gasit in nomenclatorul opencart.';
}
}
return [$this->sku, $this->name, $product_title, $product_id, $this->quantity];
}
private function get_product($product_id) {
$query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->language_id . "'");
return $query->row;
}
}
Error! SyntaxError: Unexpected token '<', "Unknown"... is not valid JSON.
Cant put code here i uploaded the file where i receive this error:
Cant put code here i uploaded the file where i receive this error:
That error is likely caused because you have error display on. Try switching off error display as a workaround, until it's fixed. You may have to switch error display of in all 3 places. Then look in both the OpenCart and PHP error logs for the errors that need fixing.
I'd look up and see if strip_tags() would work in place of the lines that have FILTER_SANITIZE_STRING
i.e.
$product_code = filter_var($product_code, FILTER_SANITIZE_STRING);
$product_code = strip_tags($product_code);
I'd update those and see what other errors show.
Does this still occur? Error! SyntaxError: Unexpected token '<', "Unknown"... is not valid JSON.
If so, where, when? Anything in the error logs.
Mike
cue4cheap not cheap quality
according to the documentation:
FILTER_SANITIZE_STRING:
Strip tags and HTML-encode double and single quotes, optionally strip or encode special characters. Encoding quotes can be disabled by setting FILTER_FLAG_NO_ENCODE_QUOTES. (Deprecated as of PHP 8.1.0, use htmlspecialchars() instead.)
This happens when i go in Settings in Smartbill extension and i apply to collect quantity manual.
Cue4cheap wrote: ↑Fri Feb 07, 2025 9:03 amI'd look up and see if strip_tags() would work in place of the lines that have FILTER_SANITIZE_STRING
i.e.
$product_code = filter_var($product_code, FILTER_SANITIZE_STRING);
$product_code = strip_tags($product_code);
I'd update those and see what other errors show.
Does this still occur? Error! SyntaxError: Unexpected token '<', "Unknown"... is not valid JSON.
If so, where, when? Anything in the error logs.
Mike
Before posting here endless, read this here and change the code es mentioned: https://www.php.net/manual/it/filter.co ... ize-string
On the other hand, the developer of that extension should support php8.x asap as this is nowadays standard!
And if you or this develper are/is not able to solve the issue, hire a professional developer from here: viewforum.php?f=88
On the other hand, the developer of that extension should support php8.x asap as this is nowadays standard!
And if you or this develper are/is not able to solve the issue, hire a professional developer from here: viewforum.php?f=88
Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.
Thank you. But i dont want to hire to fix this module because its my business to fix it. I just ask for some guidance to do it my self..OSWorX wrote: ↑Fri Feb 07, 2025 4:59 pmBefore posting here endless, read this here and change the code es mentioned: https://www.php.net/manual/it/filter.co ... ize-string
On the other hand, the developer of that extension should support php8.x asap as this is nowadays standard!
And if you or this develper are/is not able to solve the issue, hire a professional developer from here: viewforum.php?f=88
In which case you may be better to post on stackoverflow https://stackoverflow.com/questions
Or get directions here https://www.google.com/search?q=constan ... deprecated
Have you tried the support button on the extension page (if you purchased it from the Opencart Marketplace)
Or get directions here https://www.google.com/search?q=constan ... deprecated
Have you tried the support button on the extension page (if you purchased it from the Opencart Marketplace)
DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.
https://www.youtube.com/watch?v=zXIxDoCRc84
As other have pointed out FILTER_SANITIZE_STRING being deprecated should be a pretty easy fix. I provided one possible fix based upon where the data comes from (i.e. the database and the write into the database for things like product_name should already be sanitized when written).poterasal wrote: ↑Fri Feb 07, 2025 11:36 pmThank you. But i dont want to hire to fix this module because its my business to fix it. I just ask for some guidance to do it my self..OSWorX wrote: ↑Fri Feb 07, 2025 4:59 pmBefore posting here endless, read this here and change the code es mentioned: https://www.php.net/manual/it/filter.co ... ize-string
On the other hand, the developer of that extension should support php8.x asap as this is nowadays standard!
And if you or this develper are/is not able to solve the issue, hire a professional developer from here: viewforum.php?f=88
Try that fix or the other fix (htmlspecialchars) and report back or you might have to get someone to do it for free if the developer will not (or pay) sorry we don't have that extension.
Mike
cue4cheap not cheap quality
The data its take it by SMARTBILL MAIN WEBSITE where actualy there its our quantitys.Cue4cheap wrote: ↑Sat Feb 08, 2025 12:35 amAs other have pointed out FILTER_SANITIZE_STRING being deprecated should be a pretty easy fix. I provided one possible fix based upon where the data comes from (i.e. the database and the write into the database for things like product_name should already be sanitized when written).poterasal wrote: ↑Fri Feb 07, 2025 11:36 pmThank you. But i dont want to hire to fix this module because its my business to fix it. I just ask for some guidance to do it my self..OSWorX wrote: ↑Fri Feb 07, 2025 4:59 pmBefore posting here endless, read this here and change the code es mentioned: https://www.php.net/manual/it/filter.co ... ize-string
On the other hand, the developer of that extension should support php8.x asap as this is nowadays standard!
And if you or this develper are/is not able to solve the issue, hire a professional developer from here: viewforum.php?f=88
Try that fix or the other fix (htmlspecialchars) and report back or you might have to get someone to do it for free if the developer will not (or pay) sorry we don't have that extension.
Mike
From smartbill main site i need to fit in my opencart quantity and update. This what actually this extension do it. But in my case i have errors.
The error with Json its occurs when i go in the extension smartbill and i press manual fit quantity from smartbill.
The sanititaze error its constant whatever i do.
Man god bless you! This was the fix ! But i encount another problem. Everything its sync but in product options i have different products. That options the SKU that actualy sync with SMARTBILL its not read in opencart in product options SKU. Multi Options with multi SKU. How can i fix this ?Cue4cheap wrote: ↑Fri Feb 07, 2025 9:03 amI'd look up and see if strip_tags() would work in place of the lines that have FILTER_SANITIZE_STRING
i.e.
$product_code = filter_var($product_code, FILTER_SANITIZE_STRING);
$product_code = strip_tags($product_code);
I'd update those and see what other errors show.
Does this still occur? Error! SyntaxError: Unexpected token '<', "Unknown"... is not valid JSON.
If so, where, when? Anything in the error logs.
Mike
You are resistant to advices .. so when you are able to solve your problems by yourself, it's good for you.poterasal wrote: ↑Sat Feb 08, 2025 4:13 amMan god bless you! This was the fix ! But i encount another problem. Everything its sync but in product options i have different products. That options the SKU that actualy sync with SMARTBILL its not read in opencart in product options SKU. Multi Options with multi SKU. How can i fix this ?Cue4cheap wrote: ↑Fri Feb 07, 2025 9:03 amI'd look up and see if strip_tags() would work in place of the lines that have FILTER_SANITIZE_STRING
i.e.
$product_code = filter_var($product_code, FILTER_SANITIZE_STRING);
$product_code = strip_tags($product_code);
I'd update those and see what other errors show.
Does this still occur? Error! SyntaxError: Unexpected token '<', "Unknown"... is not valid JSON.
If so, where, when? Anything in the error logs.
Mike
But don't waste our time anymore with your problems when you are so smart.
And for the last question: fix it or hire someone else - this discussion here is closed because has nothing to do with your other problems.
Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.
Who is online
Users browsing this forum: No registered users and 5 guests