我在magento的成功页面上返回订单。问题在于我的数量(QTY)变量,它返回如QTY 2.0000
我尝试了一些像$itemQTY_str + 0
这样的东西,我认为它只适用于非字母数字字符串。此外,我已尝试(floatval)$itemQTY_str
$order=Mage::getModel('sales/order')->getCollection()->addFieldToFilter('increment_id',$this->getOrderId());
$order=$order->getFirstItem();
$order_items=$order->getAllVisibleItems();
$productIds=array();
$itemSKU_str = $itemAMT_str = $itemQTY_str = '';
$i = 1;
foreach($order_items as $order_item) {
$_product=Mage::getModel('catalog/product')->load($order_item->getProductId());
if($_product->getData('fb_pinterest_share')) {
$productIds[]=$order_item->getProductId();
}
if($_SERVER['REMOTE_ADDR'] == '00.00.00.000'){
$itemSKU_str = $itemSKU_str . 'ITEM'. $i . '=' . $order_item->getSku() . '&';
$itemAMT_str = $itemAMT_str . 'AMT'. $i . '=' . $order_item->getPrice() . '&';
$itemQTY_str = $itemQTY_str . 'QTY'. $i . '=' . $order_item->getQtyOrdered() . '&';
}
$i++;
}
/* COMMISSION JUNCTION TRACKING CODE - START */
if($_SERVER['REMOTE_ADDR'] == '00.00.00.000'){
$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$con = mysqli_connect('localhost', '******', '*******', '*******');
if (mysqli_connect_errno()){
//echo 'Failed to connect to MySQL: ' . mysqli_connect_error();
}else{
$result = mysqli_query($con, "
SELECT customer_id
FROM sales_flat_order
WHERE status = 'complete'
AND customer_email LIKE '" . $order->getCustomerEmail() . "'
");
if(mysqli_num_rows($result) > 0){
//returning customer
echo '
<iframe height="1" width="1" frameborder="0" scrolling="no" src="https://www.emjcd.com/tags/c?containerTagId=4813&' . $itemSKU_str . $itemAMT_str . (float)$itemQTY_str . 'CID=1527930&OID=' . $this->getOrderId() . '&TYPE=362236&CURRENCY=USD" name="cj_conversion"></iframe>
';
}else{
//new customer
echo '
<iframe height="1" width="1" frameborder="0" scrolling="no" src="https://www.emjcd.com/tags/c?containerTagId=4812&' . $itemSKU_str . $itemAMT_str . $itemQTY_str . 'CID=1527930&OID=' . $this->getOrderId() . '&TYPE=362235&CURRENCY=USD" name="cj_conversion"></iframe>
';
}
}
}
它返回:
<iframe height="1" width="1" frameborder="0" scrolling="no" src="https://www.emjcd.com/tags/c?containerTagId=4813&ITEM1=59444-no-subscription&ITEM2=793573106964-one-time&AMT1=37.0000&AMT2=65.0000&QTY1=2.0000&QTY2=3.0000&CID=1527930&OID=100000928&TYPE=362236&CURRENCY=USD" name="cj_conversion"></iframe>
QTY1=2.0000&QTY2=3.0000
终极目标:
QTY1=2&QTY2=3.
我也尝试过直接编辑字符串..
$itemQTY_str = $itemQTY_str . 'QTY'. $i . + 0 '=' . $order_item->getQtyOrdered() . '&';
$itemQTY_str = $itemQTY_str . 'QTY'. $i . '=' . $order_item->getQtyOrdered(). + 0 . '&';
希望明确的帮助将受到高度赞赏。
谢谢。
答案 0 :(得分:0)
将值转换为整数。
$itemQTY_str = $itemQTY_str . 'QTY'. $i . '=' . (int)$order_item->getQtyOrdered() . '&';