是否可以在PHP
打印包含variable
的{{1}}和其他变量?
喜欢:file" Lables.php"
类Infortis_Ultimo_Helper_Labels扩展Mage_Core_Helper_Abstract {
string
}
实际上我想用public function getLabels($product)
{
session_start();
$a = $_SESSION['sdp'];
$html = '';
$isNew = false;
if (Mage::getStoreConfig('ultimo/product_labels/new'))
{
$isNew = $this->isNew($product);
}
$isSale = false;
if (Mage::getStoreConfig('ultimo/product_labels/sale'))
{
$isSale = $this->isOnSale($product);
}
if ($isNew == true)
{
$html .= '<span class="sticker-wrapper top-left"><span class="sticker new">' . $this->__('New') . '</span></span>';
}
if ($isSale == true)
{
$html .= '<span class="sticker-wrapper top-right"><span class="sticker sale">'.$a. '</span></span>';
}
return $html;
}
/**
* Check if "new" label is enabled and if product is marked as "new"
*
* @return bool
*/
public function isNew($product)
{
return $this->_nowIsBetween($product->getData('news_from_date'), $product->getData('news_to_date'));
}
/**
* Check if "sale" label is enabled and if product has special price
*
* @return bool
*/
public function isOnSale($product)
{
$specialPrice = number_format($product->getFinalPrice(), 2);
$regularPrice = number_format($product->getPrice(), 2);
if ($specialPrice != $regularPrice)
return $this->_nowIsBetween($product->getData('special_from_date'), $product->getData('special_to_date'));
else
return false;
}
protected function _nowIsBetween($fromDate, $toDate)
{
if ($fromDate)
{
$fromDate = strtotime($fromDate);
$toDate = strtotime($toDate);
$now = strtotime(Mage::app()->getLocale()->date()->setTime('00:00:00')->toString(Varien_Date::DATETIME_INTERNAL_FORMAT));
if ($toDate)
{
if ($fromDate <= $now && $now <= $toDate)
return true;
}
else
{
if ($fromDate <= $now)
return true;
}
}
return false;
}
更改Sale sticker
。但它不适用于discount percentage
。它给出了if condition
。有什么建议?我在session variable's value 0
中尝试了echo
和print
但未成功。我正在$html
中的Labels.php
进行更改。
答案 0 :(得分:0)
我不熟悉代码,所以我会在不使用会话的情况下处理它。 像
这样的东西$saleprice = number_format($product->getFinalPrice(), 2);
$price = number_format($product->getPrice(), 2);
$percentage = round((1 - ($saleprice/$price)) * 100);
$a = $percentage." %";