2014-09-20 39 views
1

我有一个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; 
} 
} 

任何帮助将不胜感激。

非常感谢

+0

任何一个?这个问题以前必须先交叉。 – YorkieMagento 2014-09-21 08:18:25

+0

我试着复制'new'元素,但是在库存中使用日期范围而不是yes/no,但这似乎没有任何影响。 – YorkieMagento 2014-09-21 11:04:38

回答

0

我设法粗暴地做到这一点,通过“库存”添加新的产品日期属性的Magento和复制代码,为新的,编辑为名称的变化。我很高兴知道我是否可以直接将yes/no做到这一点,我认为将查询从日期更改为直接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); 

    } 

    $isInstock = false; 

    if (Mage::getStoreConfig('ultimo/product_labels/new')) 

    { 

     $isInstock = $this->isInstock($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>'; 

    } 

    if ($isInstock == true) 

    { 

     $html .= '<span class="sticker-wrapper top-right"><span class="sticker sale">' . $this->__('In Stock') . '</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')); 

} 

public function isInstock($product) 

{ 

    return $this->_nowIsBetween($product->getData('in_stock_from'), $product->getData('in_stock_to')); 

} 


/** 

* 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; 

} 

} 
0

第1步:首先,你必须创建一个新的属性。为此,请登录到您的Magento管理员面板。转至目录>>属性>>管理属性>>创建新属性。

在属性下,在属性代码中输入“新”在商品的目录输入类型中选择“是/否”。

单击左侧的管理标签/选项选项卡,在管理员字段和保存属性中输入名称,例如“新标签”。

第2步:现在您必须指定属性。

前往目录>>属性>>管理属性集。

选择属性集。

从右侧的“未分配的属性”部分选择新的和/或销售属性,并将其拖到左侧的组部分。 单击保存属性集。

导航到目录 - >管理产品,选择一个产品并在常规选项卡下将新添加的属性(新建和销售)设置为“是”,然后单击保存。

有关详情,请访问:Add Labels to Magento Products

相关问题