2012-07-26 40 views
1

我們有一個名爲web_availability的屬性代碼,向消費者發送不同形式的產品可用性消息。例如:可用性「80」應在搜索結果和/或產品詳細信息頁面上顯示「僅限於商店」。Magento自定義消息傳遞

<input type="text" class="input-text required-option" value="80" name="option[value][532][0]">

我聲明的變量爲:放置到下列Magento的price.phtml

<?php 
$_shipping_messaging = $_product->getShippingMessaging(); //looks for a value of "0" or "1" to assign either Free Shipping, or Plus Shipping Messaging 
$_shipping_price = $_product->getShippingPrice(); //if product is plus shipping this messages the approximate shipping price on the product 

$web_avail_options = $_product->getResource()->getAttribute('web_availability')) { 
foreach ($web_avail_options as $web_avail_option) { 
    if ($web_avail_option['value'] == $_product->getData('web_availability')) { 
     $web_availability = $web_avail_option['label']; 
     } 
    } 
    ?> 

每次我們設置可用性值如下自動在Magento分配選項值:

<?php 
    if ($shipping_messaging == 0) { 
     echo '+ $' . number_format($_shipping_price, 2) . " Shipping"; // displays "+ $x.xx Shipping" on the product page 
    } elseif ($_shipping_messaging == 1) { 
     echo "Free Shipping"; // displays "Free Shipping" on the product page 
    } 
    else ($web_avail_option == '70' || '80' || '90'); { 
     echo "In Store Only"; 
    } 

    ?> 

運輸信息(「免運費」,或「+ $ 4.80運費)出現,因爲我期望他們,howeve無論產品的可用性如何,始終顯示「僅限於店內」信息。我嘗試過所有可能的組合==,<,>,以及使用在開頭聲明的初始變量的不同部分?

回答

0

請注意您的代碼,尤其是else語句。

else ($web_avail_option == '70' || '80' || '90'); { echo "In Store Only"; }

else語句被誤格式化,請注意下面的代碼。您的其他語句是檢查網絡可用選項是否爲70,但您沒有使用elseif,並且在檢查80後的OR運算符後面。那麼.. 80總是如此。

一個sulution:您可能希望保存在一個陣列(例如正確的狀態:。$correct_status = array(70,80,90);如果這些代碼保存在一個數組,你可以使用下面else語句

elseif(in_array($web_avail_option, $correct_status)) { echo "In store only"; }