我有一个Magento商店,使用我购买的模板,我想添加额外的产品标签提示。例如,目前我们有'销售'和'新'作为标准。但我想添加'有货'或其他任何可能提供行动呼吁的内容。在Magento主题中添加额外的标签(例如新的,现货,销售)
下面是控制标签的'labels.php'文件(据我所知)。我想知道是否可以在设置产品属性(例如,in_stock YES/NO)之后添加更多的标签以获得更多标签。
<?php
class Infortis_Ultimo_Helper_Labels extends Mage_Core_Helper_Abstract
{
/**
* Get product labels (HTML)
*
* @return string
*/
public function getLabels($product)
{
$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">' . $this->__('Sale') . '</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;
}
}
任何帮助将不胜感激。
非常感谢
任何一个?这个问题以前必须先交叉。 – YorkieMagento 2014-09-21 08:18:25
我试着复制'new'元素,但是在库存中使用日期范围而不是yes/no,但这似乎没有任何影响。 – YorkieMagento 2014-09-21 11:04:38