I would like to search for products by the manufacturer on Opencart 2.3.0.2.
On catalog/model/catalog/product.php
Before
$sql .= " LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id)
I put this code:
$sql .= " LEFT JOIN " . DB_PREFIX . "manufacturer m ON (m.manufacturer_id = p.manufacturer_id) ";
and Before the line:
$sql .= " OR LCASE(p.model) = '" . $this->db->escape(utf8_strtolower($data['filter_name'])) . "'";
I put this code
$sql .= " ORDER BY p.quantity<1, LCASE(" . $data['sort'] . ")";
But it shows me:
Unknown: Object of class DB could not be converted to string on
catalog\model\catalog\product.php
How can i search name on table manufacturer and shows to my customers products by manufacturer
Try this code it will help you
your last order by code is wrong - remove this
$sql .= " ORDER BY p.quantity<1, LCASE(" . $data['sort'] . ")";
Do this below
before
$sql .= " GROUP BY p.product_id";
put this code
$sql .= " AND p.quantity > 0";
You have to comment this code for More then Zero quantity
/* comment this code
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
if ($data['sort'] == 'pd.name' || $data['sort'] == 'p.model') {
$sql .= " ORDER BY LCASE(" . $data['sort'] . ")";
} elseif ($data['sort'] == 'p.price') {
$sql .= " ORDER BY (CASE WHEN special IS NOT NULL THEN special WHEN discount IS NOT NULL THEN discount ELSE p.price END)";
} else {
$sql .= " ORDER BY " . $data['sort'];
}
} else {
$sql .= " ORDER BY p.sort_order";
}
*/
and add this
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
if ($data['sort'] == 'pd.name' || $data['sort'] == 'p.model') {
$sql .= " ORDER BY p.quantity, LCASE(" . $data['sort'] . ")";
} elseif ($data['sort'] == 'p.price') {
$sql .= " ORDER BY (CASE WHEN special IS NOT NULL THEN special WHEN discount IS NOT NULL THEN discount ELSE p.price END)";
} else {
$sql .= " ORDER BY p.quantity, " . $data['sort'];
}
} else {
$sql .= " ORDER BY p.quantity, p.sort_order";
}
Related
all!
I request a JSON from TMDB and save it as a file on the local harddisk. Then I read in the file and decode it with nlohmann::json. The next step is to iterate the json data and extract a few parts of the info. While it is no problem getting types „string“, „boolean“ etc. I’m struggling with an „array“ type. (Later on the type „object“ might show same problems…) Goal is to transform the json data into some „ini“ style type like
[tt1234567]
title = abcdefghij
runtime = 123
...
I iterate through the root of the decoded json by:
using json = nlohmann::json;
{
auto jsonData = json::parse( jsonText );
// std::cout << jsonData.dump( 1 ) << "\n";
for ( const auto &jsonItem : jsonData.items() )
{
jsonKey = jsonItem.key();
jsonValue = "";
if ( jsonItem.value().is_null() ) { jsonValue = "(null)"; }
else if ( jsonItem.value().is_boolean() ) { if ( jsonItem.value() ) { jsonValue = "(boolean) yes"; } else { jsonValue = "(boolean) no"; } }
else if ( jsonItem.value().is_string() ) { jsonValue = "(string) '" + string_left( jsonItem.value(), 25 ) + "'"; }
[ . . . ]
std::cout << jsonKey << ": " << jsonValue << "\n";
Screen output is like:
adult: (boolean) no
belongs_to_collection: (null)
budget: (unsigned) 45000000
credits: (object)
genres: (array) [ . . . ]
[ et al ]
My problem is that I don’t know the correct syntax to handle the „array“ type and, in fact, I’m not quite sure if it is really an array despite the fact it is enclosed in []. The code block
else if ( jsonItem.key() == "genres" ) // array
{
std::cout << " jsonItem: " << jsonItem << "\n"; // {"genres":[{"id":12,"name":"Abenteuer"},{"id":28,"name":"Action"}]}
jsonKey = jsonItem.key();
std::cout << " jsonKey: " << jsonKey << "\n"; // genres
// jsonValue = jsonItem.value(); // <-- returns array, but jsonValue expects string
// std::cout << " jsonValue: " << jsonValue << "\n";
auto jsonValueArray = jsonItem.value().array();
std::cout << " jsonValueArray: " << jsonValueArray << " (" << sizeof( jsonValueArray ) << ")\n"; // [] (16)
auto jsonValueFlat = jsonItem.value().flatten();
std::cout << " jsonValueFlat: " << jsonValueFlat << "\n"; // {"/0/id":12,"/0/name":"Abenteuer","/1/id":28,"/1/name":"Action"}
std::cout << " " << jsonKey << " elements: " << jsonValueArray.size() << "\n"; // 0
i = 0;
// for ( const auto &jsonValue : jsonValueArray )
// for ( i = jsonValueArray.begin(); i < jsonValueArray.end(); i++ )
for ( i = 0; i < jsonValueArray.size(); i++ )
{
std::cout << jsonValue << "\n";
iniKey = "Genre" + std::to_string( i );
iniValue = "";
iniValue = jsonValue;
iniText.append( iniKey );
iniText.append( " = " );
iniText.append( iniValue );
iniText.append( "\n" );
// i++;
}
}
produces
jsonItem: {"genres":[{"id":12,"name":"Abenteuer"},{"id":28,"name":"Action"}]}
jsonKey: genres
jsonValueArray: [] (16)
jsonValueFlat: {"/0/id":12,"/0/name":"Abenteuer","/1/id":28,"/1/name":"Action"}
genres elements: 0
So I see a jsonItem with „genres: [xxx]“ content, thus it is identified as an array. The „sizeof“ returns 16 and I interpret it as 4 pointer with 4 bytes each (or 2 with 8 bytes?). On the other hand the array() function seems to return an empty array [] with 0 elements. And now I’m stuck…
What I want to achieve: Extracting the „genres“ list from the json and concatenate the elements with „;“ like
genres = Abenteuer;Action
in the above exampe.
Michael
Ok, I figured it out. The central point was the misunderstanding of .array() from the JSON object. After fiddling around a bit the following branch
else if ( jsonItem.key() == "genres" ) // array
{
std::cout << " jsonItem: " << jsonItem << "\n"; // {"genres":[{"id":12,"name":"Abenteuer"},{"id":28,"name":"Action"}]}
jsonKey = jsonItem.key();
std::cout << " jsonKey: " << jsonKey << "\n"; // genres
auto jsonValueArray = jsonItem.value(); // [{"id":12,"name":"Abenteuer"},{"id":28,"name":"Action"}] (16)
std::cout << " jsonValueArray: " << jsonValueArray << " (" << sizeof( jsonValueArray ) << ")\n"; // [] (16)
i = 0;
for ( const auto &jsonValue : jsonValueArray )
{
iniKey = "Genres";
iniValue = jsonValue["name"];
std::cout << " " << jsonValue << " --> key:'" << iniKey << "', value:'" << iniValue << "'\n";
if ( i == 0 )
{
iniText.append( iniKey );
iniText.append( " = " );
}
else
{
iniText.append( ";" );
}
iniText.append( iniValue );
i++;
}
iniText.append( "\n" );
std::cout << " genres added: " << std::to_string( i ) << "\n";
}
now produces
genres: (array) [ . . . ]
jsonItem: {"genres":[{"id":12,"name":"Abenteuer"},{"id":28,"name":"Action"}]}
jsonKey: genres
jsonValueArray: [{"id":12,"name":"Abenteuer"},{"id":28,"name":"Action"}] (16)
{"id":12,"name":"Abenteuer"} --> key:'Genres', value:'Abenteuer'
{"id":28,"name":"Action"} --> key:'Genres', value:'Action'
genres added: 2
resp.
[tt0446013]
adult = no
Genres = Abenteuer;Action
ID_TMDB = 1534
ID_IMDB = tt0446013
Title_Original = Pathfinder
Overview = An sich stammt der junge
Release_Date = 2007-01-11
Runtime = 99
Tagline = Zwei Welten , ein Krieger
Title = Pathfinder - Fährte des
and that's the output I wanted to have.
I am creating two tables with the following queries. Based on the region, the number of columns might be different and some columns might not be used for some regions.
String currentTableQuery = "CREATE TABLE \"" + currentTable + "\" \n" +
"AS \n" +
"SELECT " + columns + "\n" +
"FROM \"" + region + "\" \n" +
"WHERE partition_0=\'" + date + "\' AND partition_1=\'" + table + "\';";
Columns is an array:
String[] columns = new String[]{"col0", "col1", "col2", "col3", "col4", ...
Previous table:
String previousTableQuery = "CREATE TABLE \"" + previousTable + "\" \n" +
"AS \n" +
"SELECT " + columns + "\n" +
"FROM \"" + region + "\" \n" +
"WHERE partition_0=\'" + previousDate + "\' AND partition_1=\'" + table + "\';";
And after this, I am creating a delta table like below:
String deltaProcessingQuery =
"CREATE TABLE " + deltaTable + "\n" +
"WITH (\n" +
"format = 'TEXTFILE', \n" +
"field_delimiter = '\\t', \n" +
"write_compression = 'NONE', \n" +
"external_location = \'" + uploadLocation + "\' \n" +
")" + "\n" +
"AS" + "\n" +
"SELECT * FROM \"" + currentTable + "\" \n" +
"EXCEPT" + "\n" +
"SELECT * FROM \"" + previousTable + "\" ;";
But in the final delta table, columns which do not have data (or are extra columns) are backfilled with garbage data: \N. I am not sure where this data (\N) is coming from. How can I change that to be empty data?
I am trying to insert into my SQL database using QT. I have been successful with other SQL commands like delete. But here Nothing is added to my database. I am wondering if maybe there is a syntax error somewhere.
QSqlQuery task;
task.prepare("insert or replace into animals(name, type, breed, gender, age, lifespan, noise, intelligence, adaptability, personality, diet, environment, pastOwners, timeDedication, costDedication, medication, reproductability, appetite, energyLevel, weight, height) values ('" + name + "', '" + type + "','" + breed + "','" + gender + "', " + age + ", " + lifespan + ", " + noise + ", " + intelligence + ", " + adaptability + " ,'" + personality + "', '" + diet + "', '" + environment + "', " + pastOwners + ", " + timeDedication + ", " + costDedication + ", " + medication + ", " + reproductability + ", '" + appetite + "', " + energyLevel + ", " + weight + ", " + height + ");");
task.exec();
For prepared query you need write something like this:
QSqlQuery query;
query.prepare("INSERT INTO person (id, forename, surname) "
"VALUES (:id, :forename, :surname)");
query.bindValue(":id", 1001);
query.bindValue(":forename", "Bart");
query.bindValue(":surname", "Simpson");
query.exec();
Binding values will help avoid sql injection.
im wondering how to dynamicaly declare variable name with ionic 2.
i want to implemet a read more function with ion-list result but to do it i need to have individual variable names.
// my ts file
import { Component } from '#angular/core';
import { NavController,Platform ,LoadingController, NavParams } from 'ionic-
angular';
import { GardeService } from '../../app/services/Garde.service';
#Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class Home {
//data:any;
public newslist: Array<Object>;
mytext:any;
prewords:any;
textpreview:any;
fulltext:any;
constructor(public data:GardeService) {}
ngOnInit()
{
this.loadnews();
this.fulltext = true;
this.textpreview = false;
}
public loadnews(){
this.newslist = [];
var map: {[key:string]:string} = {};
this.data.LoadNews().subscribe(
data => {
for(let i=0;i<data.length;i++){
//this.newslist.push(data[i]);
//console.log("news",data[i].content);
this.mytext = data[i].content.split(' ');
this.prewords = this.mytext[0] + " " + this.mytext[1] + " " +
this.mytext[2] + " " + this.mytext[3] + " " +
this.mytext[4] + " " + this.mytext[5] + " " + this.mytext[6] + " " +
this.mytext[7] + " " + this.mytext[8] + " " +
this.mytext[9] + " " + this.mytext[10] + " " + this.mytext[11] + " "
+ this.mytext[12] + " " + this.mytext[13] + " " +
this.mytext[14] + " " + this.mytext[15] + " " + this.mytext[16] + ""
+ this.mytext[17] + " " + this.mytext[18] + " " +
this.mytext[19] + " " + this.mytext[20];
//map['fulltext'+i] = true;
this.textpreview = false;
this.newslist.push({poster: data[i].poster, title: data[i].title,
img:data[i].img, content:data[i].content,
pre:this.prewords});
//console.log("les mots descriptifs",this.prewords);
}
},
err => {
console.log(err);
},
() => console.log('news loaded')
);
}
public readMore(){
this.textpreview = true;
this.fulltext = false;
}
}
// my html file
ion-col width-100 text-wrap>
<p style="text-align:justify;" color="dark" ion-text>
<span ion-text [hidden]="textpreview">{{item.pre}}</span><span
ion-text (click)="readMore()">...Lire plus</span>
<span ion-text [hidden]="fulltext">{{item.content}}</span>
</p>
</ion-col>
i want to have dynamic changing this.fulltext and this.textpreview variable names in order to do that because when i click the read more link all the content of all the ion-itens extend . i only want it to happen the place i click
I'm a new one used MYSQL.
The codes is:
void gdns_mysql::commit_task()
{
if (mysql_commit(conn) != 0)
{
throw_trackerr_str(boost::format("MysqlCommitError %d %s") % mysql_errno(conn) % mysql_error(conn));
}
}
This function commit_task is always spending 6~7 seconds.
I want to know why this happen ?
please list some reasons. Thank you
By the way:
The queries is like:
void gdns_mysql::update_server_status(std::string const& server_, std::string const& status_)
{
stringstream sql;
sql << "update server";
if (!status_.empty()) sql << " set status = '" << get_escape_string(status_) << "'";
else sql <<" set status = status_predict";
sql << " where serverip = '" << get_escape_string(server_) << "'"
<< endl;
execute(sql.str());
}
And
zone_ptrs_t gdns_mysql::query_zone_bykey(std::string const& zonename_)
{
string statement = "select * from zone";
bool where_flag = false;
if (!zonename_.empty())
{
statement += " where zonename = '" + get_escape_string(zonename_) + "'";
where_flag = true;
}
select(statement);
return fetch_datas<zone_t>();
}