2015-11-01 182 views
0

如果字符串的值等於或大於price字符串,則需要隱藏oldprice字符串。如果值等於或大於另一個,則不顯示字符串

字符串oldprice的正確語法是什麼?

// Save product data into result array 
    $result['products'][] = array(
    'id' => $_product->getId(), 
    'in_stock' => (bool)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getIsInStock(), 
    'url' => str_replace('/index.php', null, $result['shop_data']['url']) . $_product->getUrlKey() . $helper->getProductUrlSuffix(), 
    'price' => $_product->getFinalPrice(), 
    'oldprice' => $_product->getPrice(), 
    'currencyId' => $currencyCode, 
    'categoryId' => $_category->getId(), 
    'picture' => $picUrl, 
    'name' => $_product->getName(), 
    'vendor' => trim($_product->getAttributeText('manufacturer')), 
    'model' => $_product->getSku(), 
    'description' => trim(strip_tags($_product->getShortDescription())), 
    'local_delivery_cost' => $priceship[0],  
    'market_category' => trim($_product->getAttributeText('market_category')), 
    'country_of_origin' => trim($_product->getAttributeText('country_of_manufacture')), 
    'local_delivery_cost' => 500, 
    'sales_notes' => '100% предоплата', 
); 

回答

0

你可以做這樣的事情:

'oldprice' => ($_product->getPrice() >= $_product->getFinalPrice() ? 0 : $_product->getPrice()) 

或只是做事先計算

$oldPrice = null; 
if ($_product->getPrice() >= $_product->getFinalPrice()) { 
    $oldPrice = $_product->getPrice(); 
} 

... 

'oldprice' => $oldPrice 

但是,這也不能阻止一個值被保存到你的陣列(在這種情況下0),所以你仍然需要一些邏輯來回應它。

+0

我只是編輯的最後一個代碼,現在這個樣子: \t \t $ oldPrice = $ _product-> getPrice(); \t \t if($ _product-> getFinalPrice()> = $ _product-> getPrice()){ \t \t $ oldPrice = null; \t \t} –

0

之前的產品數據保存到數組寫一個if條件

<?php 

    $oldprice = null; 
    $finalprice = $_product->getFinalPrice(); 
    $price = $_product->getPrice(); 
    if($price>=$finalprice) 
    { 
    $oldprice = $_product->getPrice(); 
    } 

?> 

而且intialize陣列

$result['products'][] = array(
    'id' => $_product->getId(), 
    'in_stock' => (bool)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getIsInStock(), 
    'url' => str_replace('/index.php', null, $result['shop_data']['url']) . $_product->getUrlKey() . $helper->getProductUrlSuffix(), 
    'price' => $finalprice, 
    'oldprice' => $price, 
    'currencyId' => $currencyCode, 
    'categoryId' => $_category->getId(), 
    'picture' => $picUrl, 
    'name' => $_product->getName(), 
    'vendor' => trim($_product->getAttributeText('manufacturer')), 
    'model' => $_product->getSku(), 
    'description' => trim(strip_tags($_product->getShortDescription())), 
    'local_delivery_cost' => $priceship[0],  
    'market_category' => trim($_product->getAttributeText('market_category')), 
    'country_of_origin' => trim($_product->getAttributeText('country_of_manufacture')), 
    'local_delivery_cost' => 500, 
    'sales_notes' => '100% предоплата', 
); 
相關問題