douzhan1963 2014-10-09 22:25
浏览 67
已采纳

从字母数字字符串中删除小数并保留零

I'm returning orders on my success page in magento. The problem is on my quantity (QTY) variable it returns like QTY 2.0000

I've tried several things like $itemQTY_str + 0 which i think is only good for non alphanumeric strings. Additionally, I've tried (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&amp;' . $itemSKU_str . $itemAMT_str . (float)$itemQTY_str . 'CID=1527930&amp;OID=' . $this->getOrderId() . '&amp;TYPE=362236&amp;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&amp;' . $itemSKU_str . $itemAMT_str . $itemQTY_str . 'CID=1527930&amp;OID=' . $this->getOrderId() . '&amp;TYPE=362235&amp;CURRENCY=USD" name="cj_conversion"></iframe>
            ';
        }
    }
}

it returns:

<iframe height="1" width="1" frameborder="0" scrolling="no" src="https://www.emjcd.com/tags/c?containerTagId=4813&amp;ITEM1=59444-no-subscription&amp;ITEM2=793573106964-one-time&amp;AMT1=37.0000&amp;AMT2=65.0000&amp;QTY1=2.0000&amp;QTY2=3.0000&amp;CID=1527930&amp;OID=100000928&amp;TYPE=362236&amp;CURRENCY=USD" name="cj_conversion"></iframe>


QTY1=2.0000&amp;QTY2=3.0000

Ultimate goal:

QTY1=2&amp;QTY2=3.

I've also tried editing the string directly..

$itemQTY_str = $itemQTY_str . 'QTY'. $i . + 0 '=' . $order_item->getQtyOrdered() . '&';

$itemQTY_str = $itemQTY_str . 'QTY'. $i . '=' . $order_item->getQtyOrdered(). + 0 . '&';

Hopefully that's clear.. help would be highly appreciated.

Thank you.

  • 写回答

1条回答 默认 最新

  • dongshipang8094 2014-10-09 22:33
    关注

    Cast the value as an integer.

    $itemQTY_str = $itemQTY_str . 'QTY'. $i . '=' . (int)$order_item->getQtyOrdered() . '&';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?