How to solve the error syntax error, unexpected '=', expecting ')'? - opencart

i have code. but I can not understand why he swears?
This is line 17
if (!empty($city_result = $this->model_module_novapochta->getCity($this->request->post['novaposhta_key']))) {
**Parse error: syntax error, unexpected '=', expecting ')' in /home/s2332/***.com/www/admin/controller/shipping/novaposhta.php on line 17**
if (!empty($this->request->post['refresh']) && !empty($this->request->post['novaposhta_key'])) {
if (!empty($city_result = $this->model_module_novapochta->getCity($this->request->post['novaposhta_key']))) {
$this->session->data['error'] = $city_result;
} elseif (!empty($address_result = $this->model_module_novapochta->getAdress($this->request->post['novaposhta_key']))) {
$this->session->data['error'] = $address_result;
}
};

Your if statement is wrong...
You have write:
if (!empty($city_result = $this->model_module_novapochta->getCity($this->request->post['novaposhta_key']))) {
must be:
$city_result = $this->model_module_novapochta->getCity($this->request->post['novaposhta_key']);
if (!empty($city_result)) {
//your code here

Related

Fatal error: Call to a member function calculate() on null in D:\xampp\htdocs\ramesh\project1\dealer\admin\controller\sale\order.php on line 795

Am creating a custom total for products. Am using this code
$customerGroupId=$_COOKIE['customerGroupId'];
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price'))
{
$priceOld = $newPrice;
if($customerGroupId==25||$customerGroupId==0||$customerGroupId==26)
{
$total1 = $this->getPriceListForGhee($product['name'], $priceOld, $product['types'], $product['quantity']);
}
else
{
$total1 = $this->getPriceList($product['name'], $priceOld, $product['types'], $product['quantity']);
}
$total=$this->currency->format($this->tax->calculate($total1, $product['tax_class_id'], $this->config->get('config_tax')));
}
else
{
$total = false;
}
But i got some error like
Fatal error: Call to a member function calculate() on null in D:\xampp\htdocs\ramesh\project1\dealer\admin\controller\sale\order.php on line 795
How can i solve this error...?
If you're looking for getting total for product in Admin path you can use this code to implement yours:
$total = $this->currency->format($product['total'], $currency_code, $currency_value);
Of course you have to specify your own $currency_code and $currency_value

qt creator issue when include std string library

I have this function. I created it with libxml2 and std::string library.
#ifndef KNIHOVNA_H
#define KNIHOVNA_H
#include <string>
#include <libxml/tree.h>
std::string hledaniString(int index,xmlDocPtr sharedString)
{
std::string Istring;
xmlAttrPtr attr;
xmlChar *attrValue;
xmlNodePtr nodeLevel1 = sharedString->children;
int maxValue;
int aIndex;
attr = xmlHasProp(nodeLevel1, (const xmlChar*)"uniqueCount");
if (attr !=NULL)
{
attrValue = xmlGetProp(nodeLevel1, (xmlChar *)"uniqueCount");
}
else return "Chybny format souboru. Spatny soubor sharedStrings.xml.";
nodeLevel1 = nodeLevel1->children;
maxValue = atoi((const char *) attrValue);
xmlFree(attrValue);
if (maxValue<=index) return "Chybny format souboru. Spatny soubor sharedStrings.xml.";
for (aIndex = 0;aIndex < index; aIndex++ )
{
nodeLevel1 = nodeLevel1->next;
}
nodeLevel1 = nodeLevel1->children;
attrValue = xmlNodeGetContent(nodeLevel1);
xmlFree(attrValue);
attrValue = xmlNodeGetContent(nodeLevel1);
Istring = (char *) attrValue;
xmlFree(attrValue);
return Istring;
#endif // KNIHOVNA_H
I use it in Code Block project where is everything ok and in qt creator project where I get these errors:
/usr/include/c++/4.8/string:38: In file included from /usr/include/c++/4.8/string:38:0,
/usr/include/c++/4.8/bits/stl_relops.h:-1: In function 'std::string getString(int, xmlDocPtr)':
/usr/include/c++/4.8/bits/stl_relops.h:67: error: expected '=' before '__attribute__'
/usr/include/c++/4.8/bits/stl_relops.h:67: error: expected identifier before '__attribute__'
/usr/include/c++/4.8/bits/stl_relops.h:67: error: expected ';' before '__attribute__'
/usr/include/c++/4.8/bits/stl_relops.h:67: error: expected primary-expression before '__attribute__'
/usr/include/c++/4.8/bits/stl_relops.h:67: error: expected ';' before '__attribute__'
/home/daffy/qt projektz/revize/main.cpp:15: error: expected '}' at end of input
Could someone help me please ?

Syntax error : missing '{ ' before '.'

I have an AVOption structure:
static const AVOption options[] = {
COMMON_OPTIONS // error here
{ NULL }
};
and COMMON_OPTIONS is defined as:
#define COMMON_OPTIONS \
{ "interp", "select interpolation mode", OFFSET(interpolation), AV_OPT_TYPE_INT, {.i64=INTERPOLATE_TETRAHEDRAL}, 0, NB_INTERP_MODE-1, FLAGS, "interp_mode" }, \
{NULL}
I am getting an error:
2>c:\users\awki6\desktop\ffmpeg\libavfilter\vsrc_testsrc.cpp(98): error C2143: syntax error : missing '}' before '.'
Your COMMON_OPTIONS macro has already the { NULL } and does not ends with a ,, so:
static const AVOption options[] = {
COMMON_OPTIONS
};
will solve your problem.
Past answer before the edit:
Even if we don't know what does COMMON_OPTIONS expand to, I guess that you just miss the comma after it:
static const AVOption options[] = {
COMMON_OPTIONS,
// ^
{ NULL }
};

Strange compiler error in MSVC10

I've got the following code:
std::for_each(tokens.begin(), tokens.end(), [&](Token& t) {
static const std::unordered_map<std::wstring, Wide::Lexer::TokenType> mapping([]() -> std::unordered_map<std::wstring, Wide::Lexer::TokenType>
{
// Maps strings to TokenType enumerated values
std::unordered_map<std::wstring, Wide::Lexer::TokenType> result;
// RESERVED WORD
result[L"namespace"] = Wide::Lexer::TokenType::Namespace;
result[L"for"] = Wide::Lexer::TokenType::For;
result[L"while"] = Wide::Lexer::TokenType::While;
result[L"do"] = Wide::Lexer::TokenType::Do;
result[L"type"] = Wide::Lexer::TokenType::Type;
// PUNCTUATION
result[L"{"] = Wide::Lexer::TokenType::OpenCurlyBracket;
result[L"}"] = Wide::Lexer::TokenType::CloseCurlyBacket;
return result;
}());
if (mapping.find(t.Codepoints) != mapping.end()) {
t.type = mapping.find(t.Codepoints)->second;
return;
}
t.type = Wide::Lexer::TokenType::Identifier; // line 121
});
This iterates through a list of tokens, and judging by the contents of the codepoints, assigns them a value from the associated enum. If it's not found, then give it a value of "Identifier". But this fails to compile.
1>Lexer.cpp(121): error C2065: '__this' : undeclared identifier
1>Lexer.cpp(121): error C2227: left of '->Identifier' must point to class/struct/union/generic type
This is the full error, no warnings, no other errors. What? How can I fix this error?
Edit: I did some significant refactoring, and I've got the exact same problem in a somewhat simpler lambda.
auto end_current_token = [&] {
if (current != Wide::Lexer::Token()) {
current.type = Wide::Lexer::TokenType::Identifier; // error line
if (reserved_words.find(current.Codepoints) != reserved_words.end())
current.type = reserved_words.find(current.Codepoints)->second;
if (punctuation.find(current.Codepoints[0]) != punctuation.end())
current.type = punctuation.find(current.Codepoints[0])->second;
tokens.push_back(current);
current = Wide::Lexer::Token();
}
};
I've cleaned and rebuilt the project.
I fixed the problem.
auto end_current_token = [&] {
if (current != Wide::Lexer::Token()) {
// WORKAROUND compiler bug- dead code
struct bug_workaround_type {
int Identifier;
};
bug_workaround_type bug;
bug_workaround_type* __this = &bug;
current.type = Wide::Lexer::TokenType::Identifier;
if (reserved_words.find(current.Codepoints) != reserved_words.end())
current.type = reserved_words.find(current.Codepoints)->second;
if (punctuation.find(current.Codepoints[0]) != punctuation.end())
current.type = punctuation.find(current.Codepoints[0])->second;
tokens.push_back(current);
current = Wide::Lexer::Token();
}
};
No, really. Now it compiles and runs just fine.
FWIW I tried to concoct a minimal working sample in order to compile on VS2010 and compiled the following without error.
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
namespace Wide { namespace Lexer {
enum TokenType
{
OpenCurlyBracket,
CloseCurlyBacket,
Namespace,
For,
While,
Do,
Type,
Identifier,
};
} }
struct Token
{
std::wstring Codepoints;
Wide::Lexer::TokenType type;
};
int main()
{
std::vector<Token> tokens;
std::for_each(tokens.begin(), tokens.end(), [&](Token& t) {
static const std::unordered_map<std::wstring, Wide::Lexer::TokenType> mapping([]() -> std::unordered_map<std::wstring, Wide::Lexer::TokenType>
{
// Maps strings to TokenType enumerated values
std::unordered_map<std::wstring, Wide::Lexer::TokenType> result;
// RESERVED WORD
result[L"namespace"] = Wide::Lexer::TokenType::Namespace;
result[L"for"] = Wide::Lexer::TokenType::For;
result[L"while"] = Wide::Lexer::TokenType::While;
result[L"do"] = Wide::Lexer::TokenType::Do;
result[L"type"] = Wide::Lexer::TokenType::Type;
// PUNCTUATION
result[L"{"] = Wide::Lexer::TokenType::OpenCurlyBracket;
result[L"}"] = Wide::Lexer::TokenType::CloseCurlyBacket;
return result;
}());
if (mapping.find(t.Codepoints) != mapping.end()) {
t.type = mapping.find(t.Codepoints)->second;
return;
}
t.type = Wide::Lexer::TokenType::Identifier; // line 121
});
}
Could you bisect the minimum edit that show the problem, starting from this code?
I've got the same problem right now. I used other types, but for your case it will be like this:
auto end_current_token = [&] {
using Wide::Lexer::TokenType; // <-- this line solves problem
if (current != Wide::Lexer::Token()) {
current.type = Wide::Lexer::TokenType::Identifier;
Now it compiles well.

strange string error

program:
CCompussGradientOperator dlg;
string p = "preqitt";
string k = "Kirnch";
string r3 = "Robison";
f(dlg.DoModal() == IDOK)
{
CDib dib = m_Dib;
BOOL ret = FALSE;
if(dlg.m_Combo_Operators == p )
{
switch(dlg.m_nFunction)
{
case 0: ret ;
}
}
}
error:
Error 18 error C2065: 'string' : undeclared identifier d:\2nd\imagetool\imagetooldoc.cpp 870 1 ImageTool
string is a data type then why it does make me error.. its strange for me...
any one can help me ..thanks
Have you included <string> header ? Also it is in namespace std.
Change string to std::string. Also, do you have #include <string> at the top of the source file?