Prestashop bug error in classes/db/Db.php - prestashop-1.7

I have the error below
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '-12' at line 8<pre>SELECT cp.`id_product` FROM `devapp_product` p INNER JOIN devapp_product_shop product_shop ON (product_shop.id_product = p.id_product AND product_shop.id_shop = 1) LEFT JOIN `devapp_category_product` cp ON p.`id_product` = cp.`id_product` WHERE cp.`id_category` = 10 AND product_shop.`visibility` IN ("both", "catalog") ORDER BY p.date_add DESC LIMIT -12</pre>
at line 770 in file classes/db/Db.php
765. $dbg = debug_backtrace();
766. WebserviceRequest::getInstance()->setError(500, '[SQL Error] ' . $this->getMsgError() . '. From ' . (isset($dbg[3]['class']) ? $dbg[3]['class'] : '') . '->' . $dbg[3]['function'] . '() Query was : ' . $sql, 97);
767. } elseif (_PS_DEBUG_SQL_ && $errno && !defined('PS_INSTALLATION_IN_PROGRESS')) {
768. if ($sql) {
769. // throw new PrestaShopDatabaseException($this->getMsgError() . '<br /><br /><pre>' . $sql . '</pre>');
770. throw new PrestaShopDatabaseException($this->getMsgError() . '<pre>' . $sql . '</pre>');
771. }
772.
773. throw new PrestaShopDatabaseException($this->getMsgError());
774. }
775. }
----------
DbCore->displayError - [line 385 - classes/db/Db.php] - [1 Arguments]
DbCore->query - [line 613 - classes/db/Db.php] - [1 Arguments]
DbCore->executeS - [line 260 - modules/strelatedproducts/strelatedproducts.php] - [1 Arguments]
StRelatedProducts->getProducts - [line 528 - modules/stthemeeditor/classes/BaseProductsSlider.php] - [1 Arguments]
BaseProductsSlider->_prepareHook - [line 648 - modules/stthemeeditor/classes/BaseProductsSlider.php] - [1 Arguments]
BaseProductsSlider->hookDisplayLeftColumn - [line 326 - modules/strelatedproducts/strelatedproducts.php] - [2 Arguments]
Has anyone a similar problem..., when new users create an account can't add products in the basket.

Related

PHP: eval don't have value

I stored a Controller#Action in the database, but when I try to run it it don't has value.
I know that eval is very dangerous. If there is an alternative what I can use in this situation I'm open for it.
My code where I wan't to run it:
//$action = "ExchangeController::module_getAllValutaByBank";
//$params = "K&H";
$test = eval('\App\Http\Controllers\ModuleControllers' . "\\" . $action . "('" . $params . "');");
Debugbar::info($test);
The code what I want to eval:
It's an API request to the local ForexChange site. #param bank's name
#return stuctured string
public static function module_getAllValutaByBank($bankName){
$return = '';
$data['bankName'] = $bankName;
$response = self::getRequest($data);
if(is_array($response)){
$return .= $response[0]['bank'] . "\n";
foreach($response as $key => $item){
$return .= $item['valuta'] . " - " . round($item['buy'], 2) . " - " . round($item['sell'], 2) . "\n";
}
} else {
$return = $response;
}
Debugbar::info($return);
return $return;
}
Output of Debugbar::info($return);
K&H Bank GBP - 338.51 - 363.07 AUD - 189.9 - 207.8 DKK - 39.75 - 43.93
JPY - 2.26 - 2.48 CAD - 188.73 - 206.51 NOK - 30.92 - 34.18 CHF -
256.89 - 275.53 SEK - 29.18 - 32.26 USD - 246.14 - 260.32 CZK - 11.51 - 12.97 PLN - 69.87 - 78.79 EUR - 302.92 - 320.38 HRK - 39.39 - 44.41
Output of Debugbar::info($test);
null
Where it went wrong?
EDIT:
Found the solution:
$test = call_user_func('\App\Http\Controllers\ModuleControllers' . "\\" . $action, $params));
Found the solution:
$test = call_user_func('\App\Http\Controllers\ModuleControllers' . "\\" . $action, $params));

Doctrine distances function

I try to use a function which calculate distance between $user lat/lng and coordinates in my BDD with limited distance.
It's an SQL request and I try to use Doctrine to implement it.
Here is my code
$config = new \Doctrine\ORM\Configuration();
$config->addCustomNumericFunction('COS', 'DoctrineExtensions\Query\Mysql\Cos');
$config->addCustomNumericFunction('ACOS', 'DoctrineExtensions\Query\Mysql\Acos');
$config->addCustomNumericFunction('RADIANS', 'DoctrineExtensions\Query\Mysql\Radians');
$config->addCustomNumericFunction('SIN', 'DoctrineExtensions\Query\Mysql\Sin');
$maxLat = $form_citylat + rad2deg($rad / $R);
$minLat = $form_citylat - rad2deg($rad / $R);
$maxLng = $form_citylng + rad2deg(asin($rad / $R) / cos(deg2rad($form_citylat)));
$minLng = $form_citylng - rad2deg(asin($rad / $R) / cos(deg2rad($form_citylat)));
$qb = $this->createQueryBuilder('u')->select('u.lat, u.lng')
->addSelect('acos(sin(:lat)*sin(radians(u.Lat)) + cos(:lat)*cos(radians(u.Lat))*cos(radians(u.lng)-:lng)) * :R As D')
->where('lat Between :minlat And :maxlat And lng Between :minlng And :maxlng And acos(sin(:lat)*sin(radians(u.Lat)) + cos(:lat)*cos(radians(u.Lat))*cos(radians(u.Lng)-:lng)) * :R < :rad')
->setParameter('lat',deg2rad($form_citylat))
->setParameter('lng',deg2rad($form_citylng))
->setParameter('minlat',$minLat)
->setParameter('minlng',$minLng)
->setParameter('maxlat',$maxLat)
->setParameter('maxlng',$maxLng)
->setParameter('rad',$rad)
->setParameter('R',$R)
->orderBy('D');
return $qb->getQuery()->getResult();`
But I got this error message :
[Syntax Error] line 0, col 40: Error: Expected
Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got '.'
I tried different options but it doesn't work.
Anyone has an answer please ?
public function findByThemeAndDistance($theme,$distance,$user){
$latUser=$user->getAddress()->getLnt();
$lngUser = $user->getAddress()->getLgt();
return $this->createQueryBuilder('a')
//->select('a as activity,dist('.$distance.') as distance' )
->join('a.author','u')
->join('u.address','add')
->andWhere('a.theme=:val')
->andWhere( '(6378 * acos(cos(radians( add.lnt)) * cos(radians(' . $latUser . ')) * cos(radians(' . $lngUser . ') - radians(add.lgt)) + sin(radians(add.lnt )) * sin(radians(' . $latUser . '))))< :distance')
->setParameter('distance', $distance)
->setParameter('val',$theme)
->orderBy( 'a.author','ASC')
->getQuery()
->getResult();
}

Doctrine decode function

In my Symfony2 project, I want to get the sum of a column (Field1) only for some lines (Field2 = 1):
id Field1 Field2
1 10 1
2 20 1
3 30 0
4 40 1
5 50 0
In this example, I want a result of 70 (sum of lines 1, 2 and 4).
Since I Work with Oracle, I have this query working well in my SQL GUI :
SELECT
SUM(decode(Field2, 1, Field1, 0)) AS total
FROM myTable
Since Doctrine doesn't recognize Oracle decode function, I Tried to create mine :
namespace MyBundle\DQL;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\SqlWalker;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
/**
* "DECODE" "(" Expression "," Search "," Result "," Default ")"
*/
class DecodeFunction extends FunctionNode
{
public $expression;
public $search;
public $result;
public $default;
public function getSql(SqlWalker $sqlWalker)
{
return 'decode(' . $this->expression->dispatch($sqlWalker) . ','
. $this->search->dispatch($sqlWalker) . ','
. $this->result->dispatch($sqlWalker) . ','
. $this->default->dispatch($sqlWalker) . ')';
}
public function parse(Parser $parser)
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$this->expression = $parser->StringPrimary();
$parser->match(Lexer::T_COMMA);
$this->search = $parser->StringPrimary();
$parser->match(Lexer::T_COMMA);
$this->result = $parser->StringPrimary();
$parser->match(Lexer::T_COMMA);
$this->default = $parser->StringPrimary();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}
}
config.yml
doctrine:
orm:
entity_managers:
default:
auto_mapping: true
...
dql:
string_functions:
decode: MyBundle\DQL\DecodeFunction
And my querybuilder :
$qb = $this->createQueryBuilder('e');
$qb
->select('SUM(decode(e.Field2, :expect, e.Field1, :default)')
->setParameter('expect', 1)
->setParameter('default', 0);
But I got this error :
[Semantical Error] line 0, col 62 near 'Field2,': Error: Invalid PathExpression. Must be a StateFieldPathExpression.
So what I'm doing wrong?
Maybe is there a simpler solution?
Thanks

Unknown column in where clause while parsing csv to update table

I am parsing a CSV file to add records to a table. this is how I do it.
public function parse_csv($file) {
$this->load->library('CSVReader');
$csvData = $this->csvreader->parse_file($file);
foreach($csvData as $key => $row) {
$data_n[$key] = array(
'mf_date' => $row['mf_date'],
'mf_student_id' => $row['mf_student_id'],
'mf_sender' => $row['mf_sender'],
'mf_amount' => $row['mf_amount'],
'mf_trx_id' => $row['mf_trx_id'],
);
$this->db->insert('monthly_fee', $data_n[$key]);
$this->student_model->update_monthly_due($row['mf_student_id'], $row['mf_amount']);
}
}
I wish to update another table where there is three columns
1)md_student_id //unique
2)md_due
3)md_paid
I want to update that table while uploading the csv where mf_student_id and md_student_id matches with the model function below.
public function update_monthly_due($mf_student_id, $mf_amount)
{
$this->db->select('mf_student_id');
$this->db->from('monthly_fee');
$this->db->join('monthly_due', 'monthly_due.md_student_id = monthly_fee.mf_student_id');
$sql = "UPDATE monthly_due set md_due = md_due - " . $mf_amount . ", md_paid = md_paid + " . $mf_amount . " WHERE md_student_id = " . $mf_student_id;
$this->db->query($sql);
}
But when I upload a csv it generates the following error.
Error Number: 1054
Unknown column 'MCS20145B41' in 'where clause'
UPDATE monthly_due set md_due = md_due - 5500, md_paid = md_paid + 5500 WHERE md_student_id = MCS20145B41
Filename: F:\xampp\htdocs\student\system\database\DB_driver.php
Line Number: 330
What I am doing wrong?!
Thanks in advance
you should replace this line as follow
$sql = "UPDATE monthly_due set md_due = md_due - " . $mf_amount . ", md_paid = md_paid + " . $mf_amount . " WHERE md_student_id = '" . $mf_student_id . "'";
take attention to the end of this line
Why not use CI's active record instead of raw SQL queries.When doing it do it the correct way. This below:
Change this,
$sql = "UPDATE monthly_due set md_due = md_due - " . $mf_amount . ", md_paid = md_paid + " . $mf_amount . " WHERE md_student_id = " . $mf_student_id;
$this->db->query($sql);
To,
$this->db->where('md_student_id', $mf_student_id);
$this->db->set('md_due', "md_due - $mf_amount", FALSE);
$this->db->set('md_paid', "md_paid + $mf_amount", FALSE);
$this->db->update('monthly_due');
Explanation:
The reason this works is because the third (optional) FALSE parameter tells CodeIgniter not to protect the generated query with backticks ('). This means that the generated SQL will be:
UPDATE monthly_due set md_due = md_due - 5500, md_paid = md_paid + 5500 WHERE md_student_id = "MCS20145B41"

How can i overlay window subfile as400

this is the dds for my screen:
<pre>
<code>
A DSPSIZ(27 132 *DS4)
A R ASSUME
A ASSUME
A OVERLAY
A 1 3' '
A R SFLSEL SFL
A SFLNXTCHG
A SEL 1A B 4 2VALUES(' ' '1')
A 43 DSPATR(ND)
A 43 DSPATR(PR)
A FLDFET 8Y 0O 4 5EDTWRD(' / / ')
A FLDUSE 10A O 4 37
A FLDHOR 6Y 0O 4 28EDTWRD(' : : ')
A FLDFEC 8Y 0O 4 17EDTWRD(' / / ')
A FLDPER 20A H
A R CTRSEL SFLCTL(SFLSEL)
A CF03(03 'Salir')
A KEEP
A OVERLAY
A SFLCSRRRN(&RRN)
A 80 SFLDSP
A 81 SFLDSPCTL
A 82 SFLINZ
A 83 SFLCLR
A 40 SFLEND(*MORE)
A SFLSIZ(9999)
A SFLPAG(0008)
A WINDOW(*DFT 13 50)
A WDWBORDER((*COLOR BLU))
A WDWTITLE((*TEXT 'Intro = Continuar -
A F3 = Salir') *CENTER *BOTTOM)
A WDWTITLE((*TEXT 'CONSULTAR REVISION-
A ES PASADAS') *CENTER)
A NBR 4S 0H SFLRCDNBR(CURSOR)
A RRN 5S 0H
A 1 2'Op. 1=Seleccionar'
A COLOR(BLU)
A 2 2'Op Fecha Trab Fecha Gen Hora -
A Usuario '
A 3 2'==================================-
A =============='
A COLOR(WHT)
A MSGERR 30A O 1 20COLOR(RED)
</code>
</pre>
but for any razon always delete te background screen, i need to show the select but not delete the before screen.
i try several way to do that KEEP on control, ASSUME, OVERLAY, PUTOVR, RSTDSP *YES, and nothing work, please help me.
You might verify if the background screen was compiled with RSTDSP(*YES) or not. If not, try setting the attribute with the CHGDSPF command.
The problem is you require a separate record the uses OVERLAY and ASSUME. You do not have to display this record or reference it at all, it just has to be in the display file.
For example:
0017.70 A*--------------------------------------------------------------*
0017.80 A . . . . . . R BLKLN24
0018.00 A . . . . . . . . . . . . . . . . . . ASSUME
0018.10 A . . . . . . . . . . . . . . . . . . OVERLAY
should work.

Resources