如果值等于或大于另一个值,则不显示字符串

问题描述 投票:0回答:2

如果字符串的值等于或大于

oldprice
字符串,则需要隐藏
price
字符串。

字符串的正确语法是什么

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% предоплата',
 );
string magento yaml
2个回答
0
投票

你可以这样做:

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

或者提前计算一下

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

...

'oldprice' => $oldPrice

但是,这不会阻止将值保存到数组中(在本例中为 0),因此您仍然需要一些逻辑来回显它。


0
投票

在将产品数据保存到数组之前写入 if 条件

<?php

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

?>

并初始化数组

$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% предоплата',
 );
© www.soinside.com 2019 - 2024. All rights reserved.