簡體   English   中英

Magento - 函數名稱必須是字符串

[英]Magento - Function name must be a string

我正在嘗試通過向網站添加一些PHP代碼將收入數據傳遞給來自Magento的AdWords,然后使用echo實現跟蹤以將變量傳遞給Javascript。

這是我有的:

<?php
$orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
$order = Mage::getModel('sales/order')->load($orderId);
$total = (float)number_format($order()->getSubtotal(),2);
?>

然后在此之后,我使用PHP echo將$ total轉換為Google轉換跟蹤代碼,如下所示:

    <!-- Google Code for Website Conversions Conversion Page --> <script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 1011076746;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "3B7tCPfZj2YQip2P4gM"; 
if (<?php echo $total?>) {
    var google_conversion_value = <?php echo $total?>;
}
var google_conversion_currency = "USD"; 
var google_remarketing_only = false;
/* ]]> */
</script>
<script type="text/javascript"  
src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt=""  
src="//www.googleadservices.com/pagead/conversion/1011076746/?value=<?php echo $total?>&amp;currency_code=USD&amp;label=3B7tCPfZj2YQip2P4gM&amp;guid=ON&amp;script=0"/>
</div>
</noscript>

但沒有運氣。

它返回一個函數名稱必須是第69行的字符串錯誤。據我所知,第69行是我代碼中的第4行。 我不得不根據客戶的要求刪除它。

有人可以幫忙嗎? 我沒有經驗豐富的PHP來真正診斷這個。

問題:您在代碼中使用$variable作為function myFunction()是錯誤的。

注意:變量和函數是每種編程語言的兩個不同的主要元素,因此最好至少區分這兩種編程語言並且永遠不要錯誤地將這兩種語言相互接合。

解決方案:在以下代碼中的$order之后刪除圓括號() ,您的問題將得到解決。

代碼:

<?php
$orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
$order = Mage::getModel('sales/order')->load($orderId);
$total = (float)number_format($order->getSubtotal(),2);
?>

@Actual Credit轉到@Felippe Duarte

額外課程:

變量可以保存一個函數,即您可以為變量分配一個函數,然后您可以使用該變量立即調用該函數。

例如 :

//It's A Function
function myFunction() {
// Simple Printing The Hello World Text
echo "Hello World";
}
// Assigning The Function To The Variable
$variable = 'myFunction';
//Calling The Variable As A Function
echo $variable();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM