admin管理员组文章数量:1220948
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 !
Ask for help on opencart forum . They told me to ask here.
Codes :
<?php
/** *
- Class for mapping SmartBill Products
- @link
- @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;
}
}
For the error : Error! SyntaxError: Unexpected token '<', "Unknown"... is not valid JSON.
PHP FILE FOR THIS ERROR. CANT PUT THE WHOLE CODE
The sanitaze its constant error The Json error its happen when i go in the smartbill extension and i apply to manual fit quantity from smartbill main site to opencart my site.
本文标签: Problem extension Smartbill gt Constant FILTERSANITIZESTRING is deprecated OpencartStack Overflow
版权声明:本文标题:Problem extension Smartbill > Constant FILTER_SANITIZE_STRING is deprecated Opencart - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739306677a2157388.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论