Let me start by saying I am NOT a programmer. I'm a retail web manager that knows enough about HTML5 to understand what is going on. Ok now on to my issue. We recently upgraded our eCommerce platform from 3DCart to Magento. It's a completely different monster and I'm fairly lost. I'm trying to integrate Magento's simple pixel (just returns the total not the individual items) into our confirmation page but all of our tests are failing. I've tried bits and pieces of other codes that I've found around the web but I'm still missing the "amount" parameter. Can anyone help me? Below is what we have on our site now (please note this is part of the copy/paste code I've found):
//-------------------------------------------
// START CJ CONVERSION TRACKING PIXEL
//-------------------------------------------
$cjmerchID = '1521251';
$cjaid = '382643';
$cjorder = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
$cjitems = $cjorder->getAllItems();
$cjorderID = $cjorder->getIncrementId();
//$cjsubtotal = round($cjorder->getSubtotal(), 2);
$i = 1;
foreach ($cjitems as $itemId => $item)
{
$unitPrice = round($item->getPrice(), 2);
$sku = $item->getSku();
$qty = $item->getQtyToInvoice();
//echo $qty . '<br>';
$itemsStr .= '&ITEM;' . $i . '=' . $sku . '&AMT;' . $i . '=' . $unitPrice . '&QTY;' . $i . '=' . $qty . '';
$i++;
}
?>
?<img src="https://www.emjcd.com/u?CID=<?php echo $cjmerchID; ?>&OID;=<?php echo $cjorderID; ?>&TYPE;=<?php echo $cjaid; ?><?php echo $itemsStr; ?>&CURRENCY;=USD&METHOD;=IMG" height="1" width="20">
<?php
//-------------------------------------------
// END CJ CONVERSION TRACKING PIXEL
//-------------------------------------------
According to CJ this is what I'm doing wrong:
Thank you for providing the results of your test. I am seeing the pixel calls on our server. However, both tests failed as the incorrect Action ID is being used and the 'AMOUNT' parameter has no associated value and is being passed back blank. I've attached the integration instructions for your convenience.
The Action ID for the simple action that should be integrated to replace the existing pixel is 382643.
Integration Test
Advertiser: 3448671
Ad: 12313358
Action Id: 346589
Action Type: item_sale
Query String: AMOUNT=&OID=100056687&CID=1521251&CURRENCY=USD&METHOD=IMG&TYPE=346589
Sid: TrackingTest
Surfer: 476602316150531682:VJXkXAhFHzU2 Click Ref:
Action Status: active
img src="https://www.emjcd.com/u?AMOUNT=&CID=1521251&OID=100056687&TYPE=346589&CURRENCY=USD&METHOD=IMG" height="1" width="20"
Please update the pixel to pull in the subtotal (pre-taxed amount of purchase) and to have 'TYPE' populated with 382643.
Any help you can give would me most appreciated!
Diana
See if this code works. what i did is get the subtotal of total checkout order and append a new parameter in img href with AMOUNT. Let me know how the results work out
//-------------------------------------------
// START CJ CONVERSION TRACKING PIXEL
//-------------------------------------------
$cjmerchID = '1521251';
$cjaid = '382643';
$cjorder = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
$cjitems = $cjorder->getAllItems();
$cjorderID = $cjorder->getIncrementId();
//New Codee
$totals = Mage::getSingleton('checkout/cart')->getQuote()->getTotals();
$subtotal = $totals["subtotal"]->getValue();
//$cjsubtotal = round($cjorder->getSubtotal(), 2);
$i = 1;
foreach ($cjitems as $itemId => $item)
{
$unitPrice = round($item->getPrice(), 2);
$sku = $item->getSku();
$qty = $item->getQtyToInvoice();
//echo $qty . '<br>';
$itemsStr .= '&ITEM;' . $i . '=' . $sku . '&AMT;' . $i . '=' . $unitPrice . '&QTY;' . $i . '=' . $qty . '';
$i++;
}
?>
?<img src="https://www.emjcd.com/u?CID=<?php echo $cjmerchID; ?>&OID;=<?php echo $cjorderID; ?>&TYPE;=<?php echo $cjaid; ?>&AMOUNT;=<?php echo $subtotal; ?><?php echo $itemsStr; ?>&CURRENCY;=USD&METHOD;=IMG" height="1" width="20">
<?php
//-------------------------------------------
// END CJ CONVERSION TRACKING PIXEL
//-------------------------------------------
Related
I trying to generate random transaction_id, with format "2000-yymmm-0000".
I already know how to set the transaction_id, but I have a problem with the auto-increment from "2000-yymm-0000" to "2000-yymm-0001", and reseting automatically to "2000-yymm-0000" at every new month.
I put this logic in different path of controller.
PS: I'm using Lumen 6.0 with Laravel 6.0.
I'm trying to create the increment with:
$number = sprintf('%04d', 0000);
$number++;
but it didn't work.
$year = 2000;
$time = date('ym');
$number = sprintf('%04d', 0000);
$transaction_id = $year . '-' . $time . '-' . $number;
$transaction_data = explode('-', $transaction_id);
$month = date("m", strtotime($transaction_data[0]));
I expect the result to automatically increment every time a new data is stored to the database. But the actual result is transaction_id being having always the same value 2000-yymm-0000.
What am I doing wrong?
I know it's weird to answer my own question, but i already find the solution.
in Models/Order.php
i create a function like this.
public function count()
{
$this->where(transaction_id)->count();
}
after that i call the function from Model/Order.php to OrdersController.php
public function create(Request $request)
{
$year = 2000;
$date = date('ym');
$total_data = $this->table->count();
$number = str_pad($total_data + 1, 4, 0, STR_PAD_LEFT);
$transaction_id = $year . '-' . $date . '-' . $number;
return $this->success('count all transaction id', $t_id);
}
$C = $_POST['Cc'];
$X = $_POST['X'];
$CX = $_POST['Cc'] . $_POST['X'];
$NC = preg_replace_callback("/x/" ,function() {return rand(0,9);}, $CX);
$New = $NC ;
$NNew = str_repeat($New,10);
echo $NNew;
what's wrong when i output it , it gives me the same number How to make It Don't Give me the same Numbers ??
It's basically you are not changing the seed for the rand method. Each time it's getting same seed and generating same number.
Read this PHP manual : http://php.net/manual/en/function.srand.php
Check the code snippet below:
<?php
// seed with microseconds
function make_seed()
{
list($usec, $sec) = explode(' ', microtime());
return $sec + $usec * 1000000;
}
srand(make_seed());
$randval = rand(0,9);
echo $randval;
?>
Or you can use mt_rand() which is seeded differently on each execution.
I'm trying to access the contents of a K2 extra field inside the BT content slider plugin. If I do
print_r($row->extra_fields);
I get
[{"id":"16","value":"http:\/\/www.youblisher.com\/p\/611670-Test-Intro-to-R\/"}]
I need to access the value, but I've tried everything I could think of with no luck.
Tests I've done (also tried print_r for everything just in case):
echo $row->extra_fields[0]
echo $row->extra_fields[0]->value
echo $row->extra_fields->value
echo $row->extra_fields["value"]
Decode your string into a json object first before trying to access value.
<?php
$json = json_decode('[{"id":"16","value":"http:\/\/www.youblisher.com\/p\/611670-Test- Intro-to-R\/"}]');
print_r($json[0]->value);
?>
OK, I got it working the way I wanted it to.
I wanted to replace intro / full text with an extrafield that I called 'Accroche' . This extrafield has an ID of 132 (useful to know the ID that will be used in code below).
We will be editing 2 files :
/modules/mod_bt_contentslider/classes/content.php
and
/modules/mod_bt_contentslider/classes/k2.php
First thing to do is get the extrafield info from database :
in /modules/mod_bt_contentslider/classes/content.php (around line 77) I added [b]a.extra_fields,[/b] as follows
$model->setState('list.select', 'a.urls, a.images, a.fulltext, a.id, a.title, a.alias, a.introtext, a.extra_fields, a.state, a.catid, a.created, a.created_by, a.created_by_alias,' . ' a.modified, a.modified_by,a.publish_up, a.publish_down, a.attribs, a.metadata, a.metakey, a.metadesc, a.access,' . ' a.hits, a.featured,' . ' LENGTH(a.fulltext) AS readmore');
Save file & close
Now lets get to /modules/mod_bt_contentslider/classes/k2.php (around line 234),
Replace this original code
// cut introtext
if ($limitDescriptionBy == 'word') {
$item->description = self::substrword($item->introtext, $maxDesciption, $replacer, $isStrips, $stringtags);
$item->description = self::substring($item->introtext, $maxDesciption, $replacer, $isStrips, $stringtags);
}
$item->categoryLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item->catid . ':' . urlencode($item->categoryalias))));
// get author name & link
With this code that I've commented to make things understandable for noobs like me ;)
// REPLACE intro/full text With extra-field info
$extras = json_decode($item->extra_fields); // JSON Array we'll call extras (note final 's' : not to confuse with below variable)
foreach ($extras as $key=>$extraField): //Get values from array
if($extraField->value != ''): //If not empty
if($extraField->id == '132'): // This is ID value for extrafield I want to show --- Search your K2 extrafield's id in Joomla backoffice ->K2 ->extrafields ---
if($extraField->value != ''): // If there's content in the extrafield of that ID
$extra = $extraField->value; //Give $extra that value so we can hand it down below
endif;
endif;
endif;
endforeach;
// cut introtext
if ($limitDescriptionBy == 'word') {
// $item->description = self::substrword($item->introtext, $maxDesciption, $replacer, $isStrips, $stringtags);
$item->description = self::substrword($extra, $maxDesciption, $replacer, $isStrips, $stringtags);
} else {
// $item->description = self::substring($item->introtext, $maxDesciption, $replacer, $isStrips, $stringtags);
$item->description = self::substring($extra, $maxDesciption, $replacer, $isStrips, $stringtags) ;
}
$item->categoryLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item->catid . ':' . urlencode($item->categoryalias))));
// get author name & link
As you can see, I've commented out the intro texts as I don't want them. You can modify that if you want both introtext AND extrafield.
I'd have never figured this out without the JSON tip given above. Thanx to all :)
Hope this helps.
Cheers !
I know this issue has been discussed in different questions but the answers people have given don't seem to work on my end. I'm dealing with the following problem:
if ( (preg_match($suspect, $lowmsg) )
|| (preg_match($suspect, strtolower($_POST['name'])))
|| (preg_match($suspect, strtolower($_POST['email']))))
Now, people have been saying that if I put "/" in front and behind quotes like so '/email/' that this would solve the problem. I tried putting the / for email and name but it still brought me back to the same delimiter error.
I also get a final error of: Warning: Cannot modify header information - headers already sent by (my website's send.php:43) on line 61. Does this have anything to do with it or is this just an error as a result of the earlier error?
Here's the entire code for interested parties:
<?php
if(($_POST['email']=="")||($_POST['name']=="")||($_POST['message']==""))
{
echo "<html><body><p>The following fields are <strong>required</strong>.</p><ul>";
if($_POST['name'] == ""){ echo "<li>Name</li>"; }
if($_POST['email'] == ""){ echo "<li>Email</li>"; }
if($_POST['message'] == ""){ echo "<li>Message</li>"; }
echo "</ul><p>Please use your browser's back button to complete the form.</p></body></html>";
}
else
{
$message = "";
$message .= "Name: " . htmlspecialchars($_POST['name'], ENT_QUOTES) . "<br>\n";
$message .= "Email: " . htmlspecialchars($_POST['email'], ENT_QUOTES) . "<br>\n";
$message .= "Message: " . htmlspecialchars($_POST['message'], ENT_QUOTES) . "<br>\n";
$subject = htmlspecialchars($_POST['subject'], ENT_QUOTES);
$pagelink = htmlspecialchars($_POST['pagelink'], ENT_QUOTES);
$repemail = htmlspecialchars($_POST['repemail'], ENT_QUOTES);
$injection_strings = array ( "content-type:","charset=","mime-version:","multipart/mixed","bcc:","cc:");
foreach($injection_strings as $suspect)
{
if((preg_match($suspect, $lowmsg)) || (preg_match($suspect, strtolower($_POST['/name/']))) || (preg_match($suspect, strtolower($_POST['/email/']))))
{
die ( 'Illegal Input. Go back and try again. Your message has not been sent.' );
}
}
$headers = "MIME-Version: 1.0\r\nContent-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: \"" . $_POST['/name/'] . "\" <" . $_POST['/email/'] . ">\r\n";
$headers .= "Reply-To: " . $_POST['/email/'] . "\r\n\r\n";
mail($repemail, $subject, $message, $headers);
header("Location: " . $pagelink . "");
}
?>
You can try other delimiters, such as / # ~
see regexp.reference.delimiters
Hope that helps.
EDIT: you do not need to do backslash inside $_POST
Use $_POST['name'] instead of $_POST['/name/']
EDIT: try
preg_match("/".$suspect."/i", strtolower($_POST['name']);
However, I dont think you would find any of your $injection_strings inside post name. You may need to rethink how you are searching. "content_type" is not going to match "text/html" with your current statement. You'd need to try other regex like
preg_match("/".$suspect."(.*)/i", strtolower($_POST['name'], $output);
So that it would $output[0], your "suspect" variable. I'm not sure if thats what you are looking for, but maybe sending you to the right track.
EDIT: Here.
If you want to look at say "cc:" and find what email it is, use this.
preg_match("/cc:(.*)/i",'cc:'.$_POST['email'],$output);
$output[0]; would equal your email.
To be compatible with your foreach loop, you may want to change it too,
switch this below code within your "if statements"
preg_match("/".$suspect."(.*)/i",$suspect.$_POST['email'])
I making a webadmin system and I want to monitor the CPU and RAM usage of a process in PHP
Can anyone help me?
"Counters and Logs to Monitor" => http://support.microsoft.com/kb/300504
Save as CSV and read it() by PHP
[OR]
http://pecl.php.net/package/win32ps
[OR]
Use WMI:
<?PHP
#error_reporting(1);
$wmi = new COM("WinMgmts:{impersonationLevel=impersonate}") ;
$cpus = $wmi->ExecQuery("SELECT LoadPercentage FROM Win32_Processor");
foreach ($cpus as $cpu) :
echo $cpu->LoadPercentage . '%';
endforeach;
?>
Use this it works perfectly. Combine this with AJAX and a JAVASCRIPT timer so you get every xy seconds the usage of your cpu&ram.
function get_server_cpu_usage(){
$load = sys_getloadavg();
return $load[0];
}
function get_server_memory_usage(){
$free = shell_exec('free');
$free = (string)trim($free);
$free_arr = explode("\n", $free);
$mem = explode(" ", $free_arr[1]);
$mem = array_filter($mem);
$mem = array_merge($mem);
$memory_usage = $mem[2]/$mem[1]*100;
return $memory_usage;
}
echo '<h4>Server Memory usage: ' . number_format(get_server_memory_usage(), 2) . '%</h4><span style="width:' . get_server_memory_usage() . '%"></span<br>
<h4>Server CPU usage: ' . get_server_cpu_usage() . '% </h4><span style="width:' . get_server_cpu_usage() . '%"></span>';