I am trying to solve this missing feature for virtuemart. The default joomla search or the virtuemart search modules do not look into custom fields of the products.
I did try to change the plugin for search as follows:
$wheres = array();
switch ($phrase) {
case 'exact':
$text = $db->Quote ('%' . $db->getEscaped ($text, TRUE) . '%', FALSE);
$wheres2 = array();
$wheres2[] = 'p.product_sku LIKE ' . $text;
$wheres2[] = 'a.product_name LIKE ' . $text;
$wheres2[] = 'a.product_s_desc LIKE ' . $text;
$wheres2[] = 'a.product_desc LIKE ' . $text;
$wheres2[] = 'b.category_name LIKE ' . $text;
$wheres2[] = '#__virtuemart_product_customfields.custom_value LIKE ' . $text;
$where = '(' . implode (') OR (', $wheres2) . ')';
break;
case 'all':
case 'any':
default:
$words = explode (' ', $text);
$wheres = array();
foreach ($words as $word) {
$word = $db->Quote ('%' . $db->getEscaped ($word, TRUE) . '%', FALSE);
$wheres2 = array();
$wheres2[] = 'p.product_sku LIKE ' . $word;
$wheres2[] = 'a.product_name LIKE ' . $word;
$wheres2[] = 'a.product_s_desc LIKE ' . $word;
$wheres2[] = 'a.product_desc LIKE ' . $word;
$wheres2[] = 'b.category_name LIKE ' . $word;
$wheres2[] = '#__virtuemart_product_customfields.custom_value LIKE ' . $word;
$wheres[] = implode (' OR ', $wheres2);
}
$where = '(' . implode (($phrase == 'all' ? ') AND (' : ') OR ('), $wheres) . ')';
break;
}
The #__virtuemart_product_customfields has a shortname pf i think too.
Any insight?
Related
I tried to create a new log file if there is a phpmailer error. But the file is not created. I check my directory (777).
Do you have an idea ?
Thank you
if (DEBUG_EMAIL == 'true'){
$this->phpMail->SMTPDebug = $this->debug_level; //2
$this->phpMail->Debugoutput = function($str, $level) {
$filename = CLICSHOPPING::BASE_DIR . 'Work/Log/phpmail_error-' . date('Ymd') . '.log';
$data = date('Y-m-d H:i:s') . "\t" . "\t$level\t$str\n";
$flags = FILE_APPEND | LOCK_EX;
file_put_contents($filename, $data, $flags);
};
// $this->phpMail->SMTPDebug = SMTP::DEBUG_SERVER;
}
Double check all your values, don't assume they are what you think they are. For example what is in CLICSHOPPING::BASE_DIR? Also, it's usual for directory env vars to not have a trailing slash, so you may be missing one when you append Work/... to it. Try this:
$filename = CLICSHOPPING::BASE_DIR . '/Work/Log/phpmail_error-' . date('Ymd') . '.log';
$data = date('Y-m-d H:i:s') . "\t" . "\t$level\t$str\n";
I'm trying to implement a Perl function for creating SAS tokens. Doing all according to documentation (https://learn.microsoft.com/en-us/rest/api/storageservices/create-service-sas) I always get error "Signature fields not well formed".
My testing resource is "https://ribdkstoragepoc.blob.core.windows.net/project-poc/foo/koteyka.jpg". Variables populated by my code:
signedpermissions = 'r'
signedexpiry = '2020-05-01T07:59:00Z'
canonicalizedresource = '/blob/ribdkstoragepoc/project-poc/foo/koteyka.jpg'
signedresource = 'b'
signedversion = '2018-03-28'
Other variables are just empty lines. I generate a string using the following pattern:
my $stringToSign =
$permissions . "\n" .
$start . "\n" .
$expiry . "\n" .
$canonicalizedResource . "\n" .
$identifier . "\n" .
$IP . "\n" .
$protocol . "\n" .
$version . "\n" .
$resource . "\n" .
$snapshotTime . "\n" .
$rscc . "\n" .
$rscd . "\n" .
$rsce . "\n" .
$rscl . "\n" .
$rsct;
The string to sign:
r
2020-05-01T07:59:00Z
/blob/ribdkstoragepoc/project-poc/foo/koteyka.jpg
2018-03-28
b
Calculationg of signature: my $sig = Digest::SHA::hmac_sha256_base64($stringToSign, $key);
At last the final URL looks like: https://ribdkstoragepoc.blob.core.windows.net/project-poc/foo/koteyka.jpg?sig=YcwWvOT2FtOZGbXQxMAoSxvA2HhRmMAUp%2B6WUY%2Bjbjg&sv=2018-03-28&se=2020-05-01T07%3A59%3A00Z&sr=b&sp=r
As I have already said that does not work. Does anyone have ideas what could be wrong?
Figured out what's wrong with your code. Basically you're using 2018-03-28 version of Storage REST API so you don't need to include $resource and $snapshotTime in your $stringToSign.
Furthermore, you will need to pad your signature with 1-4 = (Ref: https://github.com/smarx/waz-storage-perl/blob/master/WindowsAzure/Storage.pm#L42).
Based on these, here's the code:
use strict;
use warnings;
use Digest::SHA qw(hmac_sha256_base64);
use MIME::Base64;
my $permissions = 'r';
my $start = '';
my $expiry = '2020-01-31T00:00:00Z';
my $canonicalizedResource = '/blob/ribdkstoragepoc/project-poc/foo/koteyka.jpg';
my $identifier = '';
#my $resource = 'b';
my $IP = '';
my $version = '2018-03-28';
my $protocol = '';
#my $snapshotTime = '';
my $rscc = '';
my $rscd = '';
my $rsce = '';
my $rscl = '';
my $rsct = '';
my $stringToSign = $permissions . "\n" . $start . "\n" . $expiry . "\n" . $canonicalizedResource . "\n" . $identifier . "\n" . $IP . "\n" . $protocol . "\n" . $version . "\n" . $rscc . "\n" . $rscd . "\n" . $rsce . "\n" . $rscl . "\n" . $rsct;
print $stringToSign;
my $accountKey = 'your-base64-account-key';
my $sig = Digest::SHA::hmac_sha256_base64($stringToSign, decode_base64($accountKey));
$sig .= '=' x (4 - (length($sig) % 4));
print "\n---------------------\n";
print $sig;
print "\n";
Give this a try, it should work.
How do I convert $var = "000000000" to $var = "0_0000_0000" in Perl ?
If the string is always 9 characters long, you can just use substr:
my $var = '000000000';
substr($var, 5, 0) = '_';
substr($var, 1, 0) = '_';
For formatting strings of arbitrary length you could use a function like this:
sub format_str {
my $str = reverse $_[0];
$str =~ s/(.{4})(?=.)/$1_/g;
return scalar reverse $str;
}
my $var = "000000000";
print format_str $var; # "0_0000_0000"
$var = "000000000";
$var2 = substr($var,0,1)."_".substr($var,1,4)."_".substr($var,5);
print $var2;
Assuming you're asking how to insert a _ after the first and fifth characters of a string, the following are a variety of straightforward solutions:
my $in = '000000000';
my $out = substr($var,0,1) . '_' . substr($var,1,4) . '_' . substr($var,5);
my $in = '000000000';
my $out = join('_', substr($var,0,1), substr($var,1,4), substr($var,5));
my $in = '000000000';
my $out = join('_', unpack('a1 a4 a4*', $in));
my $in = '000000000';
my $out = $in =~ s/^(.)(.{4})/${1}_${2}_/sr; # 5.14+
my $in = '000000000';
( my $out = $in ) =~ s/^(.)(.{4})/${1}_${2}_/s;
In-place:
my $var = '000000000';
$var =~ s/^(.)(.{4})/${1}_${2}_/s;
my $var = '000000000';
substr($var, 5, 0) = '_';
substr($var, 1, 0) = '_';
For a solution for any-length string and considering efficiency issues that arise for very-long strings, please see my previous question&answer: How to chunk text "from the back" in perl.
Per suggestion in comment, here is code using the idea in the linked question/answer which answers the OP question:
use integer;
my $la = length($var);
my $r = $la % 4;
my $q = $la / 4;
my $tr = $r ? "a$r" : "";
$var = join "_", unpack "$tr(a4)$q", $var;
Note: change all three 4s for a different grouping size.
If this is a commify problem that is solved in "How can I output my numbers with commas added?", available as perldoc -q 'commas added', then a similar solution will suffice, with extra parameters to define the separator and the size of the interval
You will want to read the perlfaq entry for other alternatives
use strict;
use warnings 'all';
print group_characters(1234567), "\n";
print group_characters('000000000', '_', 4), "\n";
print group_characters('0123456789ABCDEF', ' ', 4), "\n";
sub group_characters {
my ($s, $sep, $n) = #_;
$sep //= ',';
$n //= 3;
1 while $s =~ s/[^$sep]+\K(?=[^$sep]{$n})/$sep/;
$s;
}
output
1,234,567
0_0000_0000
0123 4567 89AB CDEF
What is the proper way to concatenate several scalar values into one Perl string?
The following code is deliberately a series of statements for debugging reasons.
my $bill_record;
$bill_record = $acct_no . " |";
$bill_record = $bill_record . defined($w_ptWtrMtrRecRef->{"mtr_addr_no"}) ? $w_ptWtrMtrRecRef->{"mtr_addr_no"} : " " . " |" ;
$bill_record = $bill_record . defined($w_ptWtrMtrRecRef->{"mtr_addr_str"}) ? $w_ptWtrMtrRecRef->{"mtr_addr_str"} : " " . " |" ;
$bill_record = $bill_record . defined($w_ptWtrMtrRecRef->{"mtr_addr_apt"}) ? $w_ptWtrMtrRecRef->{"mtr_addr_apt"} : " " . " |" ;
$bill_record = $bill_record . $issue_date . " |";
The | character is serving as a delimiter. Each line will be '\n terminated.
After the last line $bill_record = $bill_record . $issue_date . " |";
This error appears:
Use of uninitialized value $bill_record in concatenation (.) or string at /home/ics/include/WsBillFunc.pm line 1022.
at /home/ics/include/WsBillFunc.pm line 1022
$issue_date is defined when assigned.
What could be causing $bill_record to become undefined, and what is the proper way to concatenate a bunch of scalar values into one string?
I don't know specifically why $bill_record is undefined. But if I understand what you're trying to do, you're running into a precedence problem: the ?: operator has lower precedence than concatenation ., so that
$bill_record = $bill_record . defined($w_ptWtrMtrRecRef->{"mtr_addr_no"}) ? $w_ptWtrMtrRecRef->{"mtr_addr_no"} : " " . " |" ;
is treated as
$bill_record = ($bill_record . defined($w_ptWtrMtrRecRef->{"mtr_addr_no"})) ? $w_ptWtrMtrRecRef->{"mtr_addr_no"} : (" " . " |") ;
which I suspect is not what you want. Try adding parentheses:
$bill_record = $bill_record . (defined($w_ptWtrMtrRecRef->{"mtr_addr_no"}) ? $w_ptWtrMtrRecRef->{"mtr_addr_no"} : " ") . " |" ;
(Or use .= as another commenter suggested.)
I'd probably do that in one statement with a join:
$bill_record = join ' |',
map( {
defined( $_ ) ? $_ : ' '
} #{ $w_ptWtrMtrRecRef }{ qw( mtr_addr_no mtr_addr_str mtr_addr_apt ) }
),
$issue_date,
'';
In the map I limit with parens because I only want to apply it to the hash slice. After that is the $issue_date and the empty string. That empty string gets the final | you have.
But, for your problem, it looks like you have a precedence problem. One way to see this is to ask Perl to compile then deparse your program to see what it thinks you wanted. The B::Deparse module does this and I use the -p argument to add extra parentheses.
Here's a cut down version of your original program with the added call to the deparser at the top (it's the B::Deparse module but the namespace is O:
#!/usr/bin/perl
use O qw(Deparse -p);
my $b;
$b = $acct_no . " |";
$b = $b . defined($w->{"no"}) ? $w->{"no"} : " " . " |" ;
$b = $b . defined($w->{"str"}) ? $w->{"str"} : " " . " |" ;
$b = $b . defined($w->{"apt"}) ? $w->{"apt"} : " " . " |" ;
$b = $b . $issue_date . " |";
It outputs:
my($b);
($b = ($acct_no . ' |'));
($b = (($b . defined($$w{'no'})) ? $$w{'no'} : ' |'));
($b = (($b . defined($$w{'str'})) ? $$w{'str'} : ' |'));
($b = (($b . defined($$w{'apt'})) ? $$w{'apt'} : ' |'));
($b = (($b . $issue_date) . ' |'));
The key part is the (($b . defined($$w{'no'})). The current value of $b is concatenated with the return value of defined, then the conditional operator (? :) is done. If the test value is true, it returns the first value in the conditional.
When it gets to mgr_apt_no, there are probably many records that don't have that value set. However, the combined value of the previous $b and $$w{'apt'} is defined because $b is not empty. Thus, it chooses the value of $$w{'apt'} to assign to $b. When it does the last line, $b is empty for the concatenation with $issue_date.
Using Cakephp, I am reading from an Excel sheet (I'm using Libre Office) and the date is not converted properly.
I'm using PHP spreadsheet excel reader to import the excel sheet into the database.
I'm not using any functions to convert the date given in the excel sheet.
In the excel sheet the date which I have given like this 04/10/2013 is converted to this format (AprApr/WedWed/2013201320132013). I want the exact date which I have given in the excel sheet.
I'm adding my code also here:
$excel = new Spreadsheet_Excel_Reader(WWW_ROOT . 'files/excel/' . $this->request->data['Request']['file_name'], true);
$excel->setUTFEncoder('iconv');
$excel->setOutputEncoding('UTF-8');
$excel->read(WWW_ROOT . 'files/excel/' . $this->request->data['Request']['file_name']);
$x = 2;
$sep = ",";
ob_start();
while ($x <= $excel->sheets[0]['numRows']) {
$y = 1;
$row = "";
while ($y <= $excel->sheets[0]['numCols']) {
echo $excel->sheets[0]['cells'][$x][4];
$cell = isset($excel->sheets[0]['cells'][$x][$y]) ? $excel->sheets[0]['cells'][$x][$y] : '';
$row.=($row == "") ? "\"" . $cell . "\"" : "" . $sep . "\"" . $cell . "\"";
$y++;
}
echo $row . "\n";
$x++;
}
$fp = fopen(WWW_ROOT . "files/excel/data.csv", 'w');
fwrite($fp, ob_get_contents());
fclose($fp);
ob_end_clean();
$filehandle = fopen(WWW_ROOT . "files/excel/data.csv", "r");
fgetcsv($filehandle, 1000, ",");
while (($data = fgetcsv($filehandle, ",")) !== FALSE) {
pr($data);
}
Please help!!! Thanks in advance